rtm-javatmapi 0.3.1-java

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 (61) hide show
  1. data/DISCLAIMER +15 -0
  2. data/LICENSE +201 -0
  3. data/README +4 -0
  4. data/lib/rtm-javatmapi.rb +4 -0
  5. data/lib/rtm/javatmapi.rb +229 -0
  6. data/lib/rtm/javatmapi/aliases.rb +43 -0
  7. data/lib/rtm/javatmapi/core.rb +16 -0
  8. data/lib/rtm/javatmapi/core/association.rb +71 -0
  9. data/lib/rtm/javatmapi/core/construct.rb +92 -0
  10. data/lib/rtm/javatmapi/core/datatype_aware.rb +60 -0
  11. data/lib/rtm/javatmapi/core/locator.rb +20 -0
  12. data/lib/rtm/javatmapi/core/name.rb +127 -0
  13. data/lib/rtm/javatmapi/core/occurrence.rb +32 -0
  14. data/lib/rtm/javatmapi/core/reifiable.rb +38 -0
  15. data/lib/rtm/javatmapi/core/role.rb +49 -0
  16. data/lib/rtm/javatmapi/core/scoped.rb +93 -0
  17. data/lib/rtm/javatmapi/core/topic.rb +504 -0
  18. data/lib/rtm/javatmapi/core/topic_map.rb +677 -0
  19. data/lib/rtm/javatmapi/core/typed.rb +31 -0
  20. data/lib/rtm/javatmapi/core/variant.rb +19 -0
  21. data/lib/rtm/javatmapi/ext.rb +4 -0
  22. data/lib/rtm/javatmapi/ext/java_util_set.rb +10 -0
  23. data/lib/rtm/javatmapi/javalibs/aduna-commons-collections-2.5.0.jar +0 -0
  24. data/lib/rtm/javatmapi/javalibs/aduna-commons-concurrent-2.4.0.jar +0 -0
  25. data/lib/rtm/javatmapi/javalibs/aduna-commons-i18n-1.1.0.jar +0 -0
  26. data/lib/rtm/javatmapi/javalibs/aduna-commons-io-2.6.0.jar +0 -0
  27. data/lib/rtm/javatmapi/javalibs/aduna-commons-iteration-2.5.0.jar +0 -0
  28. data/lib/rtm/javatmapi/javalibs/aduna-commons-lang-2.6.0.jar +0 -0
  29. data/lib/rtm/javatmapi/javalibs/aduna-commons-net-2.4.0.jar +0 -0
  30. data/lib/rtm/javatmapi/javalibs/aduna-commons-text-2.4.0.jar +0 -0
  31. data/lib/rtm/javatmapi/javalibs/aduna-commons-xml-2.4.0.jar +0 -0
  32. data/lib/rtm/javatmapi/javalibs/commons-collections-3.2.1.jar +0 -0
  33. data/lib/rtm/javatmapi/javalibs/ctm-writer-1.0.8-SNAPSHOT.jar +0 -0
  34. data/lib/rtm/javatmapi/javalibs/java-tools-0.0.3-SNAPSHOT.jar +0 -0
  35. data/lib/rtm/javatmapi/javalibs/jcl-over-slf4j-1.6.1.jar +0 -0
  36. data/lib/rtm/javatmapi/javalibs/mio-syntaxpack-nodeps-0.1.1.jar +0 -0
  37. data/lib/rtm/javatmapi/javalibs/sesame-model-2.3-pr1.jar +0 -0
  38. data/lib/rtm/javatmapi/javalibs/sesame-query-2.3-pr1.jar +0 -0
  39. data/lib/rtm/javatmapi/javalibs/sesame-queryalgebra-evaluation-2.3-pr1.jar +0 -0
  40. data/lib/rtm/javatmapi/javalibs/sesame-queryalgebra-model-2.3-pr1.jar +0 -0
  41. data/lib/rtm/javatmapi/javalibs/sesame-queryparser-api-2.3-pr1.jar +0 -0
  42. data/lib/rtm/javatmapi/javalibs/sesame-queryparser-sparql-2.3-pr1.jar +0 -0
  43. data/lib/rtm/javatmapi/javalibs/sesame-queryresultio-api-2.3-pr1.jar +0 -0
  44. data/lib/rtm/javatmapi/javalibs/sesame-queryresultio-sparqlxml-2.3-pr1.jar +0 -0
  45. data/lib/rtm/javatmapi/javalibs/sesame-repository-api-2.3-pr1.jar +0 -0
  46. data/lib/rtm/javatmapi/javalibs/sesame-repository-sail-2.3-pr1.jar +0 -0
  47. data/lib/rtm/javatmapi/javalibs/sesame-rio-api-2.3-pr1.jar +0 -0
  48. data/lib/rtm/javatmapi/javalibs/sesame-rio-n3-2.3-pr1.jar +0 -0
  49. data/lib/rtm/javatmapi/javalibs/sesame-rio-rdfxml-2.2.4.jar +0 -0
  50. data/lib/rtm/javatmapi/javalibs/sesame-rio-turtle-2.3-pr1.jar +0 -0
  51. data/lib/rtm/javatmapi/javalibs/sesame-sail-api-2.3-pr1.jar +0 -0
  52. data/lib/rtm/javatmapi/javalibs/sesame-sail-inferencer-2.3-pr1.jar +0 -0
  53. data/lib/rtm/javatmapi/javalibs/sesame-sail-memory-2.3-pr1.jar +0 -0
  54. data/lib/rtm/javatmapi/javalibs/slf4j-api-1.6.1.jar +0 -0
  55. data/lib/rtm/javatmapi/javalibs/slf4j-nop-1.6.1.jar +0 -0
  56. data/lib/rtm/javatmapi/javalibs/tmapi-2.0.3-SNAPSHOT.jar +0 -0
  57. data/lib/rtm/javatmapi/javalibs/tmapix-core-0.2.0-SNAPSHOT.jar +0 -0
  58. data/lib/rtm/javatmapi/javalibs/tmapix-io-1.0.0.jar +0 -0
  59. data/lib/rtm/javatmapi/javalibs/trove-2.0.4.jar +0 -0
  60. data/lib/rtm/javatmapi/superiseable.rb +33 -0
  61. metadata +137 -0
@@ -0,0 +1,38 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module Java::OrgTmapiCore::Reifiable
5
+
6
+ include RTM::Reifiable
7
+ extend Superiseable
8
+
9
+ # Returns the reifier (a topic) of this Reifiable
10
+ # or nil if the Reifiable is not reified.
11
+ #
12
+ # :call-seq:
13
+ # reifier -> Topic
14
+ #
15
+ def reifier
16
+ getReifier
17
+ end
18
+
19
+ superised
20
+ # Sets the reifier of this reifiable Construct.
21
+ # The specified reifier MUST NOT reify another information item.
22
+ #
23
+ # Identifier may be a topic reference or nil,
24
+ # if an existing reifier should be removed.
25
+ #
26
+ # :call-seq:
27
+ # reifier = identifier
28
+ # reifier = ()
29
+ #
30
+ def reifier=(identifier=nil)
31
+ unless identifier
32
+ setReifier(nil)
33
+ return
34
+ end
35
+ raise("reifier=: identifier muss be a Topic, Locator or String; not given or nil") unless identifier.is_a?(Java::OrgTmapiCore::Topic) || identifier.is_a?(Java::OrgTmapiCore::Locator) || identifier.is_a?(String)
36
+ setReifier(topic_map.get!(identifier))
37
+ end
38
+ end
@@ -0,0 +1,49 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module Java::OrgTmapiCore::Role
5
+
6
+ include RTM::Role
7
+ extend Superiseable
8
+
9
+ # Returns the Association to which this Role belongs.
10
+ #
11
+ # :call-seq:
12
+ # parent -> Association
13
+ #
14
+ def parent
15
+ getParent
16
+ end
17
+ alias :reverse_children :parent
18
+
19
+ # Returns the Topic playing the current Role.
20
+ #
21
+ # :call-seq:
22
+ # player -> Topic
23
+ #
24
+ def player
25
+ getPlayer
26
+ end
27
+
28
+ superised
29
+ # Sets the role player. Any previous role player will be overriden.
30
+ #
31
+ # Identifier may be a topic reference.
32
+ #
33
+ # :call-seq:
34
+ # player=(identifier)
35
+ #
36
+ def player=(identifier)
37
+ setPlayer(topic_map.get!(identifier))
38
+ end
39
+
40
+ # Returns the identifier of the current Role.
41
+ # This property has no representation in the Topic Maps - Data Model.
42
+ #
43
+ # :call-seq:
44
+ # id -> String
45
+ #
46
+ def id
47
+ getId
48
+ end
49
+ end
@@ -0,0 +1,93 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module Java::OrgTmapiCore::Scoped
5
+
6
+ include RTM::Scoped
7
+ extend Superiseable
8
+
9
+ # Returns the Topics which define the scope of this scoped Construct.
10
+ # An empty Set represents the unconstrained scope.
11
+ #
12
+ # :call-seq:
13
+ # scope -> Set of Topics
14
+ #
15
+ def scope
16
+ getScope
17
+ end
18
+ alias :themes :scope
19
+
20
+ superised
21
+ # Adds a topic given by the identifier to the scope.
22
+ #
23
+ # Identifier may be a topic reference.
24
+ #
25
+ # :call-seq:
26
+ # add_theme(identifier)
27
+ #
28
+ def add_theme(identifier)
29
+ if identifier.is_a?(Java::OrgTmapiCore::Topic)
30
+ addTheme(identifier)
31
+ elsif identifier.is_a?(Java::OrgTmapiCore::Locator) || identifier.is_a?(String)
32
+ addTheme(topic_map.get!(identifier))
33
+ else
34
+ raise("Identifier must be a Topic, String or Locator")
35
+ end
36
+ end
37
+
38
+ # Adds one or several topics to the scope.
39
+ #
40
+ # An identifier may be a topic reference.
41
+ #
42
+ # :call-seq:
43
+ # add_themes(identifier)
44
+ # add_themes(identifier1, identifier2, ...)
45
+ #
46
+ def add_themes(*args)
47
+ args.flatten!
48
+ args.each do |identifier|
49
+ add_theme(identifier)
50
+ end
51
+ end
52
+ alias :add_scope :add_themes
53
+
54
+ # Future version, TODO
55
+ # def set_scope(*args)
56
+ #
57
+ # end
58
+ # alias :scope= :set_scope
59
+
60
+ superised
61
+ # Removes a topic given by the identifier from the current scope.
62
+ #
63
+ # Identifier may be a topic reference.
64
+ #
65
+ # :call-seq:
66
+ # remove_theme(identifier)
67
+ #
68
+ def remove_theme(identifier)
69
+ identifier = topic_map.get(identifier)
70
+ removeTheme(identifier) if identifier.is_a?(Java::OrgTmapiCore::Topic)
71
+ end
72
+
73
+ # Removes one or several topics from the scope.
74
+ #
75
+ # An identifier may be a topic reference.
76
+ #
77
+ # :call-seq:
78
+ # remove_themes(identifier)
79
+ # remove_themes(identifier1, identifier2, ...)
80
+ #
81
+ def remove_themes(*args)
82
+ args.flatten.each do |identifier|
83
+ remove_theme(identifier)
84
+ end
85
+ end
86
+ alias :remove_scope :remove_themes
87
+
88
+ # Future version, TODO
89
+ # def delete_scope(*args)
90
+ #
91
+ # end
92
+
93
+ end
@@ -0,0 +1,504 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module Java::OrgTmapiCore::Topic
5
+
6
+ include RTM::Topic
7
+ extend Superiseable
8
+
9
+ # Returns all Names and Occurrences parented by this Topic.
10
+ #
11
+ # :call-seq:
12
+ # children -> Array of Names and/or Occurrences
13
+ #
14
+ def children
15
+ getNames.to_a + getOccurrences.to_a
16
+ end
17
+ alias :reverse_parent :children
18
+
19
+ superised
20
+ # Returns Names of this Topic.
21
+ #
22
+ # If identifier is given, returns the Names
23
+ # of this Topic for which the Name type equals identifier.
24
+ # If several identifiers are given, returns the union
25
+ # of all Names of this Topic, which have one of
26
+ # the identifiers as Name type.
27
+ #
28
+ # If the identifier equals :default, all Names
29
+ # which have the default Name type are returned.
30
+ #
31
+ # Identifier may be a topic reference or Symbol;
32
+ # or an Array of these.
33
+ #
34
+ # :call-seq:
35
+ # names -> Set of Names
36
+ # names(identifier) -> Set of Names
37
+ #
38
+ def names(*args)
39
+ identifier = args.flatten
40
+ return getNames if identifier.empty?
41
+ if identifier.size > 1
42
+ result = java.util.HashSet.new
43
+ identifier.each{|i| result.addAll(names(i))}
44
+ return result
45
+ else
46
+ identifier = identifier[0]
47
+ return getNames if identifier == :any
48
+ return getNames(topic_map.get(RTM::PSI[:name_type])) if identifier == :default
49
+ identifier = topic_map.get(identifier)
50
+ return java.util.HashSet.new unless identifier
51
+ return getNames(identifier)
52
+ end
53
+ end
54
+
55
+ superised
56
+ # Returns Occurrences of this Topic.
57
+ #
58
+ # If identifier is given, returns the Occurrences
59
+ # of this Topic for which the Occurrence type equals identifier.
60
+ # If several identifiers are given, returns the union
61
+ # of all Occurrences of this Topic, which have one of
62
+ # the identifiers as Occurrence type.
63
+ #
64
+ # Identifier may be a topic reference or an Array of these.
65
+ #
66
+ # :call-seq:
67
+ # occurrences -> Set of Occurrences
68
+ # occurrences(identifier) -> Set of Occurrences
69
+ #
70
+ def occurrences(*args)
71
+ identifier = args.flatten
72
+ return getOccurrences if identifier.empty?
73
+ if identifier.size > 1
74
+ result = java.util.HashSet.new
75
+ identifier.each{|i| result.addAll(occurrences(i))}
76
+ return result
77
+ else
78
+ identifier = identifier[0]
79
+ return getOccurrences if identifier == :any
80
+ identifier = topic_map.get(identifier)
81
+ return java.util.HashSet.new unless identifier
82
+ return getOccurrences(identifier)
83
+ end
84
+ end
85
+
86
+ superised
87
+ # Creates a Name for this Topic with the specified value.
88
+ # Value has to be a String.
89
+ #
90
+ # Type may be a topic reference.
91
+ # If given, type specifies the Name Type;
92
+ # else the created Name will have the default name type.
93
+ #
94
+ # Scope must be an Array of Topics/Topic-References.
95
+ # If given, scope specifies the Name scope; else the Name is
96
+ # in the unconstrained scope.
97
+ #
98
+ # :call-seq:
99
+ # create_name(value) -> Name
100
+ # create_name(value, scope) -> Name
101
+ # create_name(type, value) -> Name
102
+ # create_name(type, value, scope) -> Name
103
+ #
104
+ def create_name(arg1,arg2 = :nothing, arg3 = :nothing)
105
+ if (arg2 == :nothing) && (arg3 == :nothing) #arg1 = value
106
+ raise "create_name(value): value must be a String" unless arg1.is_a?(String)
107
+ return createName(arg1,new_empty_java_topic_array)
108
+ end
109
+ if (arg3 == :nothing)
110
+ if arg2.is_a?(Array) #arg1 = value, arg2 = scope
111
+ raise "create_name(value, scope): value must be a String" unless arg1.is_a?(String)
112
+ arg2.each do |theme|
113
+ raise "create_name(value, scope): scope must be an Array of Topics/Topic-References" unless (theme.is_a?(String) || theme.is_a?(Java::OrgTmapiCore::Topic) || theme.is_a?(Java::OrgTmapiCore::Locator))
114
+ end
115
+ return arg2.empty? ? createName(arg1,new_empty_java_topic_array) : createName(arg1,topic_map.get!(arg2))
116
+ elsif arg2.is_a?(String) #arg1 = type, arg2 = value
117
+ raise "create_name(type, value): type must be a Topic/Topic-Reference" unless (arg1.is_a?(String) || arg1.is_a?(Java::OrgTmapiCore::Topic) || arg1.is_a?(Java::OrgTmapiCore::Locator))
118
+ return createName(topic_map.get!(arg1),arg2,new_empty_java_topic_array)
119
+ else
120
+ raise "create_name(?,?): arguments don't match"
121
+ end
122
+ end
123
+ #arg1 = type, arg2 = value, arg3 = scope
124
+ raise "create_name(type, value, scope): type must be a Topic/Topic-Reference" unless (arg1.is_a?(String) || arg1.is_a?(Java::OrgTmapiCore::Topic) || arg1.is_a?(Java::OrgTmapiCore::Locator))
125
+ raise "create_name(type, value, scope): value must be a String" unless arg2.is_a?(String)
126
+ raise "create_name(type, value, scope): scope must be an Array" unless arg3.is_a?(Array)
127
+ arg3.each do |theme|
128
+ raise "create_name(type, value, scope): scope must be an Array of Topics/Topic-References" unless (theme.is_a?(String) || theme.is_a?(Java::OrgTmapiCore::Topic) || theme.is_a?(Java::OrgTmapiCore::Locator))
129
+ end
130
+ return createName(topic_map.get!(arg1),arg2,topic_map.get!(arg3))
131
+ end
132
+
133
+ superised
134
+ # Creates an Occurrence for this Topic with the specified type and value and
135
+ # optional scope and datatype.
136
+ #
137
+ # Type specifies the Occurrence type and may be a topic reference.
138
+ #
139
+ # Value may be a Locator (then the datatype is set to xsd:AnyURI and
140
+ # must not be given) or String.
141
+ #
142
+ # Scope may be an Array of topic reference. If no scope
143
+ # is given, the Occurrence will be in the unconstrained scope.
144
+ #
145
+ # Datatype may be a String or Locator and indicates the datatype of the value.
146
+ #
147
+ # :call-seq:
148
+ # create_occurrence(type, value) -> Occurrence
149
+ # create_occurrence(type, value, {:scope => scope}) -> Occurrence
150
+ # create_occurrence(type, value, {:datatype => datatype, :scope => scope}) -> Occurrence
151
+ # create_occurrence(type, value, {:datatype => datatype}) -> Occurrence
152
+ #
153
+ def create_occurrence(type,value,params={})
154
+ # creating a topic for the type
155
+ type = topic_map.get!(type)
156
+ # reading the datatype if given. nil otherwise
157
+ datatype = params[:datatype]
158
+ # reading value and setting datatype if not done before
159
+ unless datatype
160
+ if value.is_a?(Java::OrgTmapiCore::Locator)
161
+ datatype = RTM::PSI[:IRI]
162
+ elsif value.is_a?(String)
163
+ datatype = RTM::PSI[:String]
164
+ elsif value.is_a?(Float)
165
+ datatype = RTM::PSI[:Float]
166
+ elsif value.is_a?(Fixnum)
167
+ datatype = RTM::PSI[:Long]
168
+ elsif value.is_a?(Bignum)
169
+ datatype = RTM::PSI[:Integer]
170
+ elsif value.is_a?(DateTime) #DateTime is a Time and a Date
171
+ datatype ||= RTM::PSI[:DateTime]
172
+ elsif value.is_a?(Time)
173
+ datatype ||= RTM::PSI[:Time]
174
+ elsif value.is_a?(Date)
175
+ datatype ||= RTM::PSI[:Date]
176
+ else
177
+ raise NoDatatypeHandlerAvailableException.new(value)
178
+ end
179
+ end
180
+ # creating locator for datatype
181
+ datatype = topic_map.create_locator(datatype)
182
+ # value must be a String
183
+ value = value.to_s
184
+ # if datatype is xsd:anyURI -> resolve value against base_iri
185
+ if datatype.reference == RTM::PSI[:IRI]
186
+ value = topic_map.create_locator(value).reference
187
+ end
188
+
189
+ begin
190
+ if params[:scope]
191
+ raise("scope must be an Array") unless params[:scope].is_a?(Array)
192
+
193
+ return createOccurrence(type, value, datatype, topic_map.get!(params[:scope]))
194
+
195
+ else #no scope
196
+ return createOccurrence(type, value, datatype, new_empty_java_topic_array)
197
+ end
198
+ rescue java.lang.IllegalArgumentException => iae
199
+ raise(iae.message)
200
+ end
201
+ end
202
+
203
+ # Returns the TopicMap the Topic belongs to.
204
+ #
205
+ # :call-seq:
206
+ # parent -> TopicMap
207
+ #
208
+ def parent
209
+ getParent
210
+ end
211
+ alias :reverse_children :parent
212
+
213
+ superised
214
+ # Returns the Roles played by this Topic.
215
+ #
216
+ # If given, rtype specifies the type of the Roles to be returned;
217
+ # If given, atype specifies the type of the Association
218
+ # from which the returned Roles must be part of.
219
+ #
220
+ # rtype and atype may be a topic reference or Arrays of these types.
221
+ #
222
+ # The result may be empty.
223
+ #
224
+ # :call-seq:
225
+ # roles -> Array of Roles
226
+ # roles(rtype) -> Array of Roles
227
+ # roles(rtype, atype) -> Array of Roles
228
+ #
229
+ def roles_played(rtype=:any, atype=:any)
230
+
231
+ if rtype == :any # -> atype may only be :any
232
+ if atype == :any
233
+ return getRolesPlayed
234
+ else
235
+ raise "Associationtype may only be specified if rtype are specified"
236
+ end
237
+ end
238
+
239
+ # Assume, that rtype is given or set to nil
240
+ # atype may be :any
241
+ rtype = topic_map.get(rtype)
242
+ return Array.new if rtype == nil || (rtype.is_a?(Array) && rtype.include?(nil))
243
+ #Assume that rtype is given and found
244
+
245
+ unless atype == :any
246
+ atype = topic_map.get(atype)
247
+ return Array.new if atype == nil || (atype.is_a?(Array) && atype.include?(nil))
248
+ end
249
+ #Assume that if atype is given, it's found
250
+
251
+ if rtype.is_a?(Array) #several rtype
252
+ if atype == :any #no atype
253
+ return rtype.map{|r| roles_played(r)}.inject(java.util.HashSet.new){|union,element| union.addAll(element); union}
254
+ elsif atype.is_a?(Array) #several atype
255
+ return rtype.map{|r| roles_played(r,atype)}.inject(java.util.HashSet.new){|union,element| union.addAll(element); union}
256
+ else #one associationtype
257
+ return rtype.map{|r| roles_played(r,atype)}.inject(java.util.HashSet.new){|union,element| union.addAll(element); union}
258
+ end
259
+ else #one roletype
260
+ if atype == :any #no atype
261
+ return getRolesPlayed(rtype)
262
+ elsif atype.is_a?(Array) #several atype
263
+ return atype.map{|a| roles_played(rtype,a)}.inject(java.util.HashSet.new){|union,element| union.addAll(element); union}
264
+ else #one associationtype
265
+ return getRolesPlayed(rtype,atype)
266
+ end
267
+ end
268
+ end
269
+ alias :roles :roles_played
270
+
271
+ # Returns the subject identifiers assigned to the current topic.
272
+ #
273
+ # :call-seq:
274
+ # subject_identifiers -> Set of Locators
275
+ #
276
+ def subject_identifiers
277
+ getSubjectIdentifiers
278
+ end
279
+
280
+ superised
281
+ # Adds a subject identifier to the current Topic.
282
+ # Identifier may be a String or Locator.
283
+ #
284
+ # :call-seq:
285
+ # add_subject_identifier(identifier)
286
+ #
287
+ def add_subject_identifier(identifier)
288
+ begin
289
+ if identifier.is_a? Java::OrgTmapiCore::Locator
290
+ addSubjectIdentifier(identifier)
291
+ else
292
+ addSubjectIdentifier(topic_map.create_locator(identifier))
293
+ end
294
+ rescue Java::OrgTmapiCore::IdentityConstraintException => ice
295
+ # TODO add condition to switch off automerge
296
+ self.mergeIn(self.topic_map.get(identifier))
297
+ end
298
+ end
299
+
300
+ superised
301
+ # Removes a subject identifier from the this Topic,
302
+ # if present.
303
+ #
304
+ # Identifier may be a String or Locator.
305
+ #
306
+ # :call-seq:
307
+ # remove_subject_identifier(identifier)
308
+ #
309
+ def remove_subject_identifier(identifier)
310
+ identifier = topic_map.create_locator(identifier) if identifier.is_a? String
311
+ removeSubjectIdentifier(identifier) if identifier.is_a? Java::OrgTmapiCore::Locator
312
+ end
313
+
314
+ # Returns the subject locators assigned to the current topic.
315
+ #
316
+ # :call-seq:
317
+ # subject_locators -> Set of Locators
318
+ #
319
+ def subject_locators
320
+ getSubjectLocators
321
+ end
322
+
323
+ superised
324
+ # Adds a subject locator to the current topic.
325
+ # Identifier may be a String or Locator.
326
+ #
327
+ # :call-seq:
328
+ # add_subject_locator(identifier)
329
+ #
330
+ def add_subject_locator(identifier)
331
+ # TODO Spec
332
+ begin
333
+ if identifier.is_a? Java::OrgTmapiCore::Locator
334
+ addSubjectLocator(identifier)
335
+ else
336
+ addSubjectLocator(topic_map.create_locator(identifier))
337
+ end
338
+ rescue Java::OrgTmapiCore::IdentityConstraintException => ice
339
+ # TODO add condition to switch off automerge
340
+ self.mergeIn(self.topic_map.topic_by_subject_locator(identifier))
341
+ end
342
+ end
343
+
344
+ superised
345
+ # Removes a subject locator from the this Topic,
346
+ # if present.
347
+ #
348
+ # Identifier may be a String or Locator.
349
+ #
350
+ # :call-seq:
351
+ # remove_subject_locator(identifier)
352
+ #
353
+ def remove_subject_locator(identifier)
354
+ identifier = topic_map.create_locator(identifier) if identifier.is_a? String
355
+ removeSubjectLocator(identifier) if identifier.is_a? Java::OrgTmapiCore::Locator
356
+ end
357
+
358
+ # superised
359
+ # # Removes an item identifer from the this Topic,
360
+ # # if present.
361
+ # #
362
+ # # Identifier may be a String or Locator.
363
+ # #
364
+ # # :call-seq:
365
+ # # remove_item_identifier(identifier)
366
+ # #
367
+ # def remove_item_identifier(identifier)
368
+ # identifier = topic_map.create_locator(identifier) if identifier.is_a? String
369
+ # removeItemIdentifier(identifier) if identifier.is_a? Java::OrgTmapiCore::Locator
370
+ # end
371
+
372
+ superised
373
+ # Adds a type given by the identifier to this Topic.
374
+ #
375
+ # Identifier may be a topic reference.
376
+ #
377
+ # :call-seq:
378
+ # add_type(identifier)
379
+ #
380
+ def add_type(identifier)
381
+ if identifier.is_a?(Java::OrgTmapiCore::Topic)
382
+ addType(identifier)
383
+ elsif identifier.is_a?(Java::OrgTmapiCore::Locator) || identifier.is_a?(String)
384
+ addType(topic_map.get!(identifier))
385
+ else
386
+ raise("Identifier must be a Topic, String or Locator")
387
+ end
388
+ end
389
+
390
+ # Adds one or several types given by the identifiers.
391
+ #
392
+ # Identifier may be a topic reference.
393
+ #
394
+ # :call-seq:
395
+ # add_types(identifier1, identifier2, ...)
396
+ #
397
+ def add_types(*args)
398
+ args.flatten!
399
+ args.each do |identifier|
400
+ add_type(identifier)
401
+ end
402
+ end
403
+
404
+
405
+ # Adds an instance given by the identifier to this Topic.
406
+ #
407
+ # Identifier may be a topic reference.
408
+ #
409
+ # :call-seq:
410
+ # add_instance(identifier)
411
+ #
412
+ def add_instance(identifier)
413
+ if identifier.is_a?(Java::OrgTmapiCore::Topic)
414
+ identifier.addType(self)
415
+ elsif identifier.is_a?(Java::OrgTmapiCore::Locator) || identifier.is_a?(String)
416
+ topic_map.get!(identifier).addType(self)
417
+ else
418
+ raise("Identifier must be a Topic, String or Locator")
419
+ end
420
+ end
421
+
422
+ # Adds one or several instances given by the identifiers.
423
+ #
424
+ # Identifier may be a topic reference.
425
+ #
426
+ # :call-seq:
427
+ # add_instances(identifier1, identifier2, ...)
428
+ #
429
+ def add_instances(*args)
430
+ args.flatten!
431
+ args.each do |identifier|
432
+ add_instance(identifier)
433
+ end
434
+ end
435
+
436
+ # Returns the reifiable Construct which is reified by this Topic
437
+ # or nil if this Topic does not reify a statement.
438
+ #
439
+ # :call-seq:
440
+ # reifier -> Name, Occurrence, Variant, Association, Role or TopicMap
441
+ #
442
+ def reified
443
+ getReified
444
+ end
445
+
446
+ # Sets this Topic as reifier of the reifiable Construct, given by the
447
+ # identifier.
448
+ #
449
+ # Identifier may be a Name, Variant, Occurrence, Association, Role or
450
+ # TopicMap.
451
+ #
452
+ # :call-seq:
453
+ # reified = identifier
454
+ #
455
+ def reified=(identifier)
456
+ if identifier.is_a?(Java::OrgTmapiCore::Reifiable)
457
+ identifier.reifier = self
458
+ return
459
+ end
460
+ raise("reified=: Identifier may be a Name, Variant, Occurrence, Association, Role or TopicMap")
461
+ end
462
+
463
+ superised
464
+ # Removes a type given by the identifier of this topic,
465
+ # if present.
466
+ #
467
+ # Identifier may be a topic reference.
468
+ #
469
+ # :call-seq:
470
+ # remove_type(identifier)
471
+ #
472
+ def remove_type(identifier)
473
+ identifier = topic_map.get(identifier)
474
+ removeType(identifier) if identifier
475
+ end
476
+
477
+ # Removes an instance given by the identifier of this topic,
478
+ # if present.
479
+ #
480
+ # Identifier may be a topic reference.
481
+ #
482
+ # :call-seq:
483
+ # remove_instance(identifier)
484
+ #
485
+ def remove_instance(identifier)
486
+ identifier = topic_map.get(identifier)
487
+ return unless identifier
488
+ identifier.removeType(self)
489
+ end
490
+
491
+ private
492
+ def new_empty_java_topic_array
493
+ [].to_java(Java::OrgTmapiCore::Topic)
494
+ end
495
+
496
+ class NoDatatypeHandlerAvailableException < Exception
497
+ def initialize(value)
498
+ super "Cannot map #{value} to an occurrence value+datatype. Maybe you need to add a handler for your Ruby object type."
499
+ end
500
+ end
501
+ end
502
+
503
+
504
+