Class: RGen::XSD::XSIInstantiator
- Inherits:
-
Object
- Object
- RGen::XSD::XSIInstantiator
- Defined in:
- lib/rgen/xsd/xsi_instantiator.rb
Instance Attribute Summary collapse
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
-
#unresolved_refs ⇒ Object
readonly
Returns the value of attribute unresolved_refs.
Instance Method Summary collapse
-
#initialize(mm, env) ⇒ XSIInstantiator
constructor
A new instance of XSIInstantiator.
-
#instantiate(file, options = {}) ⇒ Object
options: :unresolved_refs: an array to which unresolved references will be appended :problems: an array to which problems during instantiation will be appended :fragment_ref: a fragment ref object which will be set on every model element created.
- #resolve_namespace(str) ⇒ Object
Constructor Details
#initialize(mm, env) ⇒ XSIInstantiator
Returns a new instance of XSIInstantiator.
13 14 15 16 17 18 |
# File 'lib/rgen/xsd/xsi_instantiator.rb', line 13 def initialize(mm, env) @mm = mm @env = env @classes_by_xml_name = nil @namespaces = [] end |
Instance Attribute Details
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces.
11 12 13 |
# File 'lib/rgen/xsd/xsi_instantiator.rb', line 11 def namespaces @namespaces end |
#unresolved_refs ⇒ Object (readonly)
Returns the value of attribute unresolved_refs.
10 11 12 |
# File 'lib/rgen/xsd/xsi_instantiator.rb', line 10 def unresolved_refs @unresolved_refs end |
Instance Method Details
#instantiate(file, options = {}) ⇒ Object
options:
:unresolved_refs: an array to which unresolved references will be appended
:problems: an array to which problems during instantiation will be appended
:fragment_ref: a fragment ref object which will be set on every model element created
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rgen/xsd/xsi_instantiator.rb', line 24 def instantiate(file, ={}) @unresolved_refs = [:unresolved_refs] || [] @fragment_ref = [:fragment_ref] @problems = [:problems] @target_identifier_provider = [:target_identifier_provider] || lambda do |node| node["id"] end root = nil root_class = [:root_class].andand.ecore || root_class(doc.root.name) File.open(file) do |f| doc = Nokogiri::XML(f) @namespaces = doc.root.namespace_definitions root =instantiate_node(doc.root, root_class) end root end |
#resolve_namespace(str) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rgen/xsd/xsi_instantiator.rb', line 40 def resolve_namespace(str) if str =~ /:/ prefix, name = str.split(":") else prefix, name = nil, str end # the default namespace has a prefix of nil href = namespaces.find{|ns| ns.prefix == prefix}.andand.href # built in xml schema namespace if !href if prefix == "xml" href = "http://www.w3.org/XML/1998/namespace" elsif prefix report_problem "WARN: Can not resolve namespace prefix #{prefix}" end end [href, name] end |