Class: RTM::JavaTMAPI

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

Instance Attribute Summary

Class Method Summary

Instance Method Summary

Methods included from Superiseable

method_added, register_java_implementation, superised, superising

Methods inherited from Engine

[], add, all, #check, connect, default, detect, identifier, #identifier, inherited, #initialize, list, load, load!

Constructor Details

This class inherits a constructor from RTM::Engine

Instance Attribute Details

- (Object) tms (readonly)

Returns the value of attribute tms



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

def tms
  @tms
end

- (Object) tmsf (readonly)

Returns the value of attribute tmsf



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

def tmsf
  @tmsf
end

Class Method Details

+ (Boolean) abstract?

Returns:

  • (Boolean)


26
27
28
# File 'rtm-javatmapi/lib/rtm/javatmapi.rb', line 26

def self.abstract?
  self == JavaTMAPI
end

Instance Method Details

- (Object) [](*args)

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 'rtm-javatmapi/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

- (Object) close

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



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

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

- (Object) create(locator) Also known as: createTopicMap, create_topic_map

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 'rtm-javatmapi/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

- (Object) create_locator(reference) 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 'rtm-javatmapi/lib/rtm/javatmapi.rb', line 97

def create_locator(reference)
  @tms.create_locator(reference)
end

- (Object) create_system



82
83
84
# File 'rtm-javatmapi/lib/rtm/javatmapi.rb', line 82

def create_system
  @tms = @tmsf.newTopicMapSystem
end

- (Object) delete(locator) 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 'rtm-javatmapi/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

- (Boolean) existing?(locator)

States if the topic map given by the locator is existing in the engine.

Returns:

  • (Boolean)


142
143
144
145
146
# File 'rtm-javatmapi/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

- (Object) getFeature(feature_name)

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 'rtm-javatmapi/lib/rtm/javatmapi.rb', line 185

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

- (Object) getLocators

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 'rtm-javatmapi/lib/rtm/javatmapi.rb', line 177

def getLocators
  @tms.getLocators
end

- (Object) locators 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 'rtm-javatmapi/lib/rtm/javatmapi.rb', line 166

def locators()
  @tms.getLocators.map {|l| l.reference}
end

- (Object) property(property_name) Also known as: getProperty, get_property

Returns a property in the underlying implementation of TopicMapSystem.



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

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

- (Object) refresh



86
87
88
89
# File 'rtm-javatmapi/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

- (Object) set_features(features)



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'rtm-javatmapi/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

- (Object) set_properties(properties)



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 'rtm-javatmapi/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

- (Object) set_tmsf(tmsf)



62
63
64
# File 'rtm-javatmapi/lib/rtm/javatmapi.rb', line 62

def set_tmsf(tmsf)
  @tmsf = tmsf
end

- (Object) topic_map(iri) 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 'rtm-javatmapi/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