Class: WSDL::XML::Element Private

Inherits:
Object
  • Object
show all
Defined in:
lib/wsdl/xml/element.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents an XML element definition used for building SOAP messages.

Elements are the building blocks of SOAP message structures. They can be either simple types (with a base type like string or integer) or complex types (with child elements). Elements track their cardinality (singular vs. array), namespace qualification, and support detection of recursive type definitions.

Constant Summary collapse

EMPTY_ATTRIBUTES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Canonical frozen empty array shared for elements without attributes.

Returns:

[].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeElement

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new Element with default values.



29
30
31
32
33
34
35
36
37
38
# File 'lib/wsdl/xml/element.rb', line 29

def initialize
  @children    = []
  @attributes  = EMPTY_ATTRIBUTES
  @recursive   = false
  @singular    = true
  @min_occurs  = '1'
  @max_occurs  = '1'
  @any_content = false
  @nillable    = false
end

Instance Attribute Details

#any_contentBoolean Also known as: any_content?

Whether this element allows arbitrary content via xs:any wildcard. When true, the element can contain any well-formed XML elements beyond those explicitly defined in the schema.

Returns:

  • (Boolean)

    true if arbitrary content is allowed



151
152
153
# File 'lib/wsdl/xml/element.rb', line 151

def any_content
  @any_content
end

#attributesArray<Attribute>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The XML attributes defined on this element.

Returns:

  • (Array<Attribute>)

    the attribute definitions



157
158
159
# File 'lib/wsdl/xml/element.rb', line 157

def attributes
  @attributes
end

#base_typeString?

The base type name for simple type elements (e.g., 'xsd:string').

Returns:

  • (String, nil)

    the base type name, or nil for complex types



83
84
85
# File 'lib/wsdl/xml/element.rb', line 83

def base_type
  @base_type
end

#childrenArray<Element>

The child elements for complex type elements.

Returns:

  • (Array<Element>)

    the child elements



144
145
146
# File 'lib/wsdl/xml/element.rb', line 144

def children
  @children
end

#complex_type_idString?

The complex type ID for tracking recursive type definitions. Format is "namespace:localName".

Returns:

  • (String, nil)

    the complex type identifier



139
140
141
# File 'lib/wsdl/xml/element.rb', line 139

def complex_type_id
  @complex_type_id
end

#formString

The element form ('qualified' or 'unqualified'). Qualified elements include namespace prefixes in the XML output.

Returns:

  • (String)

    the element form



59
60
61
# File 'lib/wsdl/xml/element.rb', line 59

def form
  @form
end

#max_occursString

Maximum occurrences for this element in schema terms.

Returns:

  • (String)

    maxOccurs value (default: '1')



99
100
101
# File 'lib/wsdl/xml/element.rb', line 99

def max_occurs
  @max_occurs
end

#min_occursString

Minimum occurrences for this element in schema terms.

Returns:

  • (String)

    minOccurs value (default: '1')



94
95
96
# File 'lib/wsdl/xml/element.rb', line 94

def min_occurs
  @min_occurs
end

#nameString

The local name of this element.

Returns:

  • (String)

    the element name



48
49
50
# File 'lib/wsdl/xml/element.rb', line 48

def name
  @name
end

#namespaceString?

The namespace URI for this element.

Returns:

  • (String, nil)

    the namespace URI



53
54
55
# File 'lib/wsdl/xml/element.rb', line 53

def namespace
  @namespace
end

#nillableBoolean Also known as: nillable?

Whether this element can have a nil value (xsi:nil="true"). This corresponds to the nillable="true" attribute in the XSD schema.

Returns:

  • (Boolean)

    true if the element is nillable



115
116
117
# File 'lib/wsdl/xml/element.rb', line 115

def nillable
  @nillable
end

#parentElement?

The parent element in the element tree.

Returns:

  • (Element, nil)

    the parent element



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

def parent
  @parent
end

#recursive_typeString?

The name of the recursive type definition, if any.

Returns:

  • (String, nil)

    the recursive type name



132
133
134
# File 'lib/wsdl/xml/element.rb', line 132

def recursive_type
  @recursive_type
end

#singularBoolean Also known as: singular?

Whether this element appears at most once (singular) or can repeat (array).

Returns:

  • (Boolean)

    true for singular elements, false for repeating elements



88
89
90
# File 'lib/wsdl/xml/element.rb', line 88

def singular
  @singular
end

Instance Method Details

#complex_type?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether this element is a complex type.

Complex types contain child elements rather than simple text content.

Returns:

  • (Boolean)

    true if this is a complex type element



76
77
78
# File 'lib/wsdl/xml/element.rb', line 76

def complex_type?
  !simple_type?
end

#freezeself

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Deep-freezes this element by also freezing the mutable +@children+ array.

The +@attributes+ array is already frozen by the custom setter, so only +@children+ needs explicit freezing here.

Returns:

  • (self)


180
181
182
183
# File 'lib/wsdl/xml/element.rb', line 180

def freeze
  @children.freeze
  super
end

#optional?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if the element is optional (minOccurs=0).

Returns:

  • (Boolean)

    true if the element is optional (minOccurs=0)



102
103
104
# File 'lib/wsdl/xml/element.rb', line 102

def optional?
  min_occurs.to_s == '0'
end

#recursive?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether this element's type is defined recursively.

A recursive type definition means one of this element's ancestors has the same complex type as this element, which would cause infinite recursion if fully expanded.

Returns:

  • (Boolean)

    true if this element has a recursive type definition



125
126
127
# File 'lib/wsdl/xml/element.rb', line 125

def recursive?
  !!recursive_type
end

#required?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if the element is required (minOccurs>0).

Returns:

  • (Boolean)

    true if the element is required (minOccurs>0)



107
108
109
# File 'lib/wsdl/xml/element.rb', line 107

def required?
  !optional?
end

#simple_type?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether this element is a simple type.

Simple types have a base type and contain only text content, not child elements.

Returns:

  • (Boolean)

    true if this is a simple type element



67
68
69
# File 'lib/wsdl/xml/element.rb', line 67

def simple_type?
  !!base_type
end

#to_a(memo = [], stack = []) ⇒ Array<Array>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts this element and its children to an Array representation for inspection.

Each element is represented as a tuple of [path, data], where path is an array of element names from the root, and data is a hash containing the element's properties.

rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity -- straightforward tree traversal, splitting would hurt readability

Examples:

element.to_a
# => [
#      [["user"], { namespace: "http://example.com", form: "qualified", singular: true }],
#      [["user", "name"], { namespace: nil, form: "unqualified", singular: true, type: "xsd:string" }]
#    ]

Parameters:

  • memo (Array) (defaults to: [])

    accumulator for recursive traversal (internal use)

  • stack (Array<String>) (defaults to: [])

    current path of element names (internal use)

Returns:

  • (Array<Array>)

    array of [path, data] tuples



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/wsdl/xml/element.rb', line 203

def to_a(memo = [], stack = [])
  new_stack = stack + [name]
  data = {
    namespace: namespace,
    form: form,
    singular: singular?,
    min_occurs: min_occurs,
    max_occurs: max_occurs
  }

  unless attributes.empty?
    data[:attributes] = attributes.to_h { |attribute|
      [attribute.name, { optional: attribute.optional? }]
    }
  end

  if recursive?
    data[:recursive_type] = recursive_type
    memo << [new_stack, data]

  elsif simple_type?
    data[:type] = base_type
    memo << [new_stack, data]

  elsif complex_type?
    data[:any_content] = true if any_content?
    memo << [new_stack, data]

    children.each do |child|
      child.to_a(memo, new_stack)
    end

  end

  memo
end