Class: RXSD::XSD::ComplexType

Inherits:
Object
  • Object
show all
Defined in:
lib/rxsd/xsd/complex_type.rb

Overview

XSD ComplexType defintion www.w3schools.com/Schema/el_simpletype.asp

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#abstractObject

complex type attribute values



14
15
16
# File 'lib/rxsd/xsd/complex_type.rb', line 14

def abstract
  @abstract
end

#attribute_groupsObject

complex type children



17
18
19
# File 'lib/rxsd/xsd/complex_type.rb', line 17

def attribute_groups
  @attribute_groups
end

#attributesObject

complex type children



17
18
19
# File 'lib/rxsd/xsd/complex_type.rb', line 17

def attributes
  @attributes
end

#choiceObject

complex type children



17
18
19
# File 'lib/rxsd/xsd/complex_type.rb', line 17

def choice
  @choice
end

#complex_contentObject

complex type children



17
18
19
# File 'lib/rxsd/xsd/complex_type.rb', line 17

def complex_content
  @complex_content
end

#groupObject

complex type children



17
18
19
# File 'lib/rxsd/xsd/complex_type.rb', line 17

def group
  @group
end

#idObject

complex type attribute values



14
15
16
# File 'lib/rxsd/xsd/complex_type.rb', line 14

def id
  @id
end

#mixedObject

complex type attribute values



14
15
16
# File 'lib/rxsd/xsd/complex_type.rb', line 14

def mixed
  @mixed
end

#nameObject

complex type attribute values



14
15
16
# File 'lib/rxsd/xsd/complex_type.rb', line 14

def name
  @name
end

#parentObject

complexType parent



22
23
24
# File 'lib/rxsd/xsd/complex_type.rb', line 22

def parent
  @parent
end

#sequenceObject

complex type children



17
18
19
# File 'lib/rxsd/xsd/complex_type.rb', line 17

def sequence
  @sequence
end

#simple_contentObject

complex type children



17
18
19
# File 'lib/rxsd/xsd/complex_type.rb', line 17

def simple_content
  @simple_content
end

Class Method Details

.from_xml(node) ⇒ Object

node passed in should be a xml node representing the complex type



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rxsd/xsd/complex_type.rb', line 41

def self.from_xml(node)
   complexType = ComplexType.new
   complexType.parent = node.parent.related
   node.related = complexType
    
   # TODO complexType attributes: | block, final, anyAttributes

   complexType.id       = node.attrs['id']
   complexType.name     = node.attrs['name']
   complexType.abstract = node.attrs.has_key?('abstract') ? node.attrs['abstract'].to_b : false

   if node.children.find { |c| c.name == SimpleContent.tag_name }.nil?
     complexType.mixed    = node.attrs.has_key?('mixed')    ? node.attrs['mixed'].to_b  : false
   else
     complexType.mixed = false
   end

   # TODO complexType children: | all, anyAttribute, 
   complexType.attributes       = node.children_objs Attribute
   complexType.attribute_groups = node.children_objs AttributeGroup
   complexType.simple_content   = node.child_obj SimpleContent
   complexType.complex_content  = node.child_obj ComplexContent
   complexType.group            = node.child_obj Group
   complexType.choice           = node.child_obj Choice
   complexType.sequence         = node.child_obj Sequence

   return complexType
end

.tag_nameObject

xml tag name



25
26
27
# File 'lib/rxsd/xsd/complex_type.rb', line 25

def self.tag_name
  "complexType"
end

Instance Method Details

#child_attributesObject

return all child attributes assocaited w/ complex type



122
123
124
125
126
127
128
129
130
131
132
# File 'lib/rxsd/xsd/complex_type.rb', line 122

def child_attributes
   atts = []
   atts += @choice.child_attributes unless @choice.nil?
   atts += @sequence.child_attributes unless @sequence.nil?
   atts += @group.child_attributes unless @group.nil?
   atts += @simple_content.child_attributes unless @simple_content.nil?
   atts += @complex_content.child_attributes unless @complex_content.nil?
   @attribute_groups.each { |atg| atts += atg.child_attributes } unless @attribute_groups.nil?
   @attributes.each       { |att| atts += att.child_attributes } unless @attributes.nil?
   return atts
end

#childrenObject

returns array of all children



35
36
37
38
# File 'lib/rxsd/xsd/complex_type.rb', line 35

def children
  (@attributes + @attribute_groups).push(@simple_content).
  push(@complex_content).push(@choice).push(@group).push(@sequence)
end

#infoObject

return xsd node info



30
31
32
# File 'lib/rxsd/xsd/complex_type.rb', line 30

def info
  "complexType id: #{@id} name: #{@name}"
end

#resolve(node_objs) ⇒ Object

resolve hanging references given complete xsd node object array



71
72
# File 'lib/rxsd/xsd/complex_type.rb', line 71

def resolve(node_objs)
end

#to_class_builderObject

convert complex type to class builder



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
119
# File 'lib/rxsd/xsd/complex_type.rb', line 75

def to_class_builder
  unless defined? @class_builder
    # dispatch to simple / complex content to get class builder
    @class_builder = ClassBuilder.new

    if !@simple_content.nil?
       @simple_content.to_class_builder(@class_builder)
    elsif !@complex_content.nil?
       @complex_content.to_class_builder(@class_builder)
    #else
       #@class_builder = ClassBuilder.new
    end

    @class_builder.klass_name = @name.camelize unless @name.nil?

    @attributes.each { |att|
       @class_builder.attribute_builders.push att.to_class_builder
    }
    @attribute_groups.each { |atg|
       atg.to_class_builders.each { |atcb|
          @class_builder.attribute_builders.push atcb
       }
    }

    if !@group.nil?
        @group.to_class_builders.each { |gcb|
          @class_builder.attribute_builders.push gcb
        }
    end
 
    if !@choice.nil?
        @choice.to_class_builders.each { |ccb|
          @class_builder.attribute_builders.push ccb
        }
    end

    if !@sequence.nil?
        @sequence.to_class_builders.each { |scb|
          @class_builder.attribute_builders.push scb
        }
    end
  end

  return @class_builder
end