Module: RTM::TopicMap

Defined in:
lib/rtm/tmcl.rb

Instance Method Summary collapse

Instance Method Details

#validate(schema) ⇒ Hash

Validates this topic map against a schema.

Keys: :topic, :name, :occurrence, :association and :role. Values: Hashes: keys are tmapi.core-objects and values validation results.

Parameters:

  • schema (TopicMap)

    The topic map used as schema to validate against

Returns:

  • (Hash)

    The validation results as Hash:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rtm/tmcl.rb', line 22

def validate(schema)
  raise("schema must be a topic map") unless schema.is_a?(RTM::TopicMap)
  validator = Java::DeTopicmapslabTmclvalidator::TMCLValidator.new(schema, true) #true: use identifier for messages, false: use best_name for messages
  validation_results = validator.validate(self) #result is a HashMap
  result = {}
  %w[topic name occurrence association role other].each do |string|
    result[string.to_sym] = {}
  end
  # output it ...
  validation_results.each do |construct, validation_result|
    # key is a Construct
    # value is a Set of Validation Results
    case construct
    when Topic
      result[:topic][construct] = validation_result
    when Name
      result[:name][construct] = validation_result
    when Occurrence
      result[:occurrence][construct] = validation_result
    when Association
      result[:association][construct] = validation_result
    when Role
      result[:role][construct] = validation_result
    else
      result[:other][construct] = validation_result
    end       
  end
  return result
  # result is a Hash
end