Class: RTM::JavaTMAPI
- Inherits:
-
Engine
- Object
- Engine
- RTM::JavaTMAPI
- Extended by:
- Superiseable
- Defined in:
- lib/rtm/javatmapi.rb
Instance Attribute Summary collapse
-
#tms ⇒ Object
readonly
Returns the value of attribute tms.
-
#tmsf ⇒ Object
readonly
Returns the value of attribute tmsf.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](*args) ⇒ Object
Returns topic maps stored in this connection.
-
#close ⇒ Object
Applications SHOULD call this method when the topic map is no longer required.
-
#create(base_locator, *args) ⇒ Object
(also: #create_topic_map, #createTopicMap)
Creates and returns a new topic map given a base_locator.
-
#create_locator(reference) ⇒ Object
(also: #createLocator)
Returns a Locator instance representing the specified IRI reference.
- #create_system ⇒ Object
-
#getFeature(feature_name) ⇒ Object
Returns the value of the feature specified by feature_name for the TopicMapSystem instance stored by this connection: * true, if the named feature is enabled * false if the named feature is disabled.
-
#getLocators ⇒ Object
Returns all storage addresses of TopicMap instances known by this connection.
-
#locators ⇒ Object
(also: #get_locators)
Returns all storage addresses of TopicMap instances known by this connection.
-
#property(property_name) ⇒ Object
(also: #get_property, #getProperty)
Returns a property in the underlying implementation of TopicMapSystem.
- #refresh ⇒ Object
- #set_features(features) ⇒ Object
- #set_properties(properties) ⇒ Object
- #set_tmsf(tmsf) ⇒ Object
-
#topic_map(iri) ⇒ Object
(also: #getTopicMap, #get_topic_map)
Retrieves a topic map managed by this connection with the specified storage address iri.
Methods included from Superiseable
method_added, register_java_implementation, superised, superising
Instance Attribute Details
#tms ⇒ Object (readonly)
Returns the value of attribute tms.
47 48 49 |
# File 'lib/rtm/javatmapi.rb', line 47 def tms @tms end |
#tmsf ⇒ Object (readonly)
Returns the value of attribute tmsf.
46 47 48 |
# File 'lib/rtm/javatmapi.rb', line 46 def tmsf @tmsf end |
Class Method Details
.abstract? ⇒ Boolean
40 41 42 |
# File 'lib/rtm/javatmapi.rb', line 40 def self.abstract? self == JavaTMAPI end |
Instance Method Details
#[](*args) ⇒ Object
Returns topic maps stored in this connection. The optional arguments may specify the iri the topic maps are stored at.
The iris may be Strings and/or Locators. The result may be empty.
:call-seq:
[] -> Array of TopicMaps
[iri1, iri2, ...] -> Array of TopicMaps
197 198 199 200 201 202 |
# File 'lib/rtm/javatmapi.rb', line 197 def [](*args) if args.empty? return @tms.getLocators.map {|l| @tms.getTopicMap(l)} end return args.map{|l| @tms.getTopicMap(l)} end |
#close ⇒ Object
Applications SHOULD call this method when the topic map is no longer required
205 206 207 208 209 210 |
# File 'lib/rtm/javatmapi.rb', line 205 def close if defined?(@tms) && @tms.nil? @tms.close @tms = nil end end |
#create(base_locator, *args) ⇒ Object Also known as: create_topic_map, createTopicMap
Creates and returns a new topic map given a base_locator. The base locator may be a String or a Locator.
:call-seq:
create(base_locator) -> Topic Map
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/rtm/javatmapi.rb', line 122 def create(base_locator, *args) base_locator = @tms.create_locator(base_locator) if base_locator.is_a?(String) raise("base_locator must be a String or Locator") unless base_locator.is_a?(Locator) if (@tms.getLocators.include?(base_locator)) tm = @tms.getTopicMap(base_locator) else tm = @tms.createTopicMap(base_locator) end tm.base_iri ||= base_locator.reference #safe as String tm.engine = self tm.prefixes = {} return tm #end end |
#create_locator(reference) ⇒ Object Also known as: createLocator
Returns a Locator instance representing the specified IRI reference. The specified IRI reference is assumed to be absolute.
:call-seq:
create_locator(reference) -> Locator
111 112 113 |
# File 'lib/rtm/javatmapi.rb', line 111 def create_locator(reference) @tms.create_locator(reference) end |
#create_system ⇒ Object
96 97 98 |
# File 'lib/rtm/javatmapi.rb', line 96 def create_system @tms = @tmsf.newTopicMapSystem end |
#getFeature(feature_name) ⇒ Object
Returns the value of the feature specified by feature_name for the TopicMapSystem instance stored by this connection:
-
true, if the named feature is enabled
-
false if the named feature is disabled
176 177 178 |
# File 'lib/rtm/javatmapi.rb', line 176 def getFeature(feature_name) @tms.getFeature(feature_name) end |
#getLocators ⇒ Object
Returns all storage addresses of TopicMap instances known by this connection. The return value may be empty but is never null.
:call-seq:
locators -> Array of Locators
168 169 170 |
# File 'lib/rtm/javatmapi.rb', line 168 def getLocators @tms.getLocators end |
#locators ⇒ Object Also known as: get_locators
Returns all storage addresses of TopicMap instances known by this connection. The return value may be empty but is never null.
:call-seq:
locators -> Array of Strings
157 158 159 |
# File 'lib/rtm/javatmapi.rb', line 157 def locators() @tms.getLocators.map {|l| l.reference} end |
#property(property_name) ⇒ Object Also known as: get_property, getProperty
Returns a property in the underlying implementation of TopicMapSystem.
181 182 183 |
# File 'lib/rtm/javatmapi.rb', line 181 def property(property_name) @tmsf.getProperty(property_name) end |
#refresh ⇒ Object
100 101 102 103 |
# File 'lib/rtm/javatmapi.rb', line 100 def refresh RTM.included_modules.each {|im| self.extend(im)} RTM.included_modules.each {|im| self.class.class_eval("include #{im}")} end |
#set_features(features) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rtm/javatmapi.rb', line 80 def set_features(features) if features.is_a?(Hash) features.each do |key, value| @tmsf.setFeature(key, value) end elsif features.is_a?(String) && File.exists?(features) # in contrast to properties, features values are always boolean in_file = File.read_lines(features) in_file.each do |line| key, value = line.strip.split(/\s*[=:]\s*/, 2) next if key.blank? or value.blank? @tmsf.setFeature(key, %w[true 1 on enabled ja wahr da oui jo].include?(value)) # multi cultural feature files :) end end end |
#set_properties(properties) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rtm/javatmapi.rb', line 49 def set_properties(properties) if properties.is_a?(Hash) properties.each do |key, value| @tmsf.setProperty(key, value) end elsif properties.is_a?(String) && File.exists?(properties) in_file = java.io.FileInputStream.new(properties) props = java.util.Properties.new props.load(in_file) if @tmsf.respond_to?(:setProperties) # This is not part of the TMAPI interfaces but e.g. Ontopia supports it @tmsf.setProperties(props) else # Try to read a java properties file. This ignores file continuations with backslash and may be incomplete in other respects in_file = File.read_lines(features) in_file.each do |line| line.strip! # strip whitespaces at begin and end next if line.blank? # skip empty lines next if line =~ /^[#!]/ # skip comments key, value = line.split(/\s*[=:\s]\s*/, 2) # split at "=", ":" or any whitespace surrounded by any number of whitespace next if key.blank? # the value may be the empty string @tmsf.setFeature(key, value) end end end end |
#set_tmsf(tmsf) ⇒ Object
76 77 78 |
# File 'lib/rtm/javatmapi.rb', line 76 def set_tmsf(tmsf) @tmsf = tmsf end |
#topic_map(iri) ⇒ Object Also known as: getTopicMap, get_topic_map
Retrieves a topic map managed by this connection with the specified storage address iri. The iri may be a String or Locator.
If no topic map is stored at the specified iri, nil is returned.
144 145 146 147 |
# File 'lib/rtm/javatmapi.rb', line 144 def topic_map(iri) raise("The iri must be a String or Locator") unless iri.is_a?(Locator) || iri.is_a?(String) return @tms.getTopicMap(iri) end |