rtm-javatmapi 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,15 +2,19 @@
2
2
  # License: Apache License, Version 2.0
3
3
 
4
4
  module Java::OrgTmapiCore::TopicMap
5
-
5
+
6
6
  URI_PATTERN = ":"
7
-
7
+
8
+ include RTM::TopicMap
8
9
  extend Superiseable
9
- #include RTM::TopicMap
10
10
 
11
11
  attr_accessor :prefixes #hash
12
12
 
13
- attr_accessor :base_iri
13
+ attr_reader :base_iri
14
+ def base_iri=(base_iri)
15
+ class << self;undef :base_iri=;end
16
+ @base_iri = base_iri
17
+ end
14
18
 
15
19
  alias :base_locator :base_iri
16
20
 
@@ -130,7 +134,7 @@ module Java::OrgTmapiCore::TopicMap
130
134
  # the role player: the corresponding value in the Hash.
131
135
  #
132
136
  # Each identifier (type, scope-identifier, roletype-identifier and
133
- # player-identifier) may be a Topic or Topic-Reference.
137
+ # player-identifier) may be a topic reference.
134
138
  #
135
139
  # :call-seq:
136
140
  # create_association(type) -> Association
@@ -170,10 +174,10 @@ module Java::OrgTmapiCore::TopicMap
170
174
  end
171
175
  raise("create_association: type must be a Topic or Topic-Reference") unless type.is_a?(Java::OrgTmapiCore::Topic) || type.is_a?(String) || type.is_a?(Java::OrgTmapiCore::Locator)
172
176
  if scope == :ucs
173
- assoc = createAssociation(get!(type),[].to_java(org.tmapi.core.Topic))
177
+ assoc = createAssociation(get!(type),[].to_java(org.tmapi.core.Topic))
174
178
  else
175
179
  raise("create_association: scope must be an Array") unless scope.is_a?(Array)
176
- assoc = scope.empty? ? createAssociation(get!(type),[].to_java(org.tmapi.core.Topic)) : createAssociation(get!(type),get!(scope))
180
+ assoc = scope.empty? ? createAssociation(get!(type),[].to_java(org.tmapi.core.Topic)) : createAssociation(get!(type),get!(scope))
177
181
  end
178
182
  raise("create_association: roles must be a Hash") unless roles.is_a?(Hash)
179
183
  roles.each do |k,v|
@@ -234,12 +238,10 @@ module Java::OrgTmapiCore::TopicMap
234
238
  #
235
239
  def instances(type = :any)
236
240
  return types.map{|t| t.instances.to_a}.flatten.uniq if type == :any
237
- type = topic_map.get(type) unless type.is_a?(RTM::Topic)
238
- return type ? type_instance_index.getTopics(type).to_a : Array.new
241
+ type = self.get(type) unless type.is_a?(RTM::Topic)
242
+ return type ? type_instance_index.getTopics(type).to_a : []
239
243
  end
240
244
 
241
-
242
-
243
245
  # Returns all topics in the topic map that are used as type
244
246
  # in an "type-instance"-relationship.
245
247
  #
@@ -250,6 +252,26 @@ module Java::OrgTmapiCore::TopicMap
250
252
  type_instance_index.getTopicTypes
251
253
  end
252
254
 
255
+ superised
256
+ # Returns all associations contained in this topic map.
257
+ #
258
+ # The optional argument specifies the type the associations should have,
259
+ # i.e. all instances of the specified type are returned. Type may be a
260
+ # topic reference.
261
+ #
262
+ # The return value may be empty.
263
+ #
264
+ # :call_spec:
265
+ # associations -> Set of Associations
266
+ # associations(type) -> Array of Associations
267
+ #
268
+ def associations(type = :any)
269
+ return getAssociations if type == :any
270
+ raise("associations(type): type must be a topic reference.") unless (type.is_a?(RTM::Topic) || type.is_a?(RTM::Locator) || type.is_a?(String))
271
+ type = self.get(type) unless type.is_a?(RTM::Topic)
272
+ return type ? type_instance_index.getAssociations(type).to_a : []
273
+ end
274
+
253
275
  # Returns all topics in this topic map that are used
254
276
  # as types of associations.
255
277
  #
@@ -438,14 +460,14 @@ module Java::OrgTmapiCore::TopicMap
438
460
  #
439
461
  def create_topic_by(identifier)
440
462
  case identifier
441
- when Java::OrgTmapiCore::Locator
442
- return create_topic_by_subject_identifier(identifier)
443
- when String
444
- reroute_for_create(identifier)
445
- when Array
446
- return identifier.map{|i| create_topic_by(i)}
447
- else
448
- return nil
463
+ when Java::OrgTmapiCore::Locator
464
+ return create_topic_by_subject_identifier(identifier)
465
+ when String
466
+ reroute_for_create(identifier)
467
+ when Array
468
+ return identifier.map{|i| create_topic_by(i)}
469
+ else
470
+ return nil
449
471
  end
450
472
  end
451
473
 
@@ -471,27 +493,35 @@ module Java::OrgTmapiCore::TopicMap
471
493
  # get(identifier-Array) -> Array of Topics or empty Array
472
494
  #
473
495
  def get(identifier)
474
- case identifier
496
+ self.cached(self, :get, identifier) {
497
+ case identifier
475
498
  when nil
476
- return nil
499
+ nil
477
500
  when Java::OrgTmapiCore::Topic
478
- return identifier
501
+ identifier
479
502
  when Java::OrgTmapiCore::Locator
480
- return get_construct_by_item_identifier(identifier) if get_construct_by_item_identifier(identifier).is_a?(Java::OrgTmapiCore::Topic)
481
- return get_topic_by_subject_identifier(identifier) if get_topic_by_subject_identifier(identifier)
482
- #return get_topic_by_subject_locator(identifier) if get_topic_by_subject_locator(identifier) #not allowed because Topics with equals si and ii are merged but sl not
483
- return nil
503
+ if get_construct_by_item_identifier(identifier).is_a?(Java::OrgTmapiCore::Topic)
504
+ get_construct_by_item_identifier(identifier)
505
+ elsif get_topic_by_subject_identifier(identifier)
506
+ get_topic_by_subject_identifier(identifier)
507
+ else
508
+ #return get_topic_by_subject_locator(identifier) if get_topic_by_subject_locator(identifier) #not allowed because Topics with equals si and ii are merged but sl not
509
+ nil
510
+ end
484
511
  when String
485
512
  reroute_for_get(identifier)
486
513
  when Array
487
514
  # in: multi array -> out: multi array
488
- return identifier.map{|i| get(i)}
489
- #when Hash
515
+ identifier.map{|i| get(i)}
516
+ #when Hash
490
517
  #TODO: use case for getting Topics if argument is a hash
491
518
  else
492
519
  raise("get(#{identifier.inspect}): arguments do not match")
493
- end
520
+ end
521
+ }
494
522
  end
523
+ alias :topic :get
524
+ # alias :[] :get # not sure if this is a good idea, for now we leave it out
495
525
 
496
526
  # Calls get(identifier) and returns the Topic or Array of Topics according
497
527
  # to the nature of the identifier (Topic/Topic-References or
@@ -510,13 +540,14 @@ module Java::OrgTmapiCore::TopicMap
510
540
  # get!(identifier-Array) -> Array of Topics
511
541
  #
512
542
  def get!(identifier)
513
- return nil unless identifier
514
- if identifier.is_a?(Array)
515
- return identifier.map{|i| get!(i)}
516
- end
517
- found = get(identifier)
518
- return found ? found : create_topic_by(identifier)
543
+ return nil unless identifier
544
+ if identifier.is_a?(Array)
545
+ return identifier.map{|i| get!(i)}
546
+ end
547
+ found = get(identifier)
548
+ return found ? found : create_topic_by(identifier)
519
549
  end
550
+ alias :topic! :get!
520
551
 
521
552
  def construct_by_id(id)
522
553
  getConstructById(id)
@@ -569,13 +600,13 @@ module Java::OrgTmapiCore::TopicMap
569
600
  # Executes yield on locator and returns the result.
570
601
  def get_stuff(identifier)
571
602
  unless (identifier.is_a?(String)) || (identifier.is_a?(Java::OrgTmapiCore::Locator))
572
- identifier_in_use = identifier.map{|x|(x.is_a? Java::OrgTmapiCore::Locator)? x : create_locator(x)}
573
- return identifier_in_use.map{|y| yield y}
603
+ identifier_in_use = identifier.map{|x|(x.is_a? Java::OrgTmapiCore::Locator)? x : create_locator(x)}
604
+ return identifier_in_use.map{|y| yield y}
574
605
  else
575
- unless identifier.is_a? Java::OrgTmapiCore::Locator
576
- identifier = create_locator(identifier)
577
- end
578
- return (yield identifier)
606
+ unless identifier.is_a? Java::OrgTmapiCore::Locator
607
+ identifier = create_locator(identifier)
608
+ end
609
+ return (yield identifier)
579
610
  end
580
611
  end
581
612
 
@@ -588,14 +619,14 @@ module Java::OrgTmapiCore::TopicMap
588
619
  #
589
620
  def reroute_for_create(identifier)
590
621
  case identifier
591
- when /^(\^|ii:)\s*(.*)/ #identifiers starts with ^ or ii:
592
- create_topic_by_item_identifier(create_locator($2))
593
- when /^(=|sl:)\s*(.*)/ #identifier starts with = or sl:
594
- create_topic_by_subject_locator(create_locator($2))
595
- when /^(si:)\s*(.*)/ #identifier starts with si:
596
- create_topic_by_subject_identifier(create_locator($2))
597
- else #identifier does not start with a special character
598
- create_topic_by_subject_identifier(create_locator(identifier.lstrip))#lstrip: leading whitespace chars removed
622
+ when /^(\^|ii:)\s*(.*)/ #identifiers starts with ^ or ii:
623
+ create_topic_by_item_identifier(create_locator($2))
624
+ when /^(=|sl:)\s*(.*)/ #identifier starts with = or sl:
625
+ create_topic_by_subject_locator(create_locator($2))
626
+ when /^(si:)\s*(.*)/ #identifier starts with si:
627
+ create_topic_by_subject_identifier(create_locator($2))
628
+ else #identifier does not start with a special character
629
+ create_topic_by_subject_identifier(create_locator(identifier.lstrip))#lstrip: leading whitespace chars removed
599
630
  end
600
631
  end
601
632
 
@@ -608,14 +639,14 @@ module Java::OrgTmapiCore::TopicMap
608
639
  #
609
640
  def reroute_for_get(identifier)
610
641
  case identifier
611
- when /^(si:|sl:|ii:|=|^)$/
612
- return nil
613
- when /^(\^|ii:)\s*(.*)/ #identifiers starts with ^ or ii:
614
- get_construct_by_item_identifier(create_locator($2))
615
- when /^(=|sl:)\s*(.+)/ #identifier starts with = or sl:
616
- get_topic_by_subject_locator(create_locator($2))
617
- when /^(si:)\s*(.+)/ #identifier starts with si:
618
- get_topic_by_subject_identifier(create_locator($2))
642
+ when /^(si:|sl:|ii:|=|^)$/
643
+ return nil
644
+ when /^(\^|ii:)\s*(.*)/ #identifiers starts with ^ or ii:
645
+ get_construct_by_item_identifier(create_locator($2))
646
+ when /^(=|sl:)\s*(.+)/ #identifier starts with = or sl:
647
+ get_topic_by_subject_locator(create_locator($2))
648
+ when /^(si:)\s*(.+)/ #identifier starts with si:
649
+ get_topic_by_subject_identifier(create_locator($2))
619
650
  else #identifier does not start with a special character
620
651
  get_topic_by_subject_identifier(create_locator(identifier.lstrip)) #lstrip: leading whitespace chars removed
621
652
  end
@@ -2,8 +2,8 @@
2
2
  # License: Apache License, Version 2.0
3
3
 
4
4
  module Java::OrgTmapiCore::Typed
5
-
6
- #include RTM::Typed
5
+
6
+ include RTM::Typed
7
7
  extend Superiseable
8
8
 
9
9
  # Returns the type of this typed construct
@@ -2,9 +2,9 @@
2
2
  # License: Apache License, Version 2.0
3
3
 
4
4
  module Java::OrgTmapiCore::Variant
5
-
6
- #include RTM::Variant
7
- #extend Superiseable
5
+
6
+ include RTM::Variant
7
+ extend Superiseable
8
8
 
9
9
  # Returns the Name this Variant belongs to.
10
10
  #
@@ -12,8 +12,8 @@ module Java::OrgTmapiCore::Variant
12
12
  # parent -> Name
13
13
  #
14
14
  def parent
15
- getParent
16
- end
15
+ getParent
16
+ end
17
17
  alias :reverse_children :parent
18
18
 
19
19
  end
@@ -2,7 +2,7 @@
2
2
  # License: Apache License, Version 2.0
3
3
 
4
4
  module Superiseable
5
-
5
+
6
6
  def superised
7
7
  @superised = true
8
8
  end
@@ -15,60 +15,17 @@ module Superiseable
15
15
  end
16
16
 
17
17
  def superising method_name
18
- @to_superize ||= []
19
- @to_superize << method_name
18
+ @superized_methods ||= []
19
+ @superized_methods << method_name
20
20
  end
21
21
 
22
- def superize
23
- @to_superize.each do |method_name|
24
- self::JavaImplementations[self].each do |c|
25
- # puts "Superising #{method_name} in #{self} (#{c})"
26
- c.class_eval do
27
- define_method(method_name) { |*args| super *args}
28
- end
22
+ def register_java_implementation(klass)
23
+ self.included(klass) if self.respond_to?(:included)
24
+ return unless @superized_methods
25
+ @superized_methods.each do |method_name|
26
+ klass.class_eval do
27
+ define_method(method_name) { |*args| super *args}
29
28
  end
30
29
  end
31
30
  end
32
-
33
-
34
- # def superising method_name
35
- # start = Time.now
36
- #
37
- # puts self
38
- # puts self::JavaImplementations[self]
39
- #
40
- # todo = self
41
- #
42
- ## # TODO docu
43
- ## if todo == RTM::Scoped
44
- ## todo = [Java::OrgTmapiCore::Name, Java::OrgTmapiCore::Occurrence, Java::OrgTmapiCore::Association, Java::OrgTmapiCore::Variant]
45
- ## elsif todo == RTM::Reifiable
46
- ## todo = [Java::OrgTmapiCore::Association, Java::OrgTmapiCore::Name, Java::OrgTmapiCore::Occurrence, Java::OrgTmapiCore::Role, Java::OrgTmapiCore::TopicMap, Java::OrgTmapiCore::Variant]
47
- ## elsif todo == RTM::Construct
48
- ## todo = [Java::OrgTmapiCore::Association, Java::OrgTmapiCore::Name, Java::OrgTmapiCore::Occurrence, Java::OrgTmapiCore::Role, Java::OrgTmapiCore::TopicMap, Java::OrgTmapiCore::Variant, Java::OrgTmapiCore::Topic]
49
- ## elsif todo == RTM::Typed
50
- ## todo = [Java::OrgTmapiCore::Association, Java::OrgTmapiCore::Name, Java::OrgTmapiCore::Occurrence, Java::OrgTmapiCore::Role]
51
- ## end
52
- # todo = [todo].flatten
53
- #
54
- #
55
- # implFinder = ::ImplementationsForInterface.new
56
- # if $CLASSPATH
57
- # $CLASSPATH.to_a.each do |entry|
58
- # entry.slice!(/^file:/)
59
- # implFinder.addPathEntry(entry)
60
- # end
61
- # end
62
- #
63
- # todo.each do |i|
64
- # IMPLEMENTATIONS[i.java_class] ||= implFinder.classInformationsFor(i.java_class).select {|c| !c.getClassName.include? "$" }.map {|c| eval(c.getClassName) }
65
- # IMPLEMENTATIONS[i.java_class].each do |c|
66
- # c.class_eval do
67
- # define_method(method_name) { |*args| super *args}
68
- # end
69
- # end
70
- # end
71
- # #puts "Und so lange hat es gedauert:" + (Time.now - start).to_s
72
- # end
73
-
74
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtm-javatmapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Bock
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2010-02-05 00:00:00 +01:00
15
+ date: 2010-02-21 00:00:00 +01:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -23,10 +23,10 @@ dependencies:
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.0
26
+ version: 0.2.1
27
27
  version:
28
28
  description: " Ruby Topic Maps is a Topic Maps engine written in Ruby.\n This backend engine uses any Java TMAPI 2.0 compatible backend. See http://www.tmapi.org/2.0/.\n You can provide your own TMAPI 2.0 compatible implementation or use one of the existing ones:\n * rtm-ontopia\n * rtm-tinytim\n * rtm-sesametm \n"
29
- email: "#rtm+rtm-javatmapi-gem-20100205@topicmapslab.de"
29
+ email: rtm+rtm-javatmapi-gem-20100221@topicmapslab.de
30
30
  executables: []
31
31
 
32
32
  extensions: []
@@ -35,9 +35,9 @@ extra_rdoc_files: []
35
35
 
36
36
  files:
37
37
  - lib/rtm/javatmapi/aliases.rb
38
- - lib/rtm/javatmapi/base.rb
39
38
  - lib/rtm/javatmapi/core/association.rb
40
39
  - lib/rtm/javatmapi/core/construct.rb
40
+ - lib/rtm/javatmapi/core/datatype_aware.rb
41
41
  - lib/rtm/javatmapi/core/locator.rb
42
42
  - lib/rtm/javatmapi/core/name.rb
43
43
  - lib/rtm/javatmapi/core/occurrence.rb
@@ -52,8 +52,6 @@ files:
52
52
  - lib/rtm/javatmapi/core.rb
53
53
  - lib/rtm/javatmapi/ext/java_util_set.rb
54
54
  - lib/rtm/javatmapi/ext.rb
55
- - lib/rtm/javatmapi/inclusion.rb
56
- - lib/rtm/javatmapi/java_implementations.rb
57
55
  - lib/rtm/javatmapi/superiseable.rb
58
56
  - lib/rtm/javatmapi.rb
59
57
  - lib/rtm/javatmapi/javalibs/asm-2.2.3.jar
@@ -80,7 +78,7 @@ files:
80
78
  - lib/rtm/javatmapi/javalibs/slf4j-api-1.5.8.jar
81
79
  - lib/rtm/javatmapi/javalibs/slf4j-log4j12-1.5.8.jar
82
80
  - lib/rtm/javatmapi/javalibs/tinytim-mio-2.0.0a5.jar
83
- - lib/rtm/javatmapi/javalibs/tmapi-2.0a2.jar
81
+ - lib/rtm/javatmapi/javalibs/tmapi-2.0.jar
84
82
  - lib/rtm/javatmapi/javalibs/tmapix-io-0.3.0-snapshot-200910281502.jar
85
83
  - lib/rtm/javatmapi/javalibs/trove-2.0.4.jar
86
84
  - LICENSE
@@ -1,30 +0,0 @@
1
- # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
- # License: Apache License, Version 2.0
3
-
4
- module RTM
5
-
6
- def self.connect
7
- @@tmsf = TopicMapSystemFactory.newInstance.newTopicMapSystem
8
- end
9
-
10
- def self.create(base_locator)
11
- @@tmsf.createTopicMap(base_locator)
12
- end
13
-
14
-
15
- def self.[](*args)
16
- if args.size == 0
17
- return @@tmsf.getLocators.map {|l| @@tmsf.getTopicMap l}
18
- end
19
- args.map{|l| @@tmsf.getTopicMap l }
20
- end
21
-
22
- # Applications SHOULD call this method when the RTM is no longer required
23
- def self.close
24
- if defined?(@@tmsf) && @@tmsf.nil?
25
- @@tmsf.close
26
- @@tmsf = nil
27
- end
28
- end
29
-
30
- end
@@ -1,46 +0,0 @@
1
- # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
- # License: Apache License, Version 2.0
3
-
4
- module Java::OrgTmapiCore::TopicMap
5
- include RTM::TopicMap
6
- end
7
-
8
- module Java::OrgTmapiCore::Topic
9
- include RTM::Topic
10
- end
11
-
12
- module Java::OrgTmapiCore::Association
13
- include RTM::Association
14
- end
15
-
16
- module Java::OrgTmapiCore::Name
17
- include RTM::Name
18
- end
19
-
20
- module Java::OrgTmapiCore::Occurrence
21
- include RTM::Occurrence
22
- end
23
-
24
- module Java::OrgTmapiCore::Variant
25
- include RTM::Variant
26
- end
27
-
28
- module Java::OrgTmapiCore::Role
29
- include RTM::Role
30
- end
31
-
32
- module Java::OrgTmapiCore::Locator
33
- include RTM::Locator
34
- end
35
-
36
- module Java::OrgTmapiCore::Reifiable
37
- include RTM::Reifiable
38
- end
39
-
40
- module Java::OrgTmapiCore::Scoped
41
- include RTM::Scoped
42
- end
43
-
44
- module Java::OrgTmapiCore::Typed
45
- include RTM::Typed
46
- end