rtm 0.1.6 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. data/DISCLAIMER +10 -33
  2. data/LICENSE +201 -0
  3. data/README +3 -3
  4. data/lib/rtm.rb +148 -74
  5. data/lib/rtm/axes.rb +295 -0
  6. data/lib/rtm/axes/association.rb +76 -0
  7. data/lib/rtm/axes/associations.rb +96 -0
  8. data/lib/rtm/axes/assocs_names_occs.rb +56 -0
  9. data/lib/rtm/axes/characteristic.rb +68 -0
  10. data/lib/rtm/axes/characteristics.rb +93 -0
  11. data/lib/rtm/axes/string.rb +76 -0
  12. data/lib/rtm/axes/strings.rb +87 -0
  13. data/lib/rtm/axes/topic.rb +233 -0
  14. data/lib/rtm/axes/topics.rb +280 -0
  15. data/lib/rtm/{backward_compatibility.rb → deprecated/index_property_set.rb} +3 -0
  16. data/lib/rtm/engine.rb +58 -0
  17. data/lib/rtm/extensions.rb +11 -1
  18. data/lib/rtm/{locator_helpers.rb → helpers/locator.rb} +15 -4
  19. data/lib/rtm/{helpers.rb → helpers/no_output.rb} +3 -0
  20. data/lib/rtm/helpers/uri.rb +13 -0
  21. data/lib/rtm/io.rb +18 -0
  22. data/lib/rtm/io/from_xtm2_libxml.rb +2 -1
  23. data/lib/rtm/io/ontopia_io.rb +25 -0
  24. data/lib/rtm/io/tmapix.rb +234 -0
  25. data/lib/rtm/io/to_hash.rb +116 -0
  26. data/lib/rtm/io/to_jtm.rb +53 -103
  27. data/lib/rtm/io/to_rdf.rb +30 -0
  28. data/lib/rtm/io/to_string.rb +8 -6
  29. data/lib/rtm/io/to_xtm1.rb +6 -4
  30. data/lib/rtm/io/to_xtm2.rb +10 -8
  31. data/lib/rtm/io/to_yaml.rb +29 -98
  32. data/lib/rtm/navigation.rb +37 -0
  33. data/lib/rtm/navigation/association/players.rb +25 -0
  34. data/lib/rtm/navigation/name/atomify.rb +19 -0
  35. data/lib/rtm/navigation/name/characteristics.rb +33 -0
  36. data/lib/rtm/navigation/occurrence/atomify.rb +19 -0
  37. data/lib/rtm/navigation/occurrence/characteristics.rb +33 -0
  38. data/lib/rtm/navigation/topic/characteristics.rb +33 -0
  39. data/lib/rtm/navigation/topic/indicators.rb +31 -0
  40. data/lib/rtm/navigation/topic/items.rb +31 -0
  41. data/lib/rtm/navigation/topic/locators.rb +31 -0
  42. data/lib/rtm/navigation/topic/players.rb +27 -0
  43. data/lib/rtm/navigation/topic/supertypes.rb +162 -0
  44. data/lib/rtm/navigation/topic/traverse.rb +51 -0
  45. data/lib/rtm/navigation/topic/types.rb +107 -0
  46. data/lib/rtm/psi.rb +33 -2
  47. data/lib/rtm/sugar.rb +34 -0
  48. data/lib/rtm/sugar/association/hash_access.rb +46 -0
  49. data/lib/rtm/sugar/occurrence/dynamic_value.rb +75 -0
  50. data/lib/rtm/{pimp_my_api.rb → sugar/occurrence/externalize.rb} +3 -0
  51. data/lib/rtm/sugar/role/counterparts.rb +133 -46
  52. data/lib/rtm/sugar/topic/characteristics.rb +126 -12
  53. data/lib/rtm/sugar/topic/counterparts.rb +130 -7
  54. data/lib/rtm/sugar/topic/hash_access.rb +140 -30
  55. data/lib/rtm/sugar/topic/scoped.rb +65 -0
  56. data/lib/rtm/sugar/topic/topic_ref.rb +35 -0
  57. data/lib/rtm/sugar/topic/typed.rb +159 -0
  58. data/lib/rtm/sugar/typed/types.rb +38 -0
  59. data/lib/rtm/validation.rb +8 -5
  60. data/lib/rtm/version.rb +18 -0
  61. data/spec/helpers/spec_exampleexamplegroup.rb +14 -0
  62. data/spec/rtm/axes/association_spec.rb +88 -0
  63. data/spec/rtm/axes/associations_spec.rb +60 -0
  64. data/spec/rtm/axes/assocs_names_occs_spec.rb +9 -0
  65. data/spec/rtm/axes/characteristic_spec.rb +90 -0
  66. data/spec/rtm/axes/characteristics_spec.rb +85 -0
  67. data/spec/rtm/axes/string_spec.rb +145 -0
  68. data/spec/rtm/axes/strings_spec.rb +168 -0
  69. data/spec/rtm/axes/topic_spec.rb +124 -0
  70. data/spec/rtm/axes/topics_spec.rb +103 -0
  71. data/spec/rtm/base_spec.rb +32 -0
  72. data/spec/rtm/io/tmapix_spec.rb +85 -0
  73. data/spec/rtm/navigation/association/players_spec.rb +58 -0
  74. data/spec/rtm/navigation/association_spec.rb +52 -0
  75. data/spec/rtm/navigation/name/atomify_spec.rb +27 -0
  76. data/spec/rtm/navigation/name/characteristics_spec.rb +34 -0
  77. data/spec/rtm/navigation/name_spec.rb +52 -0
  78. data/spec/rtm/navigation/occurrence/atomify_spec.rb +27 -0
  79. data/spec/rtm/navigation/occurrence/characteristics_spec.rb +34 -0
  80. data/spec/rtm/navigation/occurrence_spec.rb +52 -0
  81. data/spec/rtm/navigation/string_spec.rb +51 -0
  82. data/spec/rtm/navigation/topic/characteristics_spec.rb +55 -0
  83. data/spec/rtm/navigation/topic/indicators_spec.rb +43 -0
  84. data/spec/rtm/navigation/topic/items_spec.rb +44 -0
  85. data/spec/rtm/navigation/topic/locators_spec.rb +44 -0
  86. data/spec/rtm/navigation/topic/players_spec.rb +48 -0
  87. data/spec/rtm/navigation/topic/scope_spec.rb +41 -0
  88. data/spec/rtm/navigation/topic/supertypes_spec.rb +376 -0
  89. data/spec/rtm/navigation/topic/traverse_spec.rb +64 -0
  90. data/spec/rtm/navigation/topic/types_spec.rb +195 -0
  91. data/spec/rtm/navigation/topic_spec.rb +153 -0
  92. data/spec/rtm/sugar/association/hash_access_spec.rb +55 -0
  93. data/spec/rtm/sugar/occurrence/dynamic_value_spec.rb +16 -0
  94. data/spec/rtm/sugar/role/counterparts_spec.rb +191 -0
  95. data/spec/rtm/sugar/topic/characteristics_spec.rb +318 -0
  96. data/spec/rtm/sugar/topic/counterparts_spec.rb +184 -0
  97. data/spec/rtm/sugar/topic/hash_access_spec.rb +234 -0
  98. data/spec/rtm/sugar/topic/scoped_spec.rb +131 -0
  99. data/spec/rtm/sugar/topic/topic_ref_spec.rb +44 -0
  100. data/spec/rtm/sugar/topic/typed_spec.rb +155 -0
  101. data/spec/rtm/sugar/typed/types_spec.rb +24 -0
  102. data/spec/rtm/tmapi/core/association_spec.rb +169 -0
  103. data/spec/rtm/tmapi/core/construct_spec.rb +25 -0
  104. data/spec/rtm/tmapi/core/name_spec.rb +85 -0
  105. data/spec/rtm/tmapi/core/occurrence_spec.rb +96 -0
  106. data/spec/rtm/tmapi/core/reifiable_spec.rb +168 -0
  107. data/spec/rtm/tmapi/core/role_spec.rb +73 -0
  108. data/spec/rtm/tmapi/core/scoped_spec.rb +403 -0
  109. data/spec/rtm/tmapi/core/topic_map_spec.rb +648 -0
  110. data/spec/rtm/tmapi/core/topic_spec.rb +992 -0
  111. data/spec/rtm/tmapi/core/typed_spec.rb +112 -0
  112. data/spec/rtm/tmapi/core/variant_spec.rb +52 -0
  113. data/spec/rtm/tmapi/ext/java_util_set_spec.rb +34 -0
  114. data/spec/rtm/tmapi_spec.rb +44 -0
  115. data/spec/rtm/utils/sparql_spec.rb +26 -0
  116. data/spec/rtm_spec.rb +94 -0
  117. data/spec/spec_helper.rb +23 -0
  118. data/test/base_unit_test.rb +161 -0
  119. data/test/{base_test.rb → base_unit_test_tmapi.rb} +46 -43
  120. metadata +122 -66
  121. data/COPYRIGHT +0 -4
  122. data/lib/Rakefile.rb +0 -42
  123. data/lib/activetopicmaps.rb +0 -278
  124. data/lib/rtm/backend/active_record.rb +0 -58
  125. data/lib/rtm/backend/active_record/001_initial_schema.rb +0 -116
  126. data/lib/rtm/backend/active_record/association_and_role.rb +0 -33
  127. data/lib/rtm/backend/active_record/locators.rb +0 -55
  128. data/lib/rtm/backend/active_record/name_variant_occurrence.rb +0 -45
  129. data/lib/rtm/backend/active_record/quaaxtm2rtm.rb +0 -113
  130. data/lib/rtm/backend/active_record/quaaxtm2rtmviews.rb +0 -134
  131. data/lib/rtm/backend/active_record/set_wrapper.rb +0 -98
  132. data/lib/rtm/backend/active_record/tm_construct.rb +0 -62
  133. data/lib/rtm/backend/active_record/tm_delegator.rb +0 -345
  134. data/lib/rtm/backend/active_record/tm_set_delegator.rb +0 -195
  135. data/lib/rtm/backend/active_record/tmdm.rb +0 -298
  136. data/lib/rtm/backend/active_record/topic.rb +0 -87
  137. data/lib/rtm/backend/active_record/topic_map.rb +0 -314
  138. data/lib/rtm/backend/active_record/traverse_associations.rb +0 -87
  139. data/lib/rtm/base.rb +0 -92
  140. data/lib/rtm/connect.rb +0 -92
  141. data/lib/rtm/core_ext.rb +0 -6
  142. data/lib/rtm/io/from_xtm2.rb +0 -263
  143. data/lib/rtm/merging/merging.rb +0 -307
  144. data/lib/rtm/sugar/topic/identifier_direct.rb +0 -11
  145. data/lib/rtm/sugar/topic/predefined_associations.rb +0 -42
  146. data/lib/run_main_project.rb +0 -16
@@ -1,62 +0,0 @@
1
- module RTM::AR
2
- class TopicMapConstruct < TMDelegator
3
- include RTM::TopicMapConstruct
4
-
5
- def self.abstract_class?
6
- self == TopicMapConstruct
7
- end
8
- property_set :item_identifiers, :aka => [:ii, :iid, :source_locators], :type => :ItemIdentifier, :wrap => true,
9
- #:create => :item_identifier, :create_aka => :cii
10
- :add => true, :remove => true
11
-
12
- delegate :remove, :to => :destroy
13
-
14
- delegate :id
15
- # property_parent :parent # mmh..
16
-
17
- property :topic_map, :rw => true, :type => :TopicMap, :wrap => true
18
-
19
- #class_delegate :create
20
-
21
- def self.wrap(obj)
22
- return nil unless obj
23
- raise "Double wrapping" if obj.respond_to?(:__getobj__)
24
- case obj.class.name
25
- when "RTM::AR::TMDM::Topic"
26
- Topic.wrap(obj)
27
- when "RTM::AR::TMDM::Variant"
28
- Variant.wrap(obj)
29
- when "RTM::AR::TMDM::TopicName"
30
- TopicName.wrap(obj)
31
- when "RTM::AR::TMDM::Occurrence"
32
- Occurrence.wrap(obj)
33
- when "RTM::AR::TMDM::Association"
34
- Association.wrap(obj)
35
- when "RTM::AR::TMDM::AssociationRole"
36
- AssociationRole.wrap(obj)
37
- when "RTM::AR::TMDM::TopicMap"
38
- TopicMap.wrap(obj)
39
- else
40
- raise "Can't wrap object. Class for wrapping #{obj.class} unknown (object: #{obj})"
41
- end
42
- end
43
-
44
- def self.find(*args)
45
- res = RTM::AR::TMDM.const_get(name.split("::").last).find(*args)
46
- if res.respond_to? :each
47
- TopicMapConstructs.wrap(res)
48
- else
49
- TopicMapConstruct.wrap(res)
50
- end
51
- end
52
- end
53
-
54
- class Reifiable < TopicMapConstruct
55
- include RTM::Reifiable
56
-
57
- def self.abstract_class?
58
- self == Reifiable
59
- end
60
- property :reifier, :type => :Topic, :rw => :true, :wrap => true
61
- end
62
- end
@@ -1,345 +0,0 @@
1
- module RTM::AR
2
- class TMDelegator
3
- def initialize(obj)
4
- @obj = obj
5
- end
6
-
7
- def __getobj__
8
- @obj
9
- end
10
-
11
- def __setobj__(obj)
12
- @obj = obj
13
- end
14
-
15
- def self.delegate(sym, options={})
16
- to = options[:to] || sym
17
- module_eval(<<-EOS, "(__TMDELEGATOR__)", 1)
18
- def #{sym}(*args, &block)
19
- __getobj__.send(:#{to}, *args, &block)
20
- end
21
- EOS
22
-
23
- if options[:rw]
24
- module_eval(<<-EOS, "(__TMDELEGATOR2__)", 1)
25
- def #{sym}=(*args, &block)
26
- __getobj__.send(:#{to}=, *args, &block)
27
- #{options[:save] ? "__getobj__.save" : "" }
28
- end
29
- EOS
30
- end
31
-
32
- if options[:aka]
33
- options[:aka] = [options[:aka]] unless options[:aka].respond_to? :each
34
- options[:aka].each do |aka|
35
- module_eval(<<-EOS, "(__TMDELEGATOR3__)", 1)
36
- alias :#{aka} :#{sym}
37
- EOS
38
-
39
- if options[:rw]
40
- module_eval(<<-EOS, "(__TMDELEGATOR3__)", 1)
41
- alias :#{aka}= :#{sym}=
42
- EOS
43
- end
44
- end
45
- end
46
- end
47
-
48
- def self.class_delegate(sym, options={})
49
- module_eval(<<-EOS, "(__TMDELEGATOR__)", 1)
50
- class << self
51
- def #{sym}(*args, &block)
52
- __getobj__.send(:#{sym}, *args, &block)
53
- end
54
- end
55
- EOS
56
-
57
- if options[:aka]
58
- options[:aka] = [options[:aka]] unless options[:aka].respond_to? :each
59
- options[:aka].each do |aka|
60
- module_eval(<<-EOS, "(__TMDELEGATOR2__)", 1)
61
- class << self
62
- alias :#{aka} :#{sym}
63
- end
64
- EOS
65
- end
66
- end
67
- end
68
-
69
- def self.parent(sym, options={})
70
- module_eval(<<-EOS, "(__TMDELEGATOR__)", 1)
71
- def #{sym}
72
- TopicMapConstruct.wrap(__getobj__.send(:#{sym}))
73
- end
74
- EOS
75
- aka_property(sym, [:parent, :p])
76
- end
77
-
78
- def self.property_set(prop, options={})
79
- # puts "In #{self.name.to_s.ljust(20)} we have type #{options[:type].to_s.ljust(20)} for property #{prop}"
80
- if options[:wrap]
81
- #puts "#{self}: #{options[:type]}"
82
- module_eval(<<-EOS, "(__AR_DELEGATOR_PROPERTY_SET_W__)", 1)
83
- def #{prop}(*args)
84
- if args.size == 0
85
- # fetch normal
86
- #{options[:type]}s.wrap(__getobj__.#{prop}, self, :#{options[:type]})
87
- else
88
- # fetch with filter
89
- #puts args.inspect
90
- # TODO enhance/fix condition transform code
91
- a = {}.merge(args.first)
92
- if a[:type] && !a[:ttype]
93
- a[:ttype] = a[:type]
94
- a.delete(:type)
95
- end
96
- a.each do |k,v|
97
- if v.respond_to?(:__getobj__)
98
- a[(k.to_s + "_id").to_sym] = v.id
99
- end
100
- end
101
- #{options[:type]}s.wrap(__getobj__.#{prop}.find(:all, :conditions=> a), self, :#{options[:type]})
102
- end
103
- end
104
- EOS
105
- else
106
- module_eval(<<-EOS, "(__AR_DELEGATOR_PROPERTY_SET_NW__)", 1)
107
- def #{prop}
108
- __getobj__.#{prop}
109
- end
110
- EOS
111
- end
112
-
113
- if options[:create]
114
- # some :create_args:
115
- #
116
- # create_locator reference:string
117
- # [ :name => :reference, :type => :String]
118
- #
119
- # create_topic_name value:String, scope:Collection
120
- # create_topic_name value:String, type: Topic, scope:Collection
121
- # [ {:name => :value, :type => :String}, {:name => :type, :type => :Topic, :optional => true}, {:name => :scope, :type => :Collection} ]
122
- #
123
- # create_occurrence value:String, type: Topic, scope:Collection
124
- # create_occurrence resource: Locator, type: Topic, scope:Collection
125
- # [ {:name => :value, :type => [:String, :Locator]}, {:name => :type, :type => :Topic}, {:name => :scope, :type => :Collection} ]
126
- #
127
- # create_association_role player:topic, type: topic
128
- # [ {:name => :player, :type => :Topic}, {:name => :type, :type => :Topic}]
129
- #
130
- # create_variant value:string, :scope:Collection
131
- # create_variant resource:locator, :scope:Collection
132
- # [ {:name => :value, :type => [:String, :Locator]}, {:name => :scope, :type => :Collection}]
133
-
134
- module_eval(<<-EOS, "(__AR_DELEGATOR_PROPERTY_SET_CREATE__)", 1)
135
- def create_#{ options[:create]}(*args, &block)
136
- arg_defs = #{ (options[:create_args] || nil ).inspect}
137
-
138
- a = parse_args(args, arg_defs)
139
-
140
- a = enhance_args_hash(a, arg_defs) if arg_defs
141
-
142
- a = a.reject{|k,v| v.nil?}
143
-
144
- # hack to change :type to :ttype for AR backend
145
- # puts a.inspect unless a.is_a? Hash
146
- if a[:type] && !a[:ttype]
147
- a[:ttype] = a[:type]
148
- a.delete(:type)
149
- end
150
- if [:Locator,:ItemIdentifier, :SubjectIdentifier, :SubjectLocator].include?(:#{options[:type]})
151
- unless a[:topic_map]
152
- a[:topic_map] = topic_map.__getobj__
153
- end
154
- end
155
-
156
- if block_given?
157
- obj = #{options[:type]}.wrap( __getobj__.#{options[:create]}s.new(a) )
158
- yield obj
159
- obj.save
160
- else
161
- obj = #{options[:type]}.wrap( __getobj__.#{options[:create]}s.create(a) )
162
- end
163
- obj
164
- end
165
- EOS
166
-
167
- if options[:create_aka]
168
- aka_property("create_#{options[:create]}", options[:create_aka])
169
- end
170
- end
171
-
172
- if options[:add]
173
- module_eval(<<-RUBY, "(__AR_DELEGATOR_PROPERTY_SET_ADD__)", 1)
174
- def add_#{prop.to_s.singularize}(*args, &block)
175
- #{prop}.add(*args, &block)
176
- end
177
- RUBY
178
- aka_property("add_#{prop.to_s.singularize}", options[:aka].map{|a| "add_#{a}"})
179
- aka_property("add_#{prop.to_s.singularize}", options[:aka].map{|a| "a#{a}"})
180
- end
181
-
182
- if options[:remove]
183
- module_eval(<<-RUBY, "(__AR_DELEGATOR_PROPERTY_SET_REMOVE__)", 1)
184
- def remove_#{prop.to_s.singularize}(*args, &block)
185
- #{prop}.remove(*args, &block)
186
- end
187
- RUBY
188
- aka_property("remove_#{prop.to_s.singularize}", options[:aka].map{|a| "remove_#{a}"})
189
- aka_property("remove_#{prop.to_s.singularize}", options[:aka].map{|a| "r#{a}"})
190
- end
191
-
192
- # TODO: aliases for property_set.add as add_property
193
-
194
- aka_property(prop, options[:aka]) if options[:aka]
195
- end
196
-
197
- private
198
- def parse_args(args, arg_defs)
199
- a = {}
200
- a = args.pop if args.last.is_a? Hash
201
- # We are finished if there are no more parameters or we have no arg_def.
202
- # Special case: non optional parameters must have been in the Hash, just a hash is also allowed.
203
- return a if args.size == 0 || arg_defs == nil
204
-
205
- # we have some args
206
- if args.size == arg_defs.size # all are given
207
- return args2hash(a, args,arg_defs)
208
- elsif args.size == arg_defs.reject { |d| d[:optional]}
209
- return args2hash(a, args, arg_defs.reject {|d| d[:optional]})
210
- end
211
- #warn("Functions with more than one optional parameter are not supported. This will only work if the left out ones are the last.")
212
- return args2hash(a, args,arg_defs)
213
- end
214
-
215
- def args2hash(a, args, arg_defs)
216
- arg_defs.zip(args) do |argd,arg|
217
- a[argd[:name]] = arg
218
- end
219
-
220
- return a
221
- end
222
-
223
- def enhance_args_hash(a, arg_defs)
224
- #puts "enhance_args: #{a.inspect} ---\n#{arg_defs.inspect}"
225
- return a if a.empty?
226
- arg_defs.each do |argd|
227
- #puts "enhancing #{argd[:name]}, which is a #{a[argd[:name]].class}"
228
- if argd[:type] == :Topic
229
- if a[argd[:name]].is_a? String
230
- a[argd[:name]] = topic_map._topic_by_locator!(a[argd[:name]])
231
- elsif a[argd[:name]].is_a?(RTM::Topic)
232
- a[argd[:name]] = a[argd[:name]].__getobj__
233
- end
234
- end
235
- if argd[:type] == :Locator || (argd[:type].respond_to?(:include?) && argd[:type].include?(:Locator))
236
- a[argd[:name]] = a[argd[:name]].to_s
237
- end
238
- end
239
- a
240
- end
241
-
242
- public
243
- def self.property(prop, options={})
244
- module_eval(<<-EOS, "(__AR_DELEGATOR_PROPERTY__)", 1)
245
- def #{prop}
246
- #{options[:wrap]? "#{options[:type]}.wrap":""}( __getobj__.#{prop})
247
- end
248
- EOS
249
-
250
- if options[:rw]
251
- case options[:type]
252
- when :Topic
253
- module_eval(<<-EOS, "(__AR_DELEGATOR_PROPERTY2__)", 1)
254
- def #{prop}=(obj)
255
- obj = topic_map.topic_by_locator!(obj) unless obj.is_a? #{options[:type]}
256
- __getobj__.#{prop} = obj.__getobj__
257
- __getobj__.save
258
- end
259
- EOS
260
- when :TopicMap
261
- module_eval(<<-EOS, "(__AR_DELEGATOR_PROPERTY2__)", 1)
262
- def #{prop}=(obj)
263
- obj = RTM.create obj.to_s unless obj.is_a? #{options[:type]}
264
- __getobj__.#{prop} = obj.__getobj__
265
- __getobj__.save
266
- end
267
- EOS
268
- when :String, :Locator
269
- module_eval(<<-EOS, "(__AR_DELEGATOR_PROPERTY2__)", 1)
270
- def #{prop}=(obj)
271
- __getobj__.#{prop} = obj.to_s
272
- __getobj__.save
273
- end
274
- EOS
275
- else
276
- raise "Don't know how to do wrapping for #{options[:type]}"
277
- end
278
-
279
- end
280
-
281
- aka_property(prop, options[:aka]) if options[:aka]
282
- end
283
-
284
- def self.aka_property(prop, aka)
285
- aka = [aka].flatten
286
- aka.each do |a|
287
- #puts "generating alias #{a} for #{prop}"
288
- module_eval(<<-EOS, "(__AR_DELEGATOR_AKA_PROPERTY__)", 1)
289
- alias :#{a} :#{prop}
290
- EOS
291
- end
292
- end
293
-
294
- def self.equality(eqfields, options={})
295
- field_condition = eqfields.map {|f| "self.#{f} == o.#{f}" }.join(" && ")
296
- module_eval(<<-EOS, "(__AR_EQUALITY__)", 1)
297
- def ==(o)
298
- return false unless o
299
- return true if #{field_condition}
300
- false
301
- end
302
- EOS
303
- end
304
- def eql?(o)
305
- return false unless o
306
- return true if self.class == o.class && self.id == o.id
307
- false
308
- end
309
- def hash
310
- return self.id.hash
311
- end
312
-
313
- def self.wrapper_cache
314
- module_eval(<<-EOS, "(__AR_WRAPPER_CACHE__)", 1)
315
- def self.wrap(obj)
316
- return nil unless obj
317
- raise "Double wrapping" if obj.respond_to?(:__getobj__)
318
- t = self.wrapped(obj)
319
- if t
320
- t.__setobj__(obj)
321
- return t
322
- end
323
- self.new(obj)
324
- end
325
-
326
- def self.wrapped(unwrapped_obj)
327
- @@wrapped ||= {}
328
- return @@wrapped[unwrapped_obj.id] if unwrapped_obj.respond_to? :id
329
- @@wrapped[unwrapped_obj]
330
- end
331
- def self.reset_wrapped
332
- @@wrapped = {}
333
- end
334
- def initialize(*args)
335
- super
336
- @@wrapped ||= {}
337
- @@wrapped[self.id]=self
338
- end
339
- EOS
340
- end
341
-
342
- alias :i :id
343
- delegate :reload
344
- end
345
- end
@@ -1,195 +0,0 @@
1
- module RTM::AR
2
- class TMSetDelegator < TMDelegator
3
- include Enumerable
4
- # attr_reader :content_class_name
5
- def initialize(obj,parent,type)
6
- @obj = obj
7
- @parent = parent
8
- @type = type
9
- end
10
-
11
- # This class method wraps a Set completely while the instance method wraps one single contained object
12
- def self.wrap(obj, parent=nil, type=nil)
13
- return nil unless obj
14
- raise "Double wrapping" if obj.respond_to?(:__getobj__)
15
- self.new(obj, parent, type)
16
- end
17
-
18
- def add(obj)
19
- return unless obj
20
-
21
- old = @obj.detect { |x| x == obj } # can't that be done easier?
22
- if old
23
- old.merge obj
24
- else
25
- if obj.respond_to? :__getobj__
26
- @obj << obj.__getobj__
27
- else
28
- case @type
29
- when :Topic
30
- @obj << @parent.topic_map.get!(obj).__getobj__
31
- @parent.__getobj__.reload
32
-
33
- when :ItemIdentifier
34
- if @parent.class.name.to_s =~ /::Topic$/
35
- tbi = @parent.topic_map._item_identifier(obj)
36
- if tbi && tmc=tbi.topic_map_construct
37
- if tmc.class.name =~ /::Topic$/
38
- return @parent if tmc == @parent.__getobj__
39
- result = Topic.wrap(tmc).merge @parent
40
- return result
41
- else
42
- raise "Duplicate Item Identifier"
43
- end
44
- end
45
- tbsi = @parent.topic_map._subject_identifier(obj.to_s)
46
- if tbsi
47
- if t=tbsi.topic
48
- return @parent if t == @parent.__getobj__
49
- result = Topic.wrap(t).merge @parent
50
- # after merging, we still need to add the II
51
- result.__getobj__.item_identifiers.create(:reference => obj.to_s, :topic_map_id => @parent.topic_map.__getobj__.id)
52
- return result
53
- end
54
- end
55
- end
56
- result = @obj << @parent.topic_map._item_identifier!(obj.to_s)
57
- return result
58
-
59
- when :SubjectIdentifier
60
- # check for existing item identifier
61
- tbi = @parent.topic_map._item_identifier(obj)
62
- if tbi && tmc=tbi.topic_map_construct
63
- if tmc.class.name =~ /::Topic$/
64
- return @parent if tmc == @parent.__getobj__
65
- result = Topic.wrap(tmc).merge @parent
66
- # after merging, we still need to add the SI
67
- result.__getobj__.subject_identifiers.create(:reference => obj.to_s, :topic_map_id => @parent.topic_map.__getobj__.id)
68
- return result
69
- else
70
- warn("This subject identifier IRI already belongs to another topic map construct (not a topic)")
71
- end
72
- end
73
- # check for existing subject identifier
74
- tbsi = @parent.topic_map._subject_identifier(obj.to_s)
75
- if tbsi
76
- if true && t=tbsi.topic #the single = is intentional, the "true &&" just makes netbeans not raise a warning
77
- return @parent if t == @parent.__getobj__
78
- result = Topic.wrap(t).merge @parent
79
- return result
80
- end
81
- end
82
- @obj.create(:reference => obj.to_s, :topic_map_id => @parent.topic_map.__getobj__.id)
83
-
84
- when :SubjectLocator
85
- tbsl = @parent.topic_map._subject_locator(obj.to_s)
86
- if tbsl
87
- if true && t=tbsl.topic #the single = is intentional, the "true &&" just makes netbeans not raise a warning
88
- return @parent if t == @parent.__getobj__
89
- result = Topic.wrap(t).merge @parent
90
- return result
91
- end
92
- end
93
- @obj.create(:reference => obj.to_s, :topic_map_id => @parent.topic_map.__getobj__.id)
94
-
95
- end
96
- end
97
- end
98
- end
99
- alias :<< :add
100
-
101
- def add_all(objs)
102
- return unless objs
103
- objs.each {|obj| add(obj)}
104
- true
105
- end
106
-
107
- def each(&b)
108
- @obj.each { |e| yield wrap(e)}
109
- end
110
-
111
- def size
112
- @obj.size
113
- end
114
- alias :length :size
115
-
116
- def empty?
117
- @obj.empty?
118
- end
119
-
120
- def delete(obj)
121
- obj = obj.__getobj__ if obj.respond_to? :__getobj__
122
- case @type
123
- when :ItemIdentifier, :SubjectIdentifier, :SubjectLocator
124
- obj = @obj.find_by_reference(@parent.topic_map.resolve(obj.to_s)) if obj.is_a? String
125
- end
126
- @obj.delete(obj)
127
- # item_identifiers: remove also from topicMap
128
- #removed_event obj if respond_to? :removed_event
129
- end
130
- alias :remove :delete
131
-
132
- def include?(obj)
133
- return @obj.include?(obj)
134
- #@obj.each { |e| return true if e == obj } # T#ODO support for get
135
- #false
136
- end
137
-
138
- def first
139
- wrap(@obj.entries.first)
140
- end
141
- def last
142
- wrap(@obj.entries.last)
143
- end
144
-
145
- def to_s
146
- "[#{@obj.entries.map { |e| wrap(e).to_s }.join(", ") }]"
147
- end
148
- def [](i)
149
- wrap(@obj[i])
150
- end
151
-
152
- def content_class
153
- # @content_class ||= RTM.const_get(@content_class_name)
154
- @content_class ||= RTM.const_get("#{@content_class_name}MemImpl")
155
- end
156
-
157
- def find(*args)
158
- res = @obj.find(*args)
159
- if res.respond_to? :each
160
- TopicMapConstructs.wrap(res)
161
- else
162
- TopicMapConstruct.wrap(res)
163
- end
164
- end
165
-
166
- def &(other)
167
- @obj.to_a & other.to_a
168
- end
169
-
170
- alias :old_method_missing :method_missing
171
- def method_missing(method_name, *args)
172
- if @obj.size > 0 && first.respond_to?(method_name) && (![:__getobj__, :__setobj__].include?(method_name))
173
- a = []
174
- inject(a) {|all,single| all << single.send(method_name, *args)}
175
- a
176
- else
177
- old_method_missing(method_name, *args)
178
- end
179
- end
180
-
181
- alias :old_respond_to? :respond_to?
182
- def respond_to?(method_name)
183
- resp = old_respond_to?(method_name)
184
- return resp if resp # i.e. if true
185
- return false if [:__getobj__, :__setobj__].include?(method_name)
186
- # ... and ask first child otherwise
187
- @obj.size > 0 && first.respond_to?(method_name)
188
- end
189
-
190
- # TMSetDelegator#to_a doesn't help as thought, but maybe we come back to that l8r...
191
- #def to_a
192
- # @obj.map {|o| wrap(o)}
193
- #end
194
- end
195
- end