Class: SimpleXMIECoreInstantiator

Inherits:
RGen::Instantiator::DefaultXMLInstantiator show all
Defined in:
lib/puppet/vendor/rgen/test/xml_instantiator_test/simple_xmi_ecore_instantiator.rb

Overview

SimpleXMIECoreInstantiator demonstrates the usage of the DefaultXMLInstantiator. It can be used to instantiate an ECore model from an XMI description produced by Enterprise Architect.

Note however, that this is not the recommended way to read an EA model. See EAInstantiatorTest for the clean way to do this.

This example shows how arbitrary XML content can be used to instantiate an implicit metamodel. The resulting model is transformed into a simple ECore model.

See XMLInstantiatorTest for an example of how to use this class.

Instance Method Summary collapse

Methods inherited from RGen::Instantiator::DefaultXMLInstantiator

#assoc_p2c, #build_attribute, #build_class, #build_p2c_assoc, #class_name, map_tag_ns, #method_name, #on_ascent, #on_descent, #set_attribute, tag_ns_map

Methods included from RGen::Util::NameHelper

#camelize, #className, #firstToLower, #firstToUpper, #normalize, #saneClassName, #saneMethodName

Methods inherited from RGen::Instantiator::NodebasedXMLInstantiator

#end_element, #instantiate, #instantiate_file, #namespaces, #on_ascent, #on_chardata, #on_descent, #parse, prune_level, set_prune_level, #start_element

Methods inherited from RGen::Instantiator::AbstractInstantiator

resolve, resolve_by_id

Constructor Details

#initializeSimpleXMIECoreInstantiator

Returns a new instance of SimpleXMIECoreInstantiator.



27
28
29
30
# File 'lib/puppet/vendor/rgen/test/xml_instantiator_test/simple_xmi_ecore_instantiator.rb', line 27

def initialize
  @envXMI = RGen::Environment.new 
  super(@envXMI, SimpleXMIMetaModel, true)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RGen::Instantiator::AbstractInstantiator

Instance Method Details

#instantiateECoreModel(envOut, str) ⇒ Object

This method does the actual work.



45
46
47
48
49
50
51
# File 'lib/puppet/vendor/rgen/test/xml_instantiator_test/simple_xmi_ecore_instantiator.rb', line 45

def instantiateECoreModel(envOut, str)
  instantiate(str)
  
  require 'xml_instantiator_test/simple_xmi_to_ecore'
  
  SimpleXmiToECore.new(@envXMI,envOut).transform
end

#new_object(node) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/puppet/vendor/rgen/test/xml_instantiator_test/simple_xmi_ecore_instantiator.rb', line 32

def new_object(node)
  if node.tag == "EAStub"
    class_name = saneClassName(node.attributes["UMLType"])
    mod = XMIMetaModel::UML
    build_on_error(NameError, :build_class, class_name, mod) do
      mod.const_get(class_name).new
    end	 
  else
    super
  end
end