Module: Java::OrgTmapiCore::Name

Extended by:
Superiseable
Includes:
RTM::Name
Defined in:
lib/rtm/javatmapi/core/name.rb

Overview

Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. License: Apache License, Version 2.0

Defined Under Namespace

Classes: NoDatatypeHandlerAvailableException

Instance Method Summary collapse

Methods included from Superiseable

method_added, register_java_implementation, superised, superising

Instance Method Details

#childrenObject Also known as: reverse_parent

Returns all Variants defined for this Name.

:call-seq:

children -> Array of Variants


24
25
26
# File 'lib/rtm/javatmapi/core/name.rb', line 24

def children
 	getVariants.to_a
end

#create_variant(value, *args) ⇒ Object

Creates a Variant given the value and scope, if value is a Locator or given value, datatype and scope, if the value is a String.

Scope may be an Array of topic references and must not be empty.

Datatype may be a String or Locator.

:call-seq:

create_variant(value, scope) -> Variant
create_variant(value, datatype, scope) -> Variant


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/rtm/javatmapi/core/name.rb', line 62

def create_variant(value, *args)
  # reading scope and datatype, if given
  if args.length == 1
    if args.first.is_a?(Hash)
      # TODO
    else
      # scope given
      scope = args.first
      raise("create_variant(value, scope): scope must be an Array") unless scope.is_a?(Array)
    end
  elsif args.length == 2
    # datatype and scope given
    datatype = args.first
    scope = args.last
    raise("create_variant(value, datatype, scope): scope must be an Array") unless scope.is_a?(Array)
  else
    raise("create_variant: arguments don't match - no scope given.")
  end
  # reading the value and setting the datatype dynamicaly if not set before
  unless datatype
    if value.is_a?(Java::OrgTmapiCore::Locator)
      datatype ||= RTM::PSI[:IRI]
    elsif value.is_a?(String)
      datatype ||= RTM::PSI[:String]
    elsif value.is_a?(Float)
      datatype ||= RTM::PSI[:Float]
    elsif value.is_a?(Fixnum)
      datatype ||= RTM::PSI[:Long]
    elsif value.is_a?(Bignum)
      datatype ||= RTM::PSI[:Integer]
    elsif value.is_a?(DateTime) #DateTime is a Time and a Date
      datatype ||= RTM::PSI[:DateTime]
    elsif value.is_a?(Time)
      datatype ||= RTM::PSI[:Time]
    elsif value.is_a?(Date)
      datatype ||= RTM::PSI[:Date]
    else
      raise NoDatatypeHandlerAvailableException.new(value)
    end
  end
  # creating locator for datatype
  datatype = topic_map.create_locator(datatype)
  # value must be a String
  value = value.to_s
  # if datatype is xsd:anyURI -> resolve value against base_iri
  if datatype.reference == RTM::PSI[:IRI]
    value = topic_map.create_locator(value).reference
  end
  # creating an array of topics for the scope
  scope = topic_map.get!(scope).to_java(Java::OrgTmapiCore::Topic)

  begin
    createVariant(value, datatype, scope)
  rescue java.lang.IllegalArgumentException => iae
    raise(iae.message)
  end
end

#parentObject Also known as: reverse_children

Returns the Topic this Name belongs to.

:call-seq:

parent -> Topic


14
15
16
# File 'lib/rtm/javatmapi/core/name.rb', line 14

def parent
	getParent
end

#valueObject

Returns the value of this Name.

:call-seq:

value -> String


35
36
37
# File 'lib/rtm/javatmapi/core/name.rb', line 35

def value
	getValue
end

#value=(argument) ⇒ Object

Sets the value of this name. The previous value is overridden.

Argument is a String.

:call-seq:

value=(argument)


46
47
48
# File 'lib/rtm/javatmapi/core/name.rb', line 46

def value=(argument)
	setValue(argument)
end