Class: RGen::Serializer::XMI20Serializer
Constant Summary
RGen::Serializer::XMLSerializer::INDENT_SPACE
Instance Method Summary
collapse
#endTag, #initialize, #startTag, #writeText
Instance Method Details
#addBuiltinReferenceStrings ⇒ Object
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/rgen/serializer/xmi20_serializer.rb', line 56
def addBuiltinReferenceStrings
pre = "ecore:EDataType http://www.eclipse.org/emf/2002/Ecore"
@referenceStrings[RGen::ECore::EString] = pre+"#//EString"
@referenceStrings[RGen::ECore::EInt] = pre+"#//EInt"
@referenceStrings[RGen::ECore::ELong] = pre+"#//ELong"
@referenceStrings[RGen::ECore::EFloat] = pre+"#//EFloat"
@referenceStrings[RGen::ECore::EBoolean] = pre+"#//EBoolean"
@referenceStrings[RGen::ECore::EJavaObject] = pre+"#//EJavaObject"
@referenceStrings[RGen::ECore::EJavaClass] = pre+"#//EJavaClass"
end
|
#attributeValues(element) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/rgen/serializer/xmi20_serializer.rb', line 35
def attributeValues(element)
result = []
eAllAttributes(element).select{|a| !a.derived}.each do |a|
val = element.getGeneric(a.name)
result << [a.name, val] unless val.nil? || val == ""
end
eAllReferences(element).select{|r| !r.containment && !(r.eOpposite && r.eOpposite.containment) && !r.derived}.each do |r|
targetElements = element.getGenericAsArray(r.name)
val = targetElements.collect{|te| @referenceStrings[te]}.compact.join(' ')
result << [r.name, val] unless val.nil? || val == ""
end
result
end
|
#buildReferenceStrings(element, string) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/rgen/serializer/xmi20_serializer.rb', line 49
def buildReferenceStrings(element, string)
@referenceStrings[element] = string
eachReferencedElement(element, containmentReferences(element)) do |r,te|
buildReferenceStrings(te, string+"/"+te.name) if te.respond_to?(:name)
end
end
|
#serialize(rootElement) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/rgen/serializer/xmi20_serializer.rb', line 9
def serialize(rootElement)
@referenceStrings = {}
buildReferenceStrings(rootElement, "#/")
addBuiltinReferenceStrings
attrs = attributeValues(rootElement)
attrs << ['xmi:version', "2.0"]
attrs << ['xmlns:xmi', "http://www.omg.org/XMI"]
attrs << ['xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance"]
attrs << ['xmlns:ecore', "http://www.eclipse.org/emf/2002/Ecore" ]
tag = "ecore:"+rootElement.class.ecore.name
startTag(tag, attrs)
writeComposites(rootElement)
endTag(tag)
end
|
#writeComposites(element) ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/rgen/serializer/xmi20_serializer.rb', line 24
def writeComposites(element)
eachReferencedElement(element, containmentReferences(element)) do |r,te|
attrs = attributeValues(te)
attrs << ['xsi:type', "ecore:"+te.class.ecore.name]
tag = r.name
startTag(tag, attrs)
writeComposites(te)
endTag(tag)
end
end
|