rgen 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +9 -0
- data/lib/ea/xmi_class_instantiator.rb +17 -16
- data/lib/ea/xmi_helper.rb +1 -1
- data/lib/ea/xmi_metamodel.rb +25 -10
- data/lib/ea/xmi_object_instantiator.rb +16 -12
- data/lib/ea/xmi_to_classmodel.rb +19 -19
- data/lib/ea/xmi_to_objectmodel.rb +17 -14
- data/lib/mmgen/mmgen.rb +12 -7
- data/lib/rgen/instantiator.rb +62 -0
- data/lib/rgen/metamodel_builder/builder_extensions.rb +30 -4
- data/lib/rgen/model_dumper.rb +24 -0
- data/lib/rgen/name_helper.rb +4 -1
- data/lib/rgen/transformer.rb +20 -2
- data/lib/rgen/xml_instantiator.rb +132 -0
- data/test/metamodel_builder_test.rb +86 -0
- data/test/metamodel_generator_test.rb +1 -2
- data/test/rgen_test.rb +1 -0
- data/test/transformer_test.rb +27 -0
- data/test/xmi_class_instantiator_test.rb +8 -91
- data/test/xmi_instantiator_test/class_model_checker.rb +97 -0
- data/test/xmi_object_instantiator_test.rb +3 -3
- data/test/xml_instantiator_test/testmodel.xml +7 -0
- data/test/xml_instantiator_test.rb +83 -0
- metadata +9 -6
- data/lib/rgen/xml_instantiator/dependency_resolver.rb +0 -23
- data/lib/rgen/xml_instantiator/xml_instantiator.rb +0 -78
- data/lib/rgen/xml_instantiator/xml_parser.rb +0 -39
@@ -1,23 +0,0 @@
|
|
1
|
-
# RGen Framework
|
2
|
-
# (c) Martin Thiede, 2006
|
3
|
-
|
4
|
-
require 'rgen/name_helper'
|
5
|
-
|
6
|
-
module RGen
|
7
|
-
|
8
|
-
module DependencyResolver
|
9
|
-
include NameHelper
|
10
|
-
|
11
|
-
def resolveById(idAttribute,refAttribute)
|
12
|
-
lookup = {}
|
13
|
-
@elements.each { |e|
|
14
|
-
lookup[e.send("get"+firstToUpper(idAttribute))] = e if e.respond_to?("get"+firstToUpper(idAttribute))
|
15
|
-
}
|
16
|
-
@elements.each { |e|
|
17
|
-
target = lookup[e.send("get"+firstToUpper(refAttribute))] if e.respond_to?("get"+firstToUpper(refAttribute))
|
18
|
-
assocObjectsOneToMany(target, className(e)+"_"+refAttribute, e, refAttribute+"_"+className(target)) if target
|
19
|
-
}
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# RGen Framework
|
2
|
-
# (c) Martin Thiede, 2006
|
3
|
-
|
4
|
-
require 'rgen/name_helper'
|
5
|
-
require 'rgen/xml_instantiator/xml_parser'
|
6
|
-
require 'rgen/xml_instantiator/dependency_resolver'
|
7
|
-
|
8
|
-
module RGen
|
9
|
-
|
10
|
-
class XMLInstantiator
|
11
|
-
include NameHelper
|
12
|
-
include DependencyResolver
|
13
|
-
|
14
|
-
def initialize(mod, createMM=false, &config)
|
15
|
-
@mod = mod
|
16
|
-
@createMM = createMM
|
17
|
-
@configBlock = config
|
18
|
-
end
|
19
|
-
|
20
|
-
def instantiate(env, str)
|
21
|
-
@elements = []
|
22
|
-
XMLParser.new(self).parse(str)
|
23
|
-
@configBlock.call(self) if @configBlock
|
24
|
-
@elements.each {|e| env << e}
|
25
|
-
end
|
26
|
-
|
27
|
-
def newObject(name)
|
28
|
-
# capitalize first letter only
|
29
|
-
className = firstToUpper(normalizeName(name))
|
30
|
-
begin
|
31
|
-
cls = @mod.const_get(className)
|
32
|
-
obj = cls.new
|
33
|
-
@elements << obj
|
34
|
-
return obj
|
35
|
-
rescue NameError
|
36
|
-
if @createMM
|
37
|
-
@mod.module_eval("class #{className} < RGen::MetamodelBuilder::MMBase; end")
|
38
|
-
retry
|
39
|
-
else
|
40
|
-
raise
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def setAttribute(obj, name, val)
|
46
|
-
m = normalizeName(name)
|
47
|
-
begin
|
48
|
-
obj.send("#{m}=", val)
|
49
|
-
rescue NoMethodError
|
50
|
-
if @createMM
|
51
|
-
obj.class.has_one(m)
|
52
|
-
retry
|
53
|
-
else
|
54
|
-
raise
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def assocObjectsParentToChild(parent, child)
|
60
|
-
assocObjectsOneToMany(parent,className(child),child,"_p_"+className(parent))
|
61
|
-
end
|
62
|
-
|
63
|
-
def assocObjectsOneToMany(objOne, roleOne, objMany, roleMany)
|
64
|
-
begin
|
65
|
-
objOne.addGeneric(roleOne, objMany)
|
66
|
-
rescue NoMethodError => nme
|
67
|
-
if @createMM
|
68
|
-
objOne.class.one_to_many(roleOne, objMany.class, roleMany)
|
69
|
-
retry
|
70
|
-
else
|
71
|
-
raise
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# RGen Framework
|
2
|
-
# (c) Martin Thiede, 2006
|
3
|
-
|
4
|
-
require 'rexml/parsers/sax2parser'
|
5
|
-
require 'rexml/sax2listener'
|
6
|
-
|
7
|
-
module RGen
|
8
|
-
|
9
|
-
class XMLParser
|
10
|
-
include REXML::SAX2Listener
|
11
|
-
include NameHelper
|
12
|
-
|
13
|
-
def initialize(instantiator)
|
14
|
-
@stack = []
|
15
|
-
@inst = instantiator
|
16
|
-
end
|
17
|
-
|
18
|
-
def parse(src)
|
19
|
-
parser = REXML::Parsers::SAX2Parser.new(src)
|
20
|
-
parser.listen(self)
|
21
|
-
parser.parse
|
22
|
-
end
|
23
|
-
|
24
|
-
def start_element(uri, localname, qname, attributes)
|
25
|
-
currentObject = @inst.newObject(qname)
|
26
|
-
@inst.assocObjectsParentToChild(@stack[-1],currentObject) if @stack.size > 0
|
27
|
-
attributes.each_pair { |a,v|
|
28
|
-
@inst.setAttribute(currentObject, a, v)
|
29
|
-
}
|
30
|
-
@stack.push currentObject
|
31
|
-
end
|
32
|
-
|
33
|
-
def end_element(uri, localname, qname)
|
34
|
-
@stack.pop
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|