Class: Saxon::SequenceType

Inherits:
Object
  • Object
show all
Defined in:
lib/saxon/sequence_type.rb

Overview

Represents a type definition for an XDM Sequence: an ItemType plus an OccurrenceIndicator as a restriction on the cardinality (length) of the sequence. Used most often to define variables in XPath or XSLT, plus in extension function definition.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item_type, occurrence_indicator) ⇒ Saxon::SequenceType #initialize(s9_sequence_type) ⇒ Saxon::SequenceType

Returns the new SequenceType.

Overloads:

  • #initialize(item_type, occurrence_indicator) ⇒ Saxon::SequenceType

    creates new instance using item type and occurrence indicator

    Parameters:

    • item_type (Saxon::ItemType)

      the sequence’s item type

    • occurrence_indicator (net.sf.saxon.s9api.OccurrenceIndicator)

      the occurrence indicator (cardinality) of the sequence

  • #initialize(s9_sequence_type) ⇒ Saxon::SequenceType

    create a new instance by wrapping one of Saxon’s underlying Java SequenceTypes

    Parameters:



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/saxon/sequence_type.rb', line 77

def initialize(item_type, occurrence_indicator = nil)
  if occurrence_indicator.nil? && !item_type.is_a?(S9API::SequenceType)
    raise ArgumentError, "Expected a Java s9api.SequenceType when handed a single argument, but got a #{item_type.class}"
  end

  if occurrence_indicator.nil?
    @s9_sequence_type = item_type
  else
    @item_type = item_type
    @occurrence_indicator = occurrence_indicator
  end
end

Class Method Details

.create(type_name, occurrence_indicator = nil) ⇒ Saxon::SequenceType

Generate a Saxon::SequenceType from a type declaration string (see from_type_decl), or some combination of type name/Ruby class (see ItemType.get_type), and an OccurrenceIndicator or symbol referencing an OccurenceIndicator (one of :zero_or_more, :one_or_more, :zero_or_one, or :one)

Returns:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/saxon/sequence_type.rb', line 18

def create(type_name, occurrence_indicator = nil)
  case type_name
  when SequenceType
    return type_name
  when S9API::SequenceType
    return new(type_name)
  else
    check_for_complete_decl!(type_name, occurrence_indicator)
    return from_type_decl(type_name) if type_name.is_a?(String) && occurrence_indicator.nil?
    item_type = ItemType.get_type(type_name)
    occurrence_indicator = OccurrenceIndicator.get_indicator(occurrence_indicator)
    new(item_type, occurrence_indicator)
  end
end

.from_type_decl(type_decl) ⇒ Saxon::SequenceType

Generate a Saxon::SequenceType from a declaration string following the rules of parameter and function as= declarations in XSLT, like <xsl:variable ... as="xs:string+"/>

Parameters:

  • type_decl (String)

    the declaration string

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/saxon/sequence_type.rb', line 39

def from_type_decl(type_decl)
  occurence_char = type_decl[-1]
  occurence = case occurence_char
  when '?'
    new(ItemType.get_type(type_decl[0..-2]), OccurrenceIndicator.zero_or_one)
  when '+'
    new(ItemType.get_type(type_decl[0..-2]), OccurrenceIndicator.one_or_more)
  when '*'
    new(ItemType.get_type(type_decl[0..-2]), OccurrenceIndicator.zero_or_more)
  else
    new(ItemType.get_type(type_decl), OccurrenceIndicator.one)
  end
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Compare equal with another SequenceType

Parameters:

Returns:

  • (Boolean)

    the result of comparing self and other



108
109
110
111
# File 'lib/saxon/sequence_type.rb', line 108

def ==(other)
  return false if other.class != self.class
  item_type == other.item_type && occurrence_indicator == other.occurrence_indicator
end

#hashObject

Generated hash code for use as keys in Hashes



115
116
117
# File 'lib/saxon/sequence_type.rb', line 115

def hash
  @hash ||= item_type.hash ^ occurrence_indicator.hash
end

#item_typeSaxon::ItemType

Returns the type’s ItemType.

Returns:



91
92
93
# File 'lib/saxon/sequence_type.rb', line 91

def item_type
  @item_type ||= Saxon::ItemType.get_type(s9_sequence_type.getItemType)
end

#occurrence_indicatornet.sf.saxon.s9api.OccurrenceIndicator

Returns the type’s OccurrenceIndicator.

Returns:



96
97
98
# File 'lib/saxon/sequence_type.rb', line 96

def occurrence_indicator
  @occurrence_indicator ||= s9_sequence_type.getOccurrenceIndicator
end

#to_javanet.sf.saxon.s9api.SequenceType

Returns the underlying Saxon SequenceType.

Returns:

  • (net.sf.saxon.s9api.SequenceType)

    the underlying Saxon SequenceType



101
102
103
# File 'lib/saxon/sequence_type.rb', line 101

def to_java
  s9_sequence_type
end