Class: RTM::JavaTMAPI
- Inherits:
-
Engine
- Object
- Engine
- RTM::JavaTMAPI
- Extended by:
- Superiseable
- Includes:
- Java::OrgTmapiCore::TopicMapSystem
- 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(locator) ⇒ Object
(also: #create_topic_map, #createTopicMap)
Creates and returns a new topic map given a locator.
-
#create_locator(reference) ⇒ Object
(also: #createLocator)
Returns a Locator instance representing the specified IRI reference.
- #create_system ⇒ Object
-
#delete(locator) ⇒ Object
(also: #delete_topic_map, #deleteTopicMap)
Deletes the topic map from the engine.
-
#existing?(locator) ⇒ Boolean
States if the topic map given by the locator is existing in the engine.
-
#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.
33 34 35 |
# File 'lib/rtm/javatmapi.rb', line 33 def tms @tms end |
#tmsf ⇒ Object (readonly)
Returns the value of attribute tmsf.
32 33 34 |
# File 'lib/rtm/javatmapi.rb', line 32 def tmsf @tmsf end |
Class Method Details
.abstract? ⇒ Boolean
26 27 28 |
# File 'lib/rtm/javatmapi.rb', line 26 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
206 207 208 209 210 211 |
# File 'lib/rtm/javatmapi.rb', line 206 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
214 215 216 217 218 219 |
# File 'lib/rtm/javatmapi.rb', line 214 def close if defined?(@tms) && @tms.nil? @tms.close @tms = nil end end |
#create(locator) ⇒ Object Also known as: create_topic_map, createTopicMap
Creates and returns a new topic map given a locator. The locator may be a String or a Locator.
:call-seq:
create(locator) -> Topic Map
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/rtm/javatmapi.rb', line 108 def create(locator) locator = @tms.create_locator(locator) if locator.is_a?(String) raise("locator must be a String or Locator but is: #{locator.inspect}") unless locator.is_a?(RTM::Locator) if (@tms.getLocators.include?(locator)) tm = @tms.getTopicMap(locator) tm.add_prefix("xsd", RTM::PREFIX[:xsd]) # hack, default prefix for xsd tm.engine = self # hack else tm = @tms.createTopicMap(locator) tm.add_prefix("xsd", RTM::PREFIX[:xsd]) # default prefix for xsd tm.engine = self end tm 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
97 98 99 |
# File 'lib/rtm/javatmapi.rb', line 97 def create_locator(reference) @tms.create_locator(reference) end |
#create_system ⇒ Object
82 83 84 |
# File 'lib/rtm/javatmapi.rb', line 82 def create_system @tms = @tmsf.newTopicMapSystem end |
#delete(locator) ⇒ Object Also known as: delete_topic_map, deleteTopicMap
Deletes the topic map from the engine.
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/rtm/javatmapi.rb', line 126 def delete(locator) locator = @tms.create_locator(locator) if locator.is_a?(String) raise("locator must be a String or Locator") unless locator.is_a?(RTM::Locator) if (@tms.getLocators.include?(locator)) tm = @tms.getTopicMap(locator) tm.prefixes.clear tm.clear tm.remove else raise("Topic Map with base locator #{locator.reference} not existing") end end |
#existing?(locator) ⇒ Boolean
States if the topic map given by the locator is existing in the engine.
142 143 144 145 146 |
# File 'lib/rtm/javatmapi.rb', line 142 def existing?(locator) locator = @tms.create_locator(locator) if locator.is_a?(String) raise("locator must be a String or Locator") unless locator.is_a?(RTM::Locator) return @tms.getTopicMap(locator) ? true : false 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
185 186 187 |
# File 'lib/rtm/javatmapi.rb', line 185 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
177 178 179 |
# File 'lib/rtm/javatmapi.rb', line 177 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
166 167 168 |
# File 'lib/rtm/javatmapi.rb', line 166 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.
190 191 192 |
# File 'lib/rtm/javatmapi.rb', line 190 def property(property_name) @tmsf.getProperty(property_name) end |
#refresh ⇒ Object
86 87 88 89 |
# File 'lib/rtm/javatmapi.rb', line 86 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
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rtm/javatmapi.rb', line 66 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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rtm/javatmapi.rb', line 35 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
62 63 64 |
# File 'lib/rtm/javatmapi.rb', line 62 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.
153 154 155 156 |
# File 'lib/rtm/javatmapi.rb', line 153 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 |