rgen 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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