Class: WSDL::XMLSchema::Element

Inherits:
Info
  • Object
show all
Defined in:
lib/wsdl/soap/element.rb,
lib/wsdl/xmlSchema/element.rb

Instance Attribute Summary collapse

Attributes inherited from Info

#id, #parent, #root

Instance Method Summary collapse

Methods inherited from Info

#inspect, #parse_epilogue

Constructor Details

#initialize(name = nil, type = nil) ⇒ Element

Returns a new instance of Element.



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/wsdl/xmlSchema/element.rb', line 60

def initialize(name = nil, type = nil)
  super()
  @name = name
  @form = nil
  @type = type
  @local_simpletype = @local_complextype = nil
  @constraint = nil
  @maxoccurs = '1'
  @minoccurs = '1'
  @nillable = nil
  @ref = nil
  @refelement = nil
end

Instance Attribute Details

#constraint=(value) ⇒ Object (writeonly)

Sets the attribute constraint

Parameters:

  • value

    the value to set the attribute constraint to.



43
44
45
# File 'lib/wsdl/xmlSchema/element.rb', line 43

def constraint=(value)
  @constraint = value
end

#form=(value) ⇒ Object (writeonly)

Sets the attribute form

Parameters:

  • value

    the value to set the attribute form to.



39
40
41
# File 'lib/wsdl/xmlSchema/element.rb', line 39

def form=(value)
  @form = value
end

#local_complextype=(value) ⇒ Object (writeonly)

Sets the attribute local_complextype

Parameters:

  • value

    the value to set the attribute local_complextype to.



42
43
44
# File 'lib/wsdl/xmlSchema/element.rb', line 42

def local_complextype=(value)
  @local_complextype = value
end

#local_simpletype=(value) ⇒ Object (writeonly)

Sets the attribute local_simpletype

Parameters:

  • value

    the value to set the attribute local_simpletype to.



41
42
43
# File 'lib/wsdl/xmlSchema/element.rb', line 41

def local_simpletype=(value)
  @local_simpletype = value
end

#maxoccurs=(value) ⇒ Object (writeonly)

Sets the attribute maxoccurs

Parameters:

  • value

    the value to set the attribute maxoccurs to.



44
45
46
# File 'lib/wsdl/xmlSchema/element.rb', line 44

def maxoccurs=(value)
  @maxoccurs = value
end

#minoccurs=(value) ⇒ Object (writeonly)

Sets the attribute minoccurs

Parameters:

  • value

    the value to set the attribute minoccurs to.



45
46
47
# File 'lib/wsdl/xmlSchema/element.rb', line 45

def minoccurs=(value)
  @minoccurs = value
end

#name=(value) ⇒ Object (writeonly)

required



38
39
40
# File 'lib/wsdl/xmlSchema/element.rb', line 38

def name=(value)
  @name = value
end

#nillable=(value) ⇒ Object (writeonly)

Sets the attribute nillable

Parameters:

  • value

    the value to set the attribute nillable to.



46
47
48
# File 'lib/wsdl/xmlSchema/element.rb', line 46

def nillable=(value)
  @nillable = value
end

#refObject

Returns the value of attribute ref



58
59
60
# File 'lib/wsdl/xmlSchema/element.rb', line 58

def ref
  @ref
end

#type=(value) ⇒ Object (writeonly)

Sets the attribute type

Parameters:

  • value

    the value to set the attribute type to.



40
41
42
# File 'lib/wsdl/xmlSchema/element.rb', line 40

def type=(value)
  @type = value
end

Instance Method Details

#attr_reader_ref(symbol) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/wsdl/xmlSchema/element.rb', line 19

def attr_reader_ref(symbol)
  name = symbol.to_s
  module_eval <<-EOS
    def #{name}
      @#{name} || (refelement ? refelement.#{name} : nil)
    end
  EOS
end

#attributesObject



21
22
23
# File 'lib/wsdl/soap/element.rb', line 21

def attributes
  @local_complextype.attributes
end

#elementformObject



86
87
88
# File 'lib/wsdl/xmlSchema/element.rb', line 86

def elementform
  self.form.nil? ? parent.elementformdefault : self.form
end

#elementformdefaultObject



82
83
84
# File 'lib/wsdl/xmlSchema/element.rb', line 82

def elementformdefault
  parent.elementformdefault
end

#map_as_array?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/wsdl/soap/element.rb', line 17

def map_as_array?
  maxoccurs != '1'
end

#parse_attr(attr, value) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/wsdl/xmlSchema/element.rb', line 107

def parse_attr(attr, value)
  case attr
  when NameAttrName
    # namespace may be nil
    if directelement? or elementform == 'qualified'
      @name = XSD::QName.new(targetnamespace, value.source)
    else
      @name = XSD::QName.new(nil, value.source)
    end
  when FormAttrName
    @form = value.source
  when TypeAttrName
    @type = value
  when RefAttrName
    @ref = value
  when MaxOccursAttrName
    if parent.is_a?(All)
	if value.source != '1'
 raise Parser::AttrConstraintError.new(
          "cannot parse #{value} for #{attr}")
	end
    end
    @maxoccurs = value.source
  when MinOccursAttrName
    if parent.is_a?(All)
	unless ['0', '1'].include?(value.source)
 raise Parser::AttrConstraintError.new(
          "cannot parse #{value} for #{attr}")
	end
    end
    @minoccurs = value.source
  when NillableAttrName
    @nillable = (value.source == 'true')
  else
    nil
  end
end

#parse_element(element) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/wsdl/xmlSchema/element.rb', line 90

def parse_element(element)
  case element
  when SimpleTypeName
    @local_simpletype = SimpleType.new
    @local_simpletype
  when ComplexTypeName
    @type = nil
    @local_complextype = ComplexType.new
    @local_complextype
  when UniqueName
    @constraint = Unique.new
    @constraint
  else
    nil
  end
end

#refelementObject



74
75
76
# File 'lib/wsdl/xmlSchema/element.rb', line 74

def refelement
  @refelement ||= (@ref ? root.collect_elements[@ref] : nil)
end

#targetnamespaceObject



78
79
80
# File 'lib/wsdl/xmlSchema/element.rb', line 78

def targetnamespace
  parent.targetnamespace
end