Class: RTM::JavaTMAPI

Inherits:
Engine
  • Object
show all
Extended by:
Superiseable
Includes:
Java::OrgTmapiCore::TopicMapSystem
Defined in:
lib/rtm/javatmapi.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Superiseable

method_added, register_java_implementation, superised, superising

Instance Attribute Details

#tmsObject (readonly)

Returns the value of attribute tms.



33
34
35
# File 'lib/rtm/javatmapi.rb', line 33

def tms
  @tms
end

#tmsfObject (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

Returns:

  • (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


213
214
215
216
217
218
# File 'lib/rtm/javatmapi.rb', line 213

def [](*args)
  if args.empty?
    return @tms.getLocators.map {|l| topic_map(l)}
  end
  return args.map{|l| topic_map(l)}
end

#closeObject

Applications SHOULD call this method when the topic map system is no longer required



221
222
223
224
225
226
# File 'lib/rtm/javatmapi.rb', line 221

def close
  if defined?(@tms) && @tms
    @tms.close
    @tms = nil
  end
end

#create(locator_or_tm) ⇒ Object Also known as: create_topic_map, createTopicMap

Creates and returns a new topic map given a locator. If a topic map is given directly it is returned. If a topic map with this locator already exists the existing one is returned. The locator may be a String or a Locator.

:call-seq:

create(locator_or_tm) -> Topic Map


110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/rtm/javatmapi.rb', line 110

def create(locator_or_tm)
  return locator_or_tm if locator_or_tm.is_a?(RTM::TopicMap)
  locator = locator_or_tm
  raise("locator must be a String or Locator but is: #{locator.inspect}") unless (locator.is_a?(RTM::Locator) || locator.is_a?(String))
  tm = topic_map(locator)
  unless tm
    tm = @tms.createTopicMap(locator)
    tm.add_prefix("xsd", RTM::PREFIX[:xsd]) # default prefix for xsd
    tm.set_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_systemObject



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 = topic_map(locator)
    tm.prefixes.clear
    tm.clear unless self.identifier == :hatana
    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.

Returns:

  • (Boolean)


142
143
144
145
# File 'lib/rtm/javatmapi.rb', line 142

def existing?(locator)
  raise("locator must be a String or Locator") unless (locator.is_a?(RTM::Locator) || locator.is_a?(String))
  return @tms.getTopicMap(locator) ? true : false
end

#feature(feature_name) ⇒ Object Also known as: get_feature, getFeature

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



190
191
192
# File 'lib/rtm/javatmapi.rb', line 190

def feature(feature_name)
  @tms.getFeature(feature_name)
end

#getLocatorsObject

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


182
183
184
# File 'lib/rtm/javatmapi.rb', line 182

def getLocators
  @tms.getLocators
end

#locatorsObject 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


171
172
173
# File 'lib/rtm/javatmapi.rb', line 171

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.



197
198
199
# File 'lib/rtm/javatmapi.rb', line 197

def property(property_name)
  @tmsf.getProperty(property_name)
end

#refreshObject



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.



152
153
154
155
156
157
158
159
160
161
# File 'lib/rtm/javatmapi.rb', line 152

def topic_map(iri)
  return iri if iri.is_a?(RTM::TopicMap)
  raise("The iri must be a String or Locator") unless (iri.is_a?(Locator) || iri.is_a?(String))
  tm = @tms.getTopicMap(iri) #could be nil
  if tm
    tm.add_prefix("xsd", RTM::PREFIX[:xsd]) # hack, default prefix for xsd
    tm.set_engine(self) # hack
  end
  tm
end