Class Foxen::TransactionFactory
In: lib/semantic_record/foxen.rb
Parent: REXML::Document

Builds a transaction document for updates in the store

Methods

Public Class methods

Creates a new XML-file and adds a transaction statement

[Source]

    # File lib/semantic_record/foxen.rb, line 13
13:     def initialize
14:       super
15:       add_transaction_statement
16:     end

Public Instance methods

adds an add-statement to the transaction document

  • s -> the subject to be added
  • p -> the predicate to be added
  • o -> the object to be added

[Source]

    # File lib/semantic_record/foxen.rb, line 48
48:     def add_add_statement(s, p, o)
49:       add_state = build_element( ADD_STATEMENT )
50:       #--
51:       # TODO move adding of multiple elements to support/helper
52:       #++
53:       build_triple(s,p,o).each do |resource|
54:         add_state.add(resource)
55:       end
56:       self.root.add(add_state)
57:     end

adds an remove-statement to the transaction document

  • s -> the subject to be removed
  • p -> the predicate to be removed
  • o -> the object to be removed

[Source]

    # File lib/semantic_record/foxen.rb, line 27
27:     def add_remove_statement(s, p, o)
28:       remove = build_element( REMOVE_STATEMENT )
29:       #--
30:       # TODO move adding of multiple elements to support/helper
31:       #++
32:         build_triple(s,p,o).each do |resource|
33:           remove.add(resource)
34:         end
35:       
36:       
37:       # build_triple(s,p,o).each do |resource|
38:       #   remove.add(resource)
39:       # end
40: 
41:       self.root.add(remove)
42:     end

Add a Node calles transaction to the document

[Source]

    # File lib/semantic_record/foxen.rb, line 19
19:     def add_transaction_statement
20:       self.add( build_element( TRANSACTION_STATEMENT ) )
21:     end

if theirs an update the old triple has to be deleted and the new values added to the store

[Source]

    # File lib/semantic_record/foxen.rb, line 60
60:     def add_update_statement(s, p, o, new_object)
61:       #--
62:       # TODO modify for applying changes that effect more than the object
63:       #++
64:       #construct_triples(s,p,o).each do |triple| 
65:         add_remove_statement(s, p, o)  
66:       #end
67:       #construct_triples(s,p,new_object).each do |triple| 
68:         add_add_statement(s, p, new_object)  
69:       #end
70:       
71:       #raise self.to_s.inspect
72:     end

Protected Instance methods

Creates a new Node with the specific name

[Source]

     # File lib/semantic_record/foxen.rb, line 129
129:     def build_element(name)
130:       return REXML::Element.new(name)
131:     end

If the value of an object ist a literal build a literal-node

[Source]

     # File lib/semantic_record/foxen.rb, line 120
120:     def build_literal_element(value)
121:       #--
122:       # TODO make me pretty
123:       #++
124:       b = build_element( LITERAL_STATEMENT )
125:       b.text=(value)
126:       return b
127:     end

creates a triple that could be added to the transaction document

[Source]

     # File lib/semantic_record/foxen.rb, line 87
 87:     def build_triple(s, p, o)
 88:       returning [] do |triple|
 89:         #raise s.inspect
 90:         
 91:         # ugly!!! first should not called directly
 92:         [s,p,o].each do |resource|
 93:           #--
 94:           # FIXME if handling of properties ever changes (resource.type == URI)
 95:           #++
 96:           
 97:           
 98:           if resource =~ /http:\/\//
 99:             triple << build_uri_element(resource)
100:           elsif resource.nil?
101:             triple << build_element( NULL )
102:           else
103:             triple << build_literal_element(resource)
104:           end
105:         end
106:       end
107:     end

If the value of a object is uri then build a uri-node

[Source]

     # File lib/semantic_record/foxen.rb, line 110
110:     def build_uri_element(value)
111:       #--
112:       # TODO make me pretty
113:       #++
114:       b = build_element( URI_STATEMENT )
115:       b.text=(value)
116:       return b
117:     end

[Source]

    # File lib/semantic_record/foxen.rb, line 76
76:     def construct_triples(s,p,o)
77:       returning [] do |triples|
78:         s.each do |_s|
79:           o.each do |_o|
80:             triples << {'s' => _s,'p' => p,'o' => _o}
81:           end
82:         end
83:       end
84:     end

[Validate]