rgen 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +20 -1
- data/MIT-LICENSE +1 -1
- data/README +12 -9
- data/lib/instantiators/ea_instantiator.rb +36 -0
- data/lib/metamodels/uml13_metamodel.rb +559 -0
- data/lib/metamodels/uml13_metamodel_ext.rb +26 -0
- data/lib/mmgen/metamodel_generator.rb +5 -5
- data/lib/mmgen/mm_ext/ecore_ext.rb +95 -0
- data/lib/mmgen/mmgen.rb +6 -4
- data/lib/mmgen/templates/annotations.tpl +37 -0
- data/lib/mmgen/templates/metamodel_generator.tpl +171 -0
- data/lib/rgen/ecore/ecore.rb +190 -0
- data/lib/rgen/ecore/ecore_instantiator.rb +25 -0
- data/lib/rgen/ecore/ecore_transformer.rb +85 -0
- data/lib/rgen/environment.rb +9 -24
- data/lib/rgen/find_helper.rb +68 -0
- data/lib/rgen/{instantiator.rb → instantiator/abstract_instantiator.rb} +6 -2
- data/lib/rgen/instantiator/abstract_xml_instantiator.rb +59 -0
- data/lib/rgen/instantiator/default_xml_instantiator.rb +117 -0
- data/lib/rgen/instantiator/ecore_xml_instantiator.rb +144 -0
- data/lib/rgen/instantiator/nodebased_xml_instantiator.rb +157 -0
- data/lib/rgen/instantiator/xmi11_instantiator.rb +164 -0
- data/lib/rgen/metamodel_builder.rb +103 -9
- data/lib/rgen/metamodel_builder/build_helper.rb +26 -4
- data/lib/rgen/metamodel_builder/builder_extensions.rb +285 -88
- data/lib/rgen/metamodel_builder/builder_runtime.rb +7 -1
- data/lib/rgen/metamodel_builder/data_types.rb +67 -0
- data/lib/rgen/metamodel_builder/intermediate/annotation.rb +30 -0
- data/lib/rgen/metamodel_builder/metamodel_description.rb +232 -0
- data/lib/rgen/metamodel_builder/mm_multiple.rb +23 -0
- data/lib/rgen/metamodel_builder/module_extension.rb +33 -0
- data/lib/rgen/model_comparator.rb +56 -0
- data/lib/rgen/model_dumper.rb +5 -5
- data/lib/rgen/name_helper.rb +17 -1
- data/lib/rgen/template_language.rb +148 -28
- data/lib/rgen/template_language/directory_template_container.rb +56 -38
- data/lib/rgen/template_language/output_handler.rb +93 -77
- data/lib/rgen/template_language/template_container.rb +186 -143
- data/lib/rgen/transformer.rb +19 -14
- data/lib/transformers/uml13_to_ecore.rb +75 -0
- data/redist/xmlscan/ChangeLog +1301 -0
- data/redist/xmlscan/README +34 -0
- data/redist/xmlscan/THANKS +11 -0
- data/redist/xmlscan/doc/changes.html +74 -0
- data/redist/xmlscan/doc/changes.rd +80 -0
- data/redist/xmlscan/doc/en/conformance.html +136 -0
- data/redist/xmlscan/doc/en/conformance.rd +152 -0
- data/redist/xmlscan/doc/en/manual.html +356 -0
- data/redist/xmlscan/doc/en/manual.rd +402 -0
- data/redist/xmlscan/doc/ja/conformance.ja.html +118 -0
- data/redist/xmlscan/doc/ja/conformance.ja.rd +134 -0
- data/redist/xmlscan/doc/ja/manual.ja.html +325 -0
- data/redist/xmlscan/doc/ja/manual.ja.rd +370 -0
- data/redist/xmlscan/doc/src/Makefile +41 -0
- data/redist/xmlscan/doc/src/conformance.rd.src +256 -0
- data/redist/xmlscan/doc/src/langsplit.rb +110 -0
- data/redist/xmlscan/doc/src/manual.rd.src +614 -0
- data/redist/xmlscan/install.rb +41 -0
- data/redist/xmlscan/lib/xmlscan/encoding.rb +311 -0
- data/redist/xmlscan/lib/xmlscan/htmlscan.rb +289 -0
- data/redist/xmlscan/lib/xmlscan/namespace.rb +352 -0
- data/redist/xmlscan/lib/xmlscan/parser.rb +299 -0
- data/redist/xmlscan/lib/xmlscan/scanner.rb +1109 -0
- data/redist/xmlscan/lib/xmlscan/version.rb +22 -0
- data/redist/xmlscan/lib/xmlscan/visitor.rb +158 -0
- data/redist/xmlscan/lib/xmlscan/xmlchar.rb +441 -0
- data/redist/xmlscan/memo/CONFORMANCE +1249 -0
- data/redist/xmlscan/memo/PRODUCTIONS +195 -0
- data/redist/xmlscan/memo/contentspec.ry +335 -0
- data/redist/xmlscan/samples/chibixml.rb +105 -0
- data/redist/xmlscan/samples/getxmlchar.rb +122 -0
- data/redist/xmlscan/samples/rexml.rb +159 -0
- data/redist/xmlscan/samples/xmlbench.rb +88 -0
- data/redist/xmlscan/samples/xmlbench/parser/chibixml.rb +22 -0
- data/redist/xmlscan/samples/xmlbench/parser/nqxml.rb +29 -0
- data/redist/xmlscan/samples/xmlbench/parser/rexml.rb +62 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlparser.rb +22 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan-0.0.10.rb +62 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan-chibixml.rb +22 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan-rexml.rb +22 -0
- data/redist/xmlscan/samples/xmlbench/parser/xmlscan.rb +99 -0
- data/redist/xmlscan/samples/xmlbench/xmlbench-lib.rb +116 -0
- data/redist/xmlscan/samples/xmlconftest.rb +200 -0
- data/redist/xmlscan/test.rb +7 -0
- data/redist/xmlscan/tests/deftestcase.rb +73 -0
- data/redist/xmlscan/tests/runtest.rb +47 -0
- data/redist/xmlscan/tests/testall.rb +14 -0
- data/redist/xmlscan/tests/testencoding.rb +438 -0
- data/redist/xmlscan/tests/testhtmlscan.rb +752 -0
- data/redist/xmlscan/tests/testnamespace.rb +457 -0
- data/redist/xmlscan/tests/testparser.rb +591 -0
- data/redist/xmlscan/tests/testscanner.rb +1749 -0
- data/redist/xmlscan/tests/testxmlchar.rb +143 -0
- data/redist/xmlscan/tests/visitor.rb +34 -0
- data/test/array_extensions_test.rb +2 -2
- data/test/ea_instantiator_test.rb +41 -0
- data/test/ecore_self_test.rb +53 -0
- data/test/environment_test.rb +11 -6
- data/test/metamodel_builder_test.rb +404 -245
- data/test/metamodel_roundtrip_test.rb +52 -0
- data/test/metamodel_roundtrip_test/TestModel.rb +65 -0
- data/test/metamodel_roundtrip_test/TestModel_Regenerated.rb +64 -0
- data/test/metamodel_roundtrip_test/houseMetamodel.ecore +32 -0
- data/test/metamodel_roundtrip_test/houseMetamodel_from_ecore.rb +39 -0
- data/test/rgen_test.rb +3 -3
- data/test/template_language_test.rb +65 -39
- data/test/template_language_test/expected_result.txt +24 -3
- data/test/template_language_test/templates/code/array.tpl +11 -0
- data/test/template_language_test/templates/content/author.tpl +7 -0
- data/test/template_language_test/templates/content/chapter.tpl +1 -1
- data/test/template_language_test/templates/root.tpl +17 -8
- data/test/template_language_test/testout.txt +24 -3
- data/test/testmodel/class_model_checker.rb +119 -0
- data/test/{xmi_instantiator_test/testmodel.eap → testmodel/ea_testmodel.eap} +0 -0
- data/test/{xmi_instantiator_test/testmodel.xml → testmodel/ea_testmodel.xml} +81 -14
- data/test/testmodel/ea_testmodel_partial.xml +317 -0
- data/test/testmodel/ecore_model_checker.rb +101 -0
- data/test/testmodel/manual_testmodel.xml +22 -0
- data/test/testmodel/object_model_checker.rb +67 -0
- data/test/transformer_test.rb +18 -10
- data/test/xml_instantiator_test.rb +81 -8
- data/test/xml_instantiator_test/simple_ecore_model_checker.rb +94 -0
- data/test/xml_instantiator_test/simple_xmi_ecore_instantiator.rb +53 -0
- data/test/xml_instantiator_test/simple_xmi_metamodel.rb +49 -0
- data/test/xml_instantiator_test/simple_xmi_to_ecore.rb +75 -0
- metadata +126 -28
- data/lib/ea/xmi_class_instantiator.rb +0 -46
- data/lib/ea/xmi_helper.rb +0 -26
- data/lib/ea/xmi_metamodel.rb +0 -34
- data/lib/ea/xmi_object_instantiator.rb +0 -46
- data/lib/ea/xmi_to_classmodel.rb +0 -78
- data/lib/ea/xmi_to_objectmodel.rb +0 -92
- data/lib/mmgen/mm_ext/uml_classmodel_ext.rb +0 -71
- data/lib/mmgen/templates/uml_classmodel.tpl +0 -63
- data/lib/rgen/xml_instantiator.rb +0 -132
- data/lib/uml/objectmodel_instantiator.rb +0 -53
- data/lib/uml/uml_classmodel.rb +0 -92
- data/lib/uml/uml_objectmodel.rb +0 -65
- data/test/metamodel_generator_test.rb +0 -44
- data/test/metamodel_generator_test/TestModel.rb +0 -40
- data/test/metamodel_generator_test/expected_result.txt +0 -40
- data/test/xmi_class_instantiator_test.rb +0 -24
- data/test/xmi_instantiator_test/class_model_checker.rb +0 -97
- data/test/xmi_object_instantiator_test.rb +0 -65
- data/test/xml_instantiator_test/testmodel.xml +0 -7
data/lib/ea/xmi_metamodel.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
module XMIMetaModel
|
2
|
-
|
3
|
-
module UML
|
4
|
-
|
5
|
-
include RGen::MetamodelBuilder
|
6
|
-
class Classifier_feature < MMBase
|
7
|
-
has_many 'operation'
|
8
|
-
end
|
9
|
-
class ClassifierRole < MMBase
|
10
|
-
end
|
11
|
-
class Clazz < ClassifierRole
|
12
|
-
has_many 'modelElement_stereotype'
|
13
|
-
end
|
14
|
-
class Operation < MMBase
|
15
|
-
has_one 'parent'
|
16
|
-
end
|
17
|
-
class Generalization < MMBase
|
18
|
-
end
|
19
|
-
class ModelElement_stereotype < MMBase
|
20
|
-
has_one 'parent'
|
21
|
-
end
|
22
|
-
class AssociationEnd < MMBase
|
23
|
-
end
|
24
|
-
class AssociationEndRole < MMBase
|
25
|
-
end
|
26
|
-
ClassifierRole.one_to_many 'associationEnds', AssociationEnd, 'typeClass'
|
27
|
-
ClassifierRole.one_to_many 'associationEndRoles', AssociationEndRole, 'typeClass'
|
28
|
-
Clazz.one_to_many 'generalizationsAsSubtype', Generalization, 'subtypeClass'
|
29
|
-
Clazz.one_to_many 'generalizationsAsSupertype', Generalization, 'supertypeClass'
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'rgen/xml_instantiator'
|
2
|
-
require 'rgen/environment'
|
3
|
-
require 'uml/uml_objectmodel'
|
4
|
-
require 'ea/xmi_metamodel'
|
5
|
-
|
6
|
-
# This module can be used to instantiate an UMLObjectModel from an XMI description.
|
7
|
-
#
|
8
|
-
# Here is an example:
|
9
|
-
#
|
10
|
-
# include XMIObjectInstantiator
|
11
|
-
#
|
12
|
-
# envUML = RGen::Environment.new
|
13
|
-
# File.open(MODEL_DIR+"/testmodel.xml") { |f|
|
14
|
-
# XMIClassInstantiator.new.instantiateUMLObjectModel(envUML, f.read)
|
15
|
-
# }
|
16
|
-
#
|
17
|
-
# # now use the newly created UML model
|
18
|
-
# envUML.find(:class => UMLObjectModel::UMLObject).each { |o|
|
19
|
-
# puts o.name
|
20
|
-
# }
|
21
|
-
#
|
22
|
-
# This module relies on XmiToObjectmodel to do the actual transformation.
|
23
|
-
#
|
24
|
-
class XMIObjectInstantiator < RGen::XMLInstantiator
|
25
|
-
|
26
|
-
include UMLObjectModel
|
27
|
-
|
28
|
-
map_tag_ns "omg.org/UML1.3", XMIMetaModel::UML
|
29
|
-
|
30
|
-
resolve_by_id :typeClass, :src => :type, :id => :xmi_id
|
31
|
-
|
32
|
-
def initialize
|
33
|
-
@envXMI = RGen::Environment.new
|
34
|
-
super(@envXMI, XMIMetaModel, true)
|
35
|
-
end
|
36
|
-
|
37
|
-
# This method does the actual work.
|
38
|
-
def instantiateUMLObjectModel(envOut, str)
|
39
|
-
instantiate(str)
|
40
|
-
|
41
|
-
require 'ea/xmi_to_objectmodel'
|
42
|
-
|
43
|
-
XmiToObjectmodel.new(@envXMI,envOut).transform
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
data/lib/ea/xmi_to_classmodel.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'rgen/transformer'
|
2
|
-
require 'ea/xmi_helper'
|
3
|
-
require 'ea/xmi_metamodel'
|
4
|
-
require 'uml/uml_classmodel'
|
5
|
-
require 'rgen/array_extensions'
|
6
|
-
|
7
|
-
# This class is a RGen::Transformer working on an input and output Environment.
|
8
|
-
# It creates an UMLClassModel from an XMI Model instantiated by a
|
9
|
-
# RGen::XMLInstantiator.
|
10
|
-
#
|
11
|
-
# See description of RGen::XMLInstantiator for details about the XMI (meta-)model.
|
12
|
-
# See UMLClassModel for details about the UML Class (meta-)model.
|
13
|
-
class XmiToClassmodel < RGen::Transformer
|
14
|
-
include UMLClassModel
|
15
|
-
include RGen::XMIHelper
|
16
|
-
|
17
|
-
# Do the actual transformation.
|
18
|
-
# Input and output environment have to be provided to the transformer constructor.
|
19
|
-
def transform
|
20
|
-
trans(:class => XMIMetaModel::UML::Clazz)
|
21
|
-
end
|
22
|
-
|
23
|
-
transform XMIMetaModel::UML::Package, :to => UMLPackage do
|
24
|
-
{ :name => name,
|
25
|
-
:superpackage => trans(parent.parent.is_a?(XMIMetaModel::UML::Package) ? parent.parent : nil) }
|
26
|
-
end
|
27
|
-
|
28
|
-
transform XMIMetaModel::UML::Attribute, :to => UMLAttribute do
|
29
|
-
tv = TaggedValueHelper.new(@current_object)
|
30
|
-
{ :name => name, :type => tv['type'] }
|
31
|
-
end
|
32
|
-
|
33
|
-
transform XMIMetaModel::UML::Operation, :to => UMLOperation do
|
34
|
-
{ :name => name }
|
35
|
-
end
|
36
|
-
|
37
|
-
transform XMIMetaModel::UML::TaggedValue, :to => UMLTaggedValue do
|
38
|
-
{ :tag => tag, :value => value }
|
39
|
-
end
|
40
|
-
|
41
|
-
transform XMIMetaModel::UML::Clazz, :to => UMLClass do
|
42
|
-
{ :name => name,
|
43
|
-
:package => trans(parent.parent.is_a?(XMIMetaModel::UML::Package) ? parent.parent : nil),
|
44
|
-
:attributes => trans(classifier_feature.attribute),
|
45
|
-
:operations => trans(classifier_feature.operation),
|
46
|
-
:taggedvalues => trans(modelElement_taggedValue.taggedValue),
|
47
|
-
:stereotypes => modelElement_stereotype.stereotype.name,
|
48
|
-
:subclasses => trans(generalizationsAsSupertype.subtypeClass),
|
49
|
-
:assocEnds => trans(associationEnds)}
|
50
|
-
end
|
51
|
-
|
52
|
-
transform XMIMetaModel::UML::Association, :to => :scAssociationClass do
|
53
|
-
{ :endA => trans(scAssocEnds[0]),
|
54
|
-
:endB => trans(scAssocEnds[1]) }
|
55
|
-
end
|
56
|
-
|
57
|
-
method :scAssocEnds do
|
58
|
-
association_connection.associationEnd
|
59
|
-
end
|
60
|
-
|
61
|
-
method :scAssociationClass do
|
62
|
-
(scAssocEnds[0].aggregation == 'composite' or
|
63
|
-
scAssocEnds[1].aggregation == 'composite' ?
|
64
|
-
UMLAggregation : UMLAssociation )
|
65
|
-
end
|
66
|
-
|
67
|
-
transform XMIMetaModel::UML::AssociationEnd, :to => UMLAssociationEnd do
|
68
|
-
# since we don't want to figure out if we are end A or end B,
|
69
|
-
# we let the association transformer do the work
|
70
|
-
trans(parent.parent)
|
71
|
-
{ :clazz => trans(typeClass),
|
72
|
-
:role => name,
|
73
|
-
:multiplicity => multiplicity,
|
74
|
-
:composite => (aggregation == 'composite'),
|
75
|
-
:navigable => (isNavigable == 'true') }
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
require 'rgen/transformer'
|
2
|
-
require 'ea/xmi_helper'
|
3
|
-
require 'ea/xmi_metamodel'
|
4
|
-
require 'uml/uml_objectmodel'
|
5
|
-
require 'rgen/array_extensions'
|
6
|
-
|
7
|
-
# This class is a RGen::Transformer working on an input and output Environment.
|
8
|
-
# It creates an UMLObjectModel from an XMI Model instantiated by a
|
9
|
-
# RGen::XMLInstantiator.
|
10
|
-
#
|
11
|
-
# See description of RGen::XMLInstantiator for details about the XMI (meta-)model.
|
12
|
-
# See UMLObjectModel for details about the UML Object (meta-)model.
|
13
|
-
class XmiToObjectmodel < RGen::Transformer
|
14
|
-
include UMLObjectModel
|
15
|
-
include RGen::XMIHelper
|
16
|
-
|
17
|
-
# Do the actual transformation.
|
18
|
-
# Input and output environment have to be provided to the transformer constructor.
|
19
|
-
def transform
|
20
|
-
trans(
|
21
|
-
@env_in.find(:class => XMIMetaModel::UML::ClassifierRole)-
|
22
|
-
@env_in.find(:class => XMIMetaModel::UML::Clazz)
|
23
|
-
)
|
24
|
-
end
|
25
|
-
|
26
|
-
transform XMIMetaModel::UML::Package, :to => UMLPackage do
|
27
|
-
{ :name => name,
|
28
|
-
:superpackage => trans(parent.parent.is_a?(XMIMetaModel::UML::Package) ? parent.parent : nil) }
|
29
|
-
end
|
30
|
-
|
31
|
-
transform XMIMetaModel::UML::ClassifierRole, :to => UMLObject, :if => :isEASTypeObject do
|
32
|
-
trans(associationEndRoles.parent.parent)
|
33
|
-
trans(associationEnds.parent.parent)
|
34
|
-
taggedValues = TaggedValueHelper.new(@current_object)
|
35
|
-
{ :name => name,
|
36
|
-
:classname => taggedValues['classname'],
|
37
|
-
:attributeSettings => createAttributeSettings(taggedValues['runstate']),
|
38
|
-
:package => trans(parent.parent.parent.parent) }
|
39
|
-
end
|
40
|
-
|
41
|
-
method :isEASTypeObject do
|
42
|
-
taggedValues = TaggedValueHelper.new(@current_object)
|
43
|
-
taggedValues['ea_stype'] == 'Object'
|
44
|
-
end
|
45
|
-
|
46
|
-
def createAttributeSettings(runstate)
|
47
|
-
return [] unless runstate
|
48
|
-
result = []
|
49
|
-
as = nil
|
50
|
-
runstate.split(';').each do |t|
|
51
|
-
if t == '@VAR'
|
52
|
-
as = @env_out.new UMLAttributeSetting
|
53
|
-
result << as
|
54
|
-
elsif t =~ /(\w+)=(\w+)/
|
55
|
-
as.name = $2 if $1 == 'Variable'
|
56
|
-
as.value = $2 if $1 == 'Value'
|
57
|
-
end
|
58
|
-
end
|
59
|
-
result
|
60
|
-
end
|
61
|
-
|
62
|
-
transform XMIMetaModel::UML::AssociationRole, :to => UMLAssociation, :if => :isEATypeAssociation do
|
63
|
-
ends = association_connection.associationEndRole
|
64
|
-
{ :endA => trans(ends[0]), :endB => trans(ends[1])}
|
65
|
-
end
|
66
|
-
|
67
|
-
method :isEATypeAssociation do
|
68
|
-
taggedValues = TaggedValueHelper.new(@current_object)
|
69
|
-
taggedValues['ea_type'] == 'Association'
|
70
|
-
end
|
71
|
-
|
72
|
-
transform XMIMetaModel::UML::Association, :to => UMLAggregation do
|
73
|
-
ends = association_connection.associationEnd
|
74
|
-
{ :endA => trans(ends[0]), :endB => trans(ends[1])}
|
75
|
-
end
|
76
|
-
|
77
|
-
transform XMIMetaModel::UML::AssociationEndRole, :to => UMLAssociationEnd do
|
78
|
-
buildAssociationEnd
|
79
|
-
end
|
80
|
-
|
81
|
-
transform XMIMetaModel::UML::AssociationEnd, :to => UMLAssociationEnd do
|
82
|
-
buildAssociationEnd
|
83
|
-
end
|
84
|
-
|
85
|
-
method :buildAssociationEnd do
|
86
|
-
{ :object => trans(typeClass),
|
87
|
-
:role => name,
|
88
|
-
:composite => (aggregation == 'composite'),
|
89
|
-
:navigable => (isNavigable == 'true') }
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'rgen/name_helper'
|
2
|
-
|
3
|
-
module UMLClassModel
|
4
|
-
class UMLPackage
|
5
|
-
include RGen::NameHelper
|
6
|
-
|
7
|
-
def moduleName
|
8
|
-
firstToUpper(name)
|
9
|
-
end
|
10
|
-
|
11
|
-
def qualifiedModuleName(rootPackage)
|
12
|
-
return moduleName unless superpackage and self != rootPackage
|
13
|
-
superpackage.qualifiedModuleName(rootPackage) + "::" + moduleName
|
14
|
-
end
|
15
|
-
|
16
|
-
def sortedClasses
|
17
|
-
sortArray = classes.dup
|
18
|
-
i1 = 0
|
19
|
-
while i1 < sortArray.size-1
|
20
|
-
again = false
|
21
|
-
for i2 in i1+1..sortArray.size-1
|
22
|
-
e2 = sortArray[i2]
|
23
|
-
if sortArray[i1].superclasses.include?(e2)
|
24
|
-
sortArray.delete(e2)
|
25
|
-
sortArray.insert(i1,e2)
|
26
|
-
again = true
|
27
|
-
break
|
28
|
-
end
|
29
|
-
end
|
30
|
-
i1 += 1 unless again
|
31
|
-
end
|
32
|
-
sortArray
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class UMLClass
|
37
|
-
include RGen::NameHelper
|
38
|
-
def className
|
39
|
-
firstToUpper(name)
|
40
|
-
end
|
41
|
-
def qualifiedName(rootPackage)
|
42
|
-
(package ? package.qualifiedModuleName(rootPackage) + "::" : "") + className
|
43
|
-
end
|
44
|
-
def RubySuperclass(modules)
|
45
|
-
superclasses = self.superclasses.reject {|c| modules.include?(c.name)}
|
46
|
-
raise StandardError.new("#{self.name}: Duplicate superclasses: #{superclasses}") unless superclasses.size < 2
|
47
|
-
superclasses[0]
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class UMLAttribute
|
52
|
-
def RubyType
|
53
|
-
typeMap = {'float' => 'Float', 'int' => 'Integer'}
|
54
|
-
typeMap[self.getType.downcase] || 'String'
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
class UMLAssociationEnd
|
59
|
-
def MName
|
60
|
-
return self.clazz.name.downcase unless role
|
61
|
-
self.role
|
62
|
-
end
|
63
|
-
def one?
|
64
|
-
self.upperMult == 1 or self.upperMult.nil?
|
65
|
-
end
|
66
|
-
def many?
|
67
|
-
self.upperMult == :many
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
|
2
|
-
<% define 'GenerateClassModel', :for => UMLPackage do |filename, modules| %>
|
3
|
-
<% file filename do %>
|
4
|
-
require 'rgen/metamodel_builder'
|
5
|
-
|
6
|
-
<% expand 'GeneratePackage', modules %>
|
7
|
-
<%nl%>
|
8
|
-
<% expand 'GenerateAssocs' %>
|
9
|
-
<% end %>
|
10
|
-
<% end %>
|
11
|
-
|
12
|
-
<% define 'GeneratePackage', :for => UMLPackage do |modules| %>
|
13
|
-
module <%= moduleName %><% iinc %>
|
14
|
-
<% for c in sortedClasses %><%nl%>
|
15
|
-
<% expand 'ModuleHeader', modules, :for => c %><%iinc%>
|
16
|
-
<% (c.superclasses.name & modules).each do |n| %>
|
17
|
-
include <%= n %>
|
18
|
-
<% end %>
|
19
|
-
<% if modules.include?(c.className) %>
|
20
|
-
extend RGen::MetamodelBuilder::BuilderExtensions
|
21
|
-
<% end %>
|
22
|
-
has_one 'name', String
|
23
|
-
<% for a in c.attributes %>
|
24
|
-
has_one '<%= a.name %>', <%= a.RubyType %>
|
25
|
-
<% end %><%idec%>
|
26
|
-
end
|
27
|
-
<% end %><%nl%>
|
28
|
-
<% for p in subpackages %>
|
29
|
-
<%nl%><% expand 'GeneratePackage', modules, :for => p %>
|
30
|
-
<% end %><%idec%>
|
31
|
-
end
|
32
|
-
<% end %>
|
33
|
-
|
34
|
-
<% define 'GenerateAssocs', :for => UMLPackage do %>
|
35
|
-
<% for a in allClasses.assocEnds>>:assoc %>
|
36
|
-
<% if a.endA.one? %>
|
37
|
-
<% if a.endB.one? %>
|
38
|
-
<%= a.endA.clazz.qualifiedName(this) %>.one_to_one '<%= a.endB.MName %>', <%= a.endB.clazz.qualifiedName(this) %>, '<%= a.endA.MName %>'
|
39
|
-
<% elsif a.endB.many? %>
|
40
|
-
<%= a.endA.clazz.qualifiedName(this) %>.one_to_many '<%= a.endB.MName %>', <%= a.endB.clazz.qualifiedName(this) %>, '<%= a.endA.MName %>'
|
41
|
-
<% end %>
|
42
|
-
<% elsif a.endA.many? %>
|
43
|
-
<% if a.endB.one? %>
|
44
|
-
<%= a.endB.clazz.qualifiedName(this) %>.one_to_many '<%= a.endA.MName %>', <%= a.endA.clazz.qualifiedName(this) %>, '<%= a.endB.MName %>'
|
45
|
-
<% elsif a.endB.many? %>
|
46
|
-
<%= a.endB.clazz.qualifiedName(this) %>.many_to_many '<%= a.endA.MName %>', <%= a.endA.clazz.qualifiedName(this) %>, '<%= a.endB.MName %>'
|
47
|
-
<% end %>
|
48
|
-
<% end %>
|
49
|
-
<% end %>
|
50
|
-
<% end %>
|
51
|
-
|
52
|
-
<% define 'ModuleHeader' do |modules| %>
|
53
|
-
<% if modules.include?(name) %>
|
54
|
-
module <%= className %>
|
55
|
-
<% else %>
|
56
|
-
class <%= className %> < <% nows %>
|
57
|
-
<% if rsc=RubySuperclass(modules) %><% nows %>
|
58
|
-
<%= rsc.className %>
|
59
|
-
<% else %><% nows %>
|
60
|
-
RGen::MetamodelBuilder::MMBase
|
61
|
-
<% end %>
|
62
|
-
<% end %>
|
63
|
-
<% end %>
|
@@ -1,132 +0,0 @@
|
|
1
|
-
require 'rgen/metamodel_builder'
|
2
|
-
require 'rgen/instantiator'
|
3
|
-
require 'rgen/name_helper'
|
4
|
-
require 'rexml/parsers/sax2parser'
|
5
|
-
require 'rexml/sax2listener'
|
6
|
-
|
7
|
-
module RGen
|
8
|
-
|
9
|
-
class XMLInstantiator < Instantiator
|
10
|
-
include REXML::SAX2Listener
|
11
|
-
include NameHelper
|
12
|
-
|
13
|
-
class << self
|
14
|
-
def tag_ns_map
|
15
|
-
@tag_ns_map ||={}
|
16
|
-
@tag_ns_map
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class XMLElementDescriptor
|
21
|
-
attr_reader :tag, :mod, :parent, :attributes
|
22
|
-
attr_accessor :object, :children
|
23
|
-
def initialize(tag, mod, parent, children, attributes)
|
24
|
-
@tag, @mod, @parent, @children, @attributes = tag, mod, parent, children, attributes
|
25
|
-
@parent.children << self if @parent
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
NamespaceDescriptor = Struct.new(:prefix, :target)
|
30
|
-
|
31
|
-
def self.map_tag_ns(from, to, prefix="")
|
32
|
-
tag_ns_map[from] = NamespaceDescriptor.new(prefix, to)
|
33
|
-
end
|
34
|
-
|
35
|
-
def initialize(env, mod, createMM=false)
|
36
|
-
super(env,mod)
|
37
|
-
@env = env
|
38
|
-
@default_module = mod
|
39
|
-
@createMM = createMM
|
40
|
-
@stack = []
|
41
|
-
end
|
42
|
-
|
43
|
-
def instantiate_file(file)
|
44
|
-
File.open(file) { |f| parse(f.read)}
|
45
|
-
resolve
|
46
|
-
end
|
47
|
-
|
48
|
-
def instantiate(text)
|
49
|
-
parse(text)
|
50
|
-
resolve
|
51
|
-
end
|
52
|
-
|
53
|
-
def parse(src)
|
54
|
-
parser = REXML::Parsers::SAX2Parser.new(src)
|
55
|
-
parser.listen(self)
|
56
|
-
parser.parse
|
57
|
-
end
|
58
|
-
|
59
|
-
def start_element(ns, tag, qtag, attributes)
|
60
|
-
ns_desc = self.class.tag_ns_map[ns]
|
61
|
-
tag = ns_desc.nil? ? qtag : ns_desc.prefix+tag
|
62
|
-
mod = (ns_desc && ns_desc.target) || @default_module
|
63
|
-
@stack.push XMLElementDescriptor.new(tag, mod, @stack[-1], [], attributes)
|
64
|
-
end
|
65
|
-
|
66
|
-
def end_element(uri, localname, qname)
|
67
|
-
elementDesc = @stack.pop
|
68
|
-
obj = callBuildMethod(:new_object, NameError, :create_class, elementDesc.mod, elementDesc)
|
69
|
-
@env << obj
|
70
|
-
elementDesc.object = obj
|
71
|
-
elementDesc.children.each { |c|
|
72
|
-
callBuildMethod(:assoc_p2c, NoMethodError, :create_p2c_assoc, elementDesc, c)
|
73
|
-
}
|
74
|
-
elementDesc.attributes.each_pair {|k,v|
|
75
|
-
callBuildMethod(:set_attribute, NoMethodError, :create_attribute, elementDesc, k, v)
|
76
|
-
}
|
77
|
-
# optionally prune children to save memory
|
78
|
-
#elementDesc.children = nil
|
79
|
-
end
|
80
|
-
|
81
|
-
def callBuildMethod(method, exception, mmMethod, *args)
|
82
|
-
begin
|
83
|
-
send(method, *args)
|
84
|
-
rescue exception
|
85
|
-
if @createMM
|
86
|
-
send(mmMethod, *args)
|
87
|
-
send(method, *args)
|
88
|
-
else
|
89
|
-
raise
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
# Model and Metamodel builder methods
|
95
|
-
# These methods are to be overwritten by specific instantiators
|
96
|
-
def new_object(mod, node)
|
97
|
-
mod.const_get(saneClassName(node)).new
|
98
|
-
end
|
99
|
-
|
100
|
-
def create_class(mod, node)
|
101
|
-
mod.const_set(saneClassName(node), Class.new(RGen::MetamodelBuilder::MMBase))
|
102
|
-
end
|
103
|
-
|
104
|
-
def assoc_p2c(parent, child)
|
105
|
-
parent.object.addGeneric(saneMethodName(child), child.object)
|
106
|
-
child.object.setGeneric("parent", parent.object)
|
107
|
-
end
|
108
|
-
|
109
|
-
def create_p2c_assoc(parent, child)
|
110
|
-
parent.object.class.has_many(saneMethodName(child), child.object.class)
|
111
|
-
child.object.class.has_one("parent", RGen::MetamodelBuilder::MMBase)
|
112
|
-
end
|
113
|
-
|
114
|
-
def set_attribute(node, attr, value)
|
115
|
-
node.object.setGeneric(normalize(attr), value)
|
116
|
-
end
|
117
|
-
|
118
|
-
def create_attribute(node, attr, value)
|
119
|
-
node.object.class.has_one(normalize(attr))
|
120
|
-
end
|
121
|
-
|
122
|
-
def saneClassName(node)
|
123
|
-
firstToUpper(normalize(node.tag)).sub(/^Class$/, 'Clazz')
|
124
|
-
end
|
125
|
-
|
126
|
-
def saneMethodName(node)
|
127
|
-
firstToLower(normalize(node.tag)).sub(/^class$/, 'clazz')
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|