Class: RXSD::XSD::Schema
- Inherits:
-
Object
- Object
- RXSD::XSD::Schema
- Defined in:
- lib/rxsd/xsd/schema.rb,
lib/rxsd/translator.rb
Overview
Schema defintion, top level XSD element www.w3schools.com/Schema/el_schema.asp
Instance Attribute Summary collapse
-
#attribute_groups ⇒ Object
arrays of children in schema.
-
#attributeFormDefault ⇒ Object
schema attribute values.
-
#attributes ⇒ Object
arrays of children in schema.
-
#complex_types ⇒ Object
arrays of children in schema.
-
#elementFormDefault ⇒ Object
schema attribute values.
-
#elements ⇒ Object
arrays of children in schema.
-
#groups ⇒ Object
arrays of children in schema.
-
#namespaces ⇒ Object
hash of prefix => namespace values “ is the key of the default namespace (or use default_namespace).
-
#parent ⇒ Object
parent, always nil but here for conformity.
-
#simple_types ⇒ Object
arrays of children in schema.
-
#targetNamespace ⇒ Object
schema attribute values.
-
#version ⇒ Object
schema attribute values.
Class Method Summary collapse
-
.from_xml(node) ⇒ Object
node passed in should be a xml root node representing the schema.
-
.tag_name ⇒ Object
xml tag name.
Instance Method Summary collapse
-
#all_class_builders ⇒ Object
helper method, return all class builders in/under schema.
-
#children ⇒ Object
returns array of all schema children.
-
#default_namespace ⇒ Object
return default namespace.
-
#info ⇒ Object
return xsd node info.
-
#resolve(node_objs) ⇒ Object
resolve hanging references given complete xsd node object array.
-
#tags ⇒ Object
helper method, return hash of all tag names -> class builders under schema.
-
#to(output_type) ⇒ Object
translates schema and all child entities to instances of specified output type.
-
#to_class_builders ⇒ Object
convert schema to array of class builders.
Instance Attribute Details
#attribute_groups ⇒ Object
arrays of children in schema
21 22 23 |
# File 'lib/rxsd/xsd/schema.rb', line 21 def attribute_groups @attribute_groups end |
#attributeFormDefault ⇒ Object
schema attribute values
18 19 20 |
# File 'lib/rxsd/xsd/schema.rb', line 18 def attributeFormDefault @attributeFormDefault end |
#attributes ⇒ Object
arrays of children in schema
21 22 23 |
# File 'lib/rxsd/xsd/schema.rb', line 21 def attributes @attributes end |
#complex_types ⇒ Object
arrays of children in schema
21 22 23 |
# File 'lib/rxsd/xsd/schema.rb', line 21 def complex_types @complex_types end |
#elementFormDefault ⇒ Object
schema attribute values
18 19 20 |
# File 'lib/rxsd/xsd/schema.rb', line 18 def elementFormDefault @elementFormDefault end |
#elements ⇒ Object
arrays of children in schema
21 22 23 |
# File 'lib/rxsd/xsd/schema.rb', line 21 def elements @elements end |
#groups ⇒ Object
arrays of children in schema
21 22 23 |
# File 'lib/rxsd/xsd/schema.rb', line 21 def groups @groups end |
#namespaces ⇒ Object
hash of prefix => namespace values
" is the key of the default namespace (or use default_namespace)
15 16 17 |
# File 'lib/rxsd/xsd/schema.rb', line 15 def namespaces @namespaces end |
#parent ⇒ Object
parent, always nil but here for conformity
24 25 26 |
# File 'lib/rxsd/xsd/schema.rb', line 24 def parent @parent end |
#simple_types ⇒ Object
arrays of children in schema
21 22 23 |
# File 'lib/rxsd/xsd/schema.rb', line 21 def simple_types @simple_types end |
#targetNamespace ⇒ Object
schema attribute values
18 19 20 |
# File 'lib/rxsd/xsd/schema.rb', line 18 def targetNamespace @targetNamespace end |
#version ⇒ Object
schema attribute values
18 19 20 |
# File 'lib/rxsd/xsd/schema.rb', line 18 def version @version end |
Class Method Details
.from_xml(node) ⇒ Object
node passed in should be a xml root node representing the schema
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rxsd/xsd/schema.rb', line 48 def self.from_xml(node) schema = Schema.new schema.parent = nil node.= schema # set namespaces schema.namespaces = {} node.namespaces.each{ |ns| schema.namespaces[ns.prefix] = ns.href } # parse version out of attrs schema.version = node.attrs["version"] # parse target namespace out of attrs schema.targetNamespace = node.attrs["targetNamespace"] # parse elementFormDefault out of attrs schema.elementFormDefault = node.attrs["elementFormDefault"] # parse attributeFormDefault out of attrs schema.attributeFormDefault = node.attrs["attributeFormDefault"] # TODO schema attrs: | blockDefault / finalDefault / anyAttr # TODO schema children: | import, notation, redefine / anyChild # FIXME handle "xs:include" (use Loader?) # parse elements schema.elements = node.children_objs Element # parse simple types schema.simple_types = node.children_objs SimpleType # parse complex types schema.complex_types = node.children_objs ComplexType # parse attributes schema.attributes = node.children_objs Attribute # parse attribute groups schema.attribute_groups = node.children_objs AttributeGroup # parse groups schema.groups = node.children_objs Group return schema end |
.tag_name ⇒ Object
xml tag name
32 33 34 |
# File 'lib/rxsd/xsd/schema.rb', line 32 def self.tag_name "schema" end |
Instance Method Details
#all_class_builders ⇒ Object
helper method, return all class builders in/under schema
43 44 45 46 47 |
# File 'lib/rxsd/translator.rb', line 43 def all_class_builders to_class_builders.collect { |cb| cb.associated.push cb }.flatten.uniq.compact # FIXME this only filters duplicates by obj id, # its possible we have multiple objects refering # to the same type, should filter these out here or sometime b4 end |
#children ⇒ Object
returns array of all schema children
42 43 44 45 |
# File 'lib/rxsd/xsd/schema.rb', line 42 def children ([@elements] + [@simple_types] + [@complex_types] + [@attributes] + [@attribute_groups] + [@groups]).flatten end |
#default_namespace ⇒ Object
return default namespace
27 28 29 |
# File 'lib/rxsd/xsd/schema.rb', line 27 def default_namespace @namespaces[""] end |
#info ⇒ Object
return xsd node info
37 38 39 |
# File 'lib/rxsd/xsd/schema.rb', line 37 def info "schema" end |
#resolve(node_objs) ⇒ Object
resolve hanging references given complete xsd node object array
95 96 97 98 |
# File 'lib/rxsd/xsd/schema.rb', line 95 def resolve(node_objs) # right now does nothing # (possible resolve include/import here) end |
#tags ⇒ Object
helper method, return hash of all tag names -> class builders under schema. An tag is an element or attribute name that can appear in a xml document conforming to the schema
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rxsd/translator.rb', line 23 def unless defined? @tags @tags = {} Resolver. node_objects(self)[Element]. find_all { |no| no.class == Element }. each { |elem| unless elem.name.nil? @tags[elem.name] = elem.to_class_builder eca = elem.child_attributes eca.each { |att| @tags[elem.name + ":" + att.name] = att.to_class_builder # prepend element to attribute name to prevent conflicts } unless eca.nil? end } end return @tags end |
#to(output_type) ⇒ Object
translates schema and all child entities to instances of specified output type. output_type may be one of
* :ruby_classes
* :ruby_definitions
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rxsd/translator.rb', line 53 def to(output_type) cbs = all_class_builders results = [] cbs.each { |cb| # probably a better way to do this at some point than invoking the copy constructors # FIXME we create class builders in the translator on the fly, this may cause # problems for later operations that need to access class builder attributes which # have been created case(output_type) when :ruby_classes cl = RubyClassBuilder.new(:builder => cb).build results.push cl unless results.include? cl cb.klass = cl # small hack to get around the above fixme... for now when :ruby_definitions df = RubyDefinitionBuilder.new(:builder => cb).build results.push df unless results.include? df end } return results end |
#to_class_builders ⇒ Object
convert schema to array of class builders
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/rxsd/xsd/schema.rb', line 101 def to_class_builders unless defined? @class_builder @class_builders = [] @elements.each { |e| @class_builders.push e.to_class_builder } end return @class_builders end |