rxsd 0.2 → 0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/rxsd/loader.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # RXSD resource loader
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  require 'uri' # use uri to parse sources
data/lib/rxsd/parser.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  # xml / xsd parsers
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  module RXSD
7
7
 
8
- # provides class methods to parse xsd and xml data
8
+ # Provides class methods to parse xsd and xml data
9
9
  class Parser
10
10
  private
11
11
  def initialize
@@ -13,10 +13,10 @@ class Parser
13
13
 
14
14
  public
15
15
 
16
- # parse xsd specified by uri or in raw data form into RXSD::XSD::Schema instance
16
+ # Parse xsd specified by uri or in raw data form into RXSD::XSD::Schema instance
17
17
  # args should be a hash w/ optional keys:
18
- # * :uri location which to load resource from
19
- # * :raw raw data which to parse
18
+ # * :uri location which to load resource from
19
+ # * :raw raw data which to parse
20
20
  def self.parse_xsd(args)
21
21
  data = Loader.load(args[:uri]) unless args[:uri].nil?
22
22
  data = args[:raw] unless args[:raw].nil?
@@ -33,7 +33,7 @@ class Parser
33
33
  return schema
34
34
  end
35
35
 
36
- # parse xml specified by uri or in raw data form into RXSD::XSD::SchemaInstance instance
36
+ # Parse xml specified by uri or in raw data form into RXSD::XSD::SchemaInstance instance
37
37
  def self.parse_xml(args)
38
38
  data = Loader.load(args[:uri]) unless args[:uri].nil?
39
39
  data = args[:raw] unless args[:raw].nil?
@@ -46,12 +46,12 @@ class Parser
46
46
  return schema_instance
47
47
  end
48
48
 
49
- # return true is specified class is builtin, else false
49
+ # Return true is specified class is builtin, else false
50
50
  def self.is_builtin?(builtin_class)
51
51
  [Array, String, Boolean, Char, Time, XSDFloat, XSDInteger].include? builtin_class
52
52
  end
53
53
 
54
- # return ruby class corresponding to builting type
54
+ # Return ruby class corresponding to builtin type
55
55
  def self.parse_builtin_type(builtin_type_name)
56
56
  res = nil
57
57
 
data/lib/rxsd/resolver.rb CHANGED
@@ -2,12 +2,12 @@
2
2
  #
3
3
  # resolves hanging node relationships and provides overall node access
4
4
  #
5
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
5
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
6
6
  # See COPYING for the License of this software
7
7
 
8
8
  module RXSD
9
9
 
10
- # resolves
10
+ # Resolves xsd relationships, used internally
11
11
  class Resolver
12
12
 
13
13
  # return hash of xsd types -> array of type instances for all nodes
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # transaltes xsd <-> ruby classes & xml <-> instances
4
4
  #
5
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
5
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
6
6
  # See COPYING for the License of this software
7
7
 
8
8
  # include whatever output builders you want here,
@@ -55,7 +55,7 @@ class Schema
55
55
  results = []
56
56
  cbs.each { |cb|
57
57
  # probably a better way to do this at some point than invoking the copy constructors
58
- #
58
+
59
59
  # FIXME we create class builders in the translator on the fly, this may cause
60
60
  # problems for later operations that need to access class builder attributes which
61
61
  # have been created
@@ -83,29 +83,29 @@ class SchemaInstance
83
83
  # array of object builders represented by current instance
84
84
  attr_accessor :object_builders
85
85
 
86
- # return array of ObjectBuilders parsed out of a RXSD::XML::Node.
86
+ # Return array of ObjectBuilders parsed out of a RXSD::XML::Node.
87
87
  # Optionally specify parent ObjectBuilder to use
88
88
  def self.builders_from_xml(node, parent = nil)
89
89
  node_builder = ObjectBuilder.new(:tag_name => node.name, :attributes => node.attrs, :parent => parent)
90
90
  parent.children.push node_builder unless parent.nil? || parent.children.include?(node_builder)
91
91
  builders = [ node_builder ]
92
- node.children.each { |c|
93
- if c.text?
94
- node_builder.content = c.content if node.children.size == 1 # FIXME if text/children-elements be mixed under a node this wont work
95
- else
96
- builders += SchemaInstance.builders_from_xml(c, node_builder )
97
- end
98
- }
92
+ if node.text?
93
+ node_builder.content = node.content
94
+ else
95
+ node.children.each { |c|
96
+ builders += SchemaInstance.builders_from_xml(c, node_builder )
97
+ }
98
+ end
99
99
  return builders
100
100
  end
101
101
 
102
- # create new schema instance w/ specified args
102
+ # Create new schema instance w/ specified args
103
103
  def initialize(args = {})
104
104
  @object_builders = args[:builders] if args.has_key? :builders
105
105
  end
106
106
 
107
107
  # translates SchemaInstance's objects into instances of the specified output type.
108
- # :output_type may be one of
108
+ # * :output_type may be one of
109
109
  # * :ruby_objects
110
110
  # Must specify :schema argument containing RXSD::XSD::Schema to use in object creation
111
111
  def to(output_type, args = {})
data/lib/rxsd/xml.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # xml parsing subsystem
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  require 'rubygems'
@@ -11,31 +11,31 @@ require 'libxml_adapter'
11
11
  module RXSD
12
12
  module XML
13
13
 
14
- # RXSD XML node interface subclasses must conform to and helper methods
14
+ # RXSD XML node interface that subclasses must conform to and implement methods
15
15
  class Node
16
16
 
17
- # should return name of node, eg <foo> => "foo"
17
+ # Should return name of node, eg <foo> => "foo"
18
18
  virtual :name
19
19
 
20
- # return hash of attribute name / values
20
+ # Return hash of attribute name / values
21
21
  virtual :attrs
22
22
 
23
- # should return bool if node has a parent
23
+ # Should return bool if node has a parent
24
24
  virtual :parent?
25
25
 
26
- # should return this nodes's parent, if any
26
+ # Should return this nodes's parent, if any
27
27
  virtual :parent
28
28
 
29
- # should return children nodes
29
+ # Should return children nodes
30
30
  virtual :children
31
31
 
32
- # should return bool if node only contains text
32
+ # Should return bool if node only contains text
33
33
  virtual :text?
34
34
 
35
- # should return string contents of text node
35
+ # Should return string contents of text node
36
36
  virtual :content
37
37
 
38
- # should return list of namespaces corresponding to node
38
+ # Should return list of namespaces corresponding to node
39
39
  virtual :namespaces
40
40
 
41
41
  # should also define class method 'xml_root' that returns a node instance corresponding
@@ -43,7 +43,7 @@ class Node
43
43
 
44
44
  ############################################################################
45
45
 
46
- # node factory, returns root node corresponding to specified backend and xml data
46
+ # Node factory, returns root node corresponding to specified backend and xml data
47
47
  def self.factory(args = {})
48
48
  backend = args[:backend]
49
49
  xml = args[:xml]
@@ -53,40 +53,53 @@ class Node
53
53
  return nil
54
54
  end
55
55
 
56
- # returns root node
56
+ # Returns root node
57
57
  def root
58
58
  parent? ? parent.root : self
59
59
  end
60
60
 
61
- # provides accessor interface to related obj, in our case related xsd obj
61
+ # Provides accessor interface to related obj, in our case related xsd obj
62
62
  attr_accessor :related
63
63
 
64
- # instantiate all children of provided class type
64
+ # Instantiate all children of provided class type
65
65
  def children_objs(klass)
66
66
  elements = []
67
67
  children.find_all { |c| c.name == klass.tag_name }.each { |c|
68
- elements.push(klass.from_xml(c)) }
68
+ elements << klass.from_xml(c)
69
+ }
69
70
  return elements
70
71
  end
71
72
 
72
- # instantiate first child of provided class type
73
+ # Instantiate first child of provided class type
73
74
  def child_obj(klass)
74
75
  return children_objs(klass)[0]
75
76
  end
76
77
 
77
- # return 'value' attribute of all children w/ specified tag
78
+ # Return 'value' attribute of all children w/ specified tag
78
79
  def child_values(tag_name)
79
80
  values = []
80
81
  children.find_all { |c| c.name == tag_name }.each { |c| values.push(c.attrs['value']) }
81
82
  return values
82
83
  end
83
84
 
84
- # return 'value' attribute of first childw/ specified tag
85
+ # Return 'value' attribute of first childw/ specified tag
85
86
  def child_value(tag_name)
86
87
  return child_values(tag_name)[0]
87
88
  end
88
89
 
89
90
  end
90
91
 
92
+ # RXSD XML namespace interface that subclasses must conform to and implement methods
93
+ class Namespace
94
+ # Should return prefix of namespace
95
+ virtual :prefix
96
+
97
+ # Should return href of namespace
98
+ virtual :href
99
+
100
+ # Should return namespace in string format
101
+ virtual :to_s
102
+ end
103
+
91
104
  end # module XML
92
105
  end # module RXSD
@@ -1,6 +1,6 @@
1
1
  # The XSD Attribute definition
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  module RXSD
@@ -1,6 +1,6 @@
1
1
  # The XSD AttributeGroup definition
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  module RXSD
@@ -1,6 +1,6 @@
1
1
  # The XSD Choice definition
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  module RXSD
@@ -1,6 +1,6 @@
1
1
  # The XSD ComplexContent definition
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  module RXSD
@@ -1,6 +1,6 @@
1
1
  # The XSD ComplexType definition
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  module RXSD
@@ -33,7 +33,8 @@ class ComplexType
33
33
 
34
34
  # returns array of all children
35
35
  def children
36
- (@attributes + @attribute_groups).push(@simple_content).push(@complex_content).push(@choice).push(@group).push(@sequence)
36
+ (@attributes + @attribute_groups).push(@simple_content).
37
+ push(@complex_content).push(@choice).push(@group).push(@sequence)
37
38
  end
38
39
 
39
40
  # node passed in should be a xml node representing the complex type
@@ -1,6 +1,6 @@
1
1
  # The XSD Element definition
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  module RXSD
@@ -13,7 +13,7 @@ class Element
13
13
  # element attribute values
14
14
  attr_accessor :id, :name, :type,
15
15
  :nillable, :abstract, :ref,
16
- :substitionGroup, :form, :maxOccurs,
16
+ :substitutionGroup, :form, :maxOccurs,
17
17
  :minOccurs, :default, :fixed
18
18
 
19
19
  # simple type in element
@@ -64,7 +64,7 @@ class Element
64
64
  ref = ref.split(':')[1] if !(ref.nil? || ref.index(":").nil?)
65
65
  element.ref = ref
66
66
 
67
- element.substitionGroup = node.attrs["substitionGroup"]
67
+ element.substitutionGroup = node.attrs["substitutionGroup"]
68
68
  element.form = node.attrs.has_key?("form") ?
69
69
  node.attrs["form"] :
70
70
  node.root.attrs["elementFormDefault"]
@@ -108,8 +108,8 @@ class Element
108
108
  @ref = node_objs[Element].find { |no| no.name == @ref }
109
109
  end
110
110
 
111
- unless @substitionGroup.nil?
112
- @substitutionGroup = node_objs[Element].find { |no| no.name == @substitionGroup }
111
+ unless @substitutionGroup.nil?
112
+ @substitutionGroup = node_objs[Element].find { |no| no.name == @substitutionGroup }
113
113
  end
114
114
  end
115
115
 
@@ -1,6 +1,6 @@
1
1
  # The XSD Extension definition
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  module RXSD
@@ -1,6 +1,6 @@
1
1
  # The XSD Group definition
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  module RXSD
data/lib/rxsd/xsd/list.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # The XSD List definition
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  module RXSD
@@ -1,6 +1,6 @@
1
1
  # The XSD Restriction definition
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  module RXSD
@@ -1,6 +1,6 @@
1
1
  # The XSD Schema definition
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  module RXSD
@@ -40,7 +40,8 @@ class Schema
40
40
 
41
41
  # returns array of all schema children
42
42
  def children
43
- ([@elements] + [@simple_types] + [@complex_types] + [@attributes] + [@attribute] + [@attribute_groups] + [@groups]).flatten
43
+ ([@elements] + [@simple_types] + [@complex_types] + [@attributes] +
44
+ [@attribute_groups] + [@groups]).flatten
44
45
  end
45
46
 
46
47
  # node passed in should be a xml root node representing the schema
@@ -1,6 +1,6 @@
1
1
  # The XSD Sequence definition
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  module RXSD
@@ -1,6 +1,6 @@
1
1
  # The XSD SimpleContent definition
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  module RXSD
@@ -1,6 +1,6 @@
1
1
  # The XSD SimpleType definition
2
2
  #
3
- # Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
4
  # See COPYING for the License of this software
5
5
 
6
6
  module RXSD
@@ -0,0 +1,224 @@
1
+ # tests the builder module
2
+ #
3
+ # Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
4
+ # See COPYING for the License of this software
5
+
6
+ require File.dirname(__FILE__) + '/spec_helper'
7
+
8
+ describe "Builder" do
9
+
10
+ # test to_class_builder method on all XSD classes
11
+
12
+ it "should return schema class builders" do
13
+ schema = Schema.new
14
+ elem1 = MockXSDEntity.new
15
+ elem2 = MockXSDEntity.new
16
+
17
+ schema.elements = [elem1, elem2]
18
+ class_builders = schema.to_class_builders
19
+
20
+ class_builders.size.should == 2
21
+ class_builders[0].class.should == ClassBuilder
22
+ class_builders[0].instance_variable_get("@xsd_obj").should == elem1
23
+ class_builders[1].class.should == ClassBuilder
24
+ class_builders[1].instance_variable_get("@xsd_obj").should == elem2
25
+ end
26
+
27
+ it "should return element class builders" do
28
+ elem1 = MockXSDEntity.new
29
+ st1 = MockXSDEntity.new
30
+ ct1 = MockXSDEntity.new
31
+
32
+ element = Element.new
33
+ element.name = "foo_element"
34
+ element.ref = elem1
35
+ cb = element.to_class_builder
36
+ cb.class.should == ClassBuilder
37
+ cb.instance_variable_get("@xsd_obj").should == elem1
38
+ cb.klass_name.should == "FooElement"
39
+
40
+ # FIXME the next two 'type' test cases need to be fixed / expanded
41
+ element = Element.new
42
+ element.name = "bar_element"
43
+ element.type = st1
44
+ cb = element.to_class_builder
45
+ cb.class.should == ClassBuilder
46
+ #cb.instance_variable_get("@xsd_obj").should == st1 TODO since clone is invoked, @xsd_obj test field never gets copied, fix this
47
+ cb.klass_name.should == "BarElement"
48
+
49
+ element = Element.new
50
+ element.type = ct1
51
+ cb = element.to_class_builder
52
+ cb.class.should == ClassBuilder
53
+ #cb.instance_variable_get("@xsd_obj").should == ct1
54
+
55
+ element = Element.new
56
+ element.simple_type = st1
57
+ cb = element.to_class_builder
58
+ cb.class.should == ClassBuilder
59
+ cb.instance_variable_get("@xsd_obj").should == st1
60
+
61
+ element = Element.new
62
+ element.complex_type = ct1
63
+ cb = element.to_class_builder
64
+ cb.class.should == ClassBuilder
65
+ cb.instance_variable_get("@xsd_obj").should == ct1
66
+ end
67
+
68
+ # FIXME test other XSD classes' to_class_builder methods
69
+
70
+ ##########
71
+
72
+ it "should correctly return associated builders" do
73
+ gp = ClassBuilder.new
74
+ p = ClassBuilder.new :base_builder => gp
75
+ c = ClassBuilder.new :base_builder => p
76
+ as = ClassBuilder.new
77
+ c.associated_builder = as
78
+ at1 = ClassBuilder.new
79
+ at2 = ClassBuilder.new
80
+ c.attribute_builders.push at1
81
+ c.attribute_builders.push at2
82
+
83
+ ab = c.associated
84
+ ab.size.should == 5
85
+ end
86
+
87
+ it "should build class" do
88
+ cb1 = RubyClassBuilder.new :klass => String, :klass_name => "Widget"
89
+ cb1.build.should == String
90
+
91
+ cb2 = RubyClassBuilder.new :klass_name => "Foobar"
92
+ c2 = cb2.build
93
+ c2.should == Foobar
94
+ c2.superclass.should == Object
95
+
96
+ acb = RubyClassBuilder.new :klass => Array, :klass_name => "ArrSocket", :associated_builder => cb1
97
+ ac = acb.build
98
+ ac.should == Array
99
+
100
+ tcb = RubyClassBuilder.new :klass_name => "CamelCased"
101
+
102
+ cb3 = RubyClassBuilder.new :klass_name => "Foomoney", :base_builder => cb2
103
+ cb3.attribute_builders.push cb1
104
+ cb3.attribute_builders.push tcb
105
+ cb3.attribute_builders.push acb
106
+ c3 = cb3.build
107
+ c3.should == Foomoney
108
+ c3.superclass.should == Foobar
109
+ c3i = c3.new
110
+ c3i.method(:widget).should_not be_nil
111
+ c3i.method(:widget).arity.should == 0
112
+ c3i.method(:widget=).should_not be_nil
113
+ c3i.method(:widget=).arity.should == 1
114
+ c3i.method(:camel_cased).should_not be_nil
115
+ c3i.method(:camel_cased).arity.should == 0
116
+ c3i.method(:camel_cased=).should_not be_nil
117
+ c3i.method(:camel_cased=).arity.should == 1
118
+ c3i.method(:arr_socket).should_not be_nil
119
+ c3i.method(:arr_socket).arity.should == 0
120
+ c3i.method(:arr_socket=).should_not be_nil
121
+ c3i.method(:arr_socket=).arity.should == 1
122
+ end
123
+
124
+ it "should build definition" do
125
+ cb1 = RubyDefinitionBuilder.new :klass => String, :klass_name => "Widget"
126
+ cb1.build.should == "class String\nend"
127
+
128
+ cb2 = RubyDefinitionBuilder.new :klass_name => "Foobar"
129
+ d2 = cb2.build
130
+ d2.should == "class Foobar < Object\nend"
131
+
132
+ acb = RubyDefinitionBuilder.new :klass => Array, :klass_name => "ArrSocket", :associated_builder => cb1
133
+ ad = acb.build
134
+ ad.should == "class Array\nend"
135
+
136
+ tcb = RubyDefinitionBuilder.new :klass_name => "CamelCased"
137
+
138
+ cb3 = RubyDefinitionBuilder.new :klass_name => "Foomoney", :base_builder => cb2
139
+ cb3.attribute_builders.push cb1
140
+ cb3.attribute_builders.push tcb
141
+ cb3.attribute_builders.push acb
142
+ d3 = cb3.build
143
+ d3.should == "class Foomoney < Foobar\n" +
144
+ "attr_accessor :widget\n" +
145
+ "attr_accessor :camel_cased\n" +
146
+ "attr_accessor :arr_socket\n" +
147
+ "end"
148
+ end
149
+
150
+ it "should build object" do
151
+ schema_data = "<schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>" +
152
+ "<xs:element name='Godzilla'>" +
153
+ "<xs:complexType>" +
154
+ "<xs:simpleContent>" +
155
+ "<xs:extension base='xs:string'>" +
156
+ "<xs:attribute name='first_attr' type='xs:string' />" +
157
+ "<xs:attribute name='SecondAttr' type='xs:integer' />" +
158
+ "</xs:extension>" +
159
+ "</xs:simpleContent>"+
160
+ "</xs:complexType>"+
161
+ "</xs:element>" +
162
+ "</schema>"
163
+
164
+ schema = Parser.parse_xsd :raw => schema_data
165
+ rbclasses = schema.to :ruby_classes
166
+
167
+ rob = RubyObjectBuilder.new :tag_name => "Godzilla", :content => "some stuff", :attributes => { "first_attr" => "first_val", "SecondAttr" => "420" }
168
+ obj = rob.build schema
169
+
170
+ obj.class.should == Godzilla
171
+ obj.should == "some stuff" # since obj derives from string
172
+ obj.first_attr.should == "first_val"
173
+ obj.second_attr.should == 420
174
+
175
+
176
+ schema_data = "<schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>" +
177
+ '<xs:element name="employee" type="fullpersoninfo"/>' +
178
+ '<xs:complexType name="personinfo">'+
179
+ '<xs:attribute name="ssn" type="xs:string" />' +
180
+ '<xs:sequence>'+
181
+ '<xs:element name="firstname" type="xs:string"/>'+
182
+ '<xs:element name="lastname" type="xs:string"/>'+
183
+ '</xs:sequence>'+
184
+ '</xs:complexType>'+
185
+ '<xs:complexType name="fullpersoninfo">'+
186
+ '<xs:complexContent>'+
187
+ '<xs:extension base="personinfo">'+
188
+ '<xs:attribute name="residency" type="xs:string" />' +
189
+ '<xs:sequence>'+
190
+ '<xs:element name="address" type="xs:string"/>'+
191
+ '<xs:element name="country" type="xs:string"/>'+
192
+ '</xs:sequence>'+
193
+ '</xs:extension>'+
194
+ '</xs:complexContent>'+
195
+ '</xs:complexType> '+
196
+ "</schema>"
197
+
198
+ schema = Parser.parse_xsd :raw => schema_data
199
+ rbclasses = schema.to :ruby_classes
200
+
201
+ rob = RubyObjectBuilder.new :tag_name => "employee", :attributes => { "ssn" => "111-22-3333", "residency" => "citizen" },
202
+ :children => [ ObjectBuilder.new(:tag_name => "firstname", :content => "mo" ),
203
+ ObjectBuilder.new(:tag_name => "lastname", :content => "morsi"),
204
+ ObjectBuilder.new(:tag_name => "address", :content => "wouldn't you like to know :-p"),
205
+ ObjectBuilder.new(:tag_name => "country", :content => "USA") ]
206
+
207
+ obj = rob.build schema
208
+
209
+ obj.class.should == Employee
210
+ obj.ssn.should == "111-22-3333"
211
+ obj.residency.should == "citizen"
212
+ obj.firstname.should == "mo"
213
+ obj.lastname.should == "morsi"
214
+ obj.country.should == "USA"
215
+ end
216
+ end
217
+
218
+ class MockXSDEntity
219
+ def to_class_builder
220
+ cb = ClassBuilder.new
221
+ cb.instance_variable_set("@xsd_obj", self)
222
+ return cb
223
+ end
224
+ end