Class: RXSD::XSD::Extension

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

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attribute_groupsObject

extension group children



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

def attribute_groups
  @attribute_groups
end

#attributesObject

extension group children



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

def attributes
  @attributes
end

#baseObject

extension attributes



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

def base
  @base
end

#choiceObject

extension group children



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

def choice
  @choice
end

#groupObject

extension group children



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

def group
  @group
end

#idObject

extension attributes



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

def id
  @id
end

#parentObject

extension parent



20
21
22
# File 'lib/rxsd/xsd/extension.rb', line 20

def parent
  @parent
end

#sequenceObject

extension group children



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

def sequence
  @sequence
end

Class Method Details

.from_xml(node) ⇒ Object

node passed in should be a xml node representing the extension



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rxsd/xsd/extension.rb', line 44

def self.from_xml(node)
   extension = Extension.new
   extension.parent = node.parent.related
   node.related = extension

   # TODO extension attributes: | anyAttributes
   extension.id       = node.attrs["id"]
   extension.base     = node.attrs["base"]

   # TODO extension children: | anyAttribute
   extension.group       = node.child_obj Group
   extension.choice      = node.child_obj Choice
   extension.sequence    = node.child_obj Sequence
   extension.attributes  = node.children_objs Attribute
   extension.attribute_groups  = node.children_objs AttributeGroup

   return extension
end

.tag_nameObject

xml tag name



23
24
25
# File 'lib/rxsd/xsd/extension.rb', line 23

def self.tag_name
  "extension"
end

Instance Method Details

#child_attributesObject

return all child attributes assocaited w/ extension



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

def child_attributes
   atts = []
   atts += @base.child_attributes unless @base.nil? || ![SimpleType, ComplexType].include?(@base.class)
   atts += @choice.child_attributes unless @choice.nil?
   atts += @sequence.child_attributes unless @sequence.nil?
   atts += @group.child_attributes unless @group.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



33
34
35
36
37
38
39
40
41
# File 'lib/rxsd/xsd/extension.rb', line 33

def children
  c = []
  c.push @group  unless @group.nil?
  c.push @choice unless @choice.nil?
  c.push @sequence unless @sequence.nil?
  c += @attributes unless @attributes.nil?
  c += @attribute_groups unless @attribute_groups.nil?
  return c
end

#infoObject

return xsd node info



28
29
30
# File 'lib/rxsd/xsd/extension.rb', line 28

def info
  "extension id: #{@id} base: #{@base.nil? ? "" : (@base.class == String || Parser.is_builtin?(@base)) ? @base : @base.name }"
end

#resolve(node_objs) ⇒ Object

resolve hanging references given complete xsd node object array



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rxsd/xsd/extension.rb', line 64

def resolve(node_objs)
  unless @base.nil?
    builtin  = Parser.parse_builtin_type @base
    simple   = node_objs[SimpleType].find  { |no| no.name == @base }
    complex  = node_objs[ComplexType].find { |no| no.name == @base }
    if !builtin.nil?
      @base = builtin
    elsif !simple.nil?
      @base = simple
    elsif !complex.nil?
      @base = complex
    end
  end
end

#to_class_builder(cb = nil) ⇒ Object

convert extension to class builder



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
120
121
# File 'lib/rxsd/xsd/extension.rb', line 80

def to_class_builder(cb = nil)
   unless defined? @class_builder
     @class_builder = cb.nil? ? ClassBuilder.new : cb

     # convert extension to builder 
     if Parser.is_builtin? @base
       @class_builder.base = @base
     elsif !@base.nil?
       @class_builder.base_builder = @base.to_class_builder
     end

     unless @group.nil?
       @group.to_class_builders.each { |gcb|
         @class_builder.attribute_builders.push gcb
       }
     end

     unless @choice.nil?
       @choice.to_class_builders.each { |ccb|
         @class_builder.attribute_builders.push ccb
       }
     end

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

     @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
        }
     }
   end

   return @class_builder
end