Class: VPMSComponentSchemaInterpreter
Constant Summary
collapse
- VPMS_SCHEMA_INTERPRETER_ROOT =
File.dirname(__FILE__)
- XSL_ROOT =
File.join(VPMS_SCHEMA_INTERPRETER_ROOT, 'xslt')
- MOCK_ROOT =
File.join(VPMS_SCHEMA_INTERPRETER_ROOT, 'mocks')
Instance Method Summary
collapse
Methods inherited from DslContext
bubble, execute, polish_text
Constructor Details
Returns a new instance of VPMSComponentSchemaInterpreter.
20
21
22
23
24
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 20
def initialize(*args)
@props = args
@useDynamicFileMapping = (args.length > 0) ? true : false
@hashesRoot = (args.length > 0) ? OIL_HASH_ROOT : ENTITY_DEF_ROOT
end
|
Instance Method Details
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 55
def applyTransform(*args)
require 'rexml/document'
require 'xml/xslt'
xslt = XML::XSLT.new()
string = args[0]
doc = REXML::Document.new(string)
xslt.xml = doc
xslt.xsl = File.join(XSL_ROOT, "VPMSSchemaInterpreter.xsl")
transformed_xml = xslt.serve()
transformed_xml
end
|
#coverage(*args) ⇒ Object
140
141
142
143
144
145
146
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 140
def coverage(*args)
@erbAry = []
@erb = ""
@argName = "#{args[0]}"
@useDynamicFileMapping == true ? io = open(File.join(@hashesRoot,"/coverages/#{@argName}PropertyHash"),'r' ) : io = open(File.join(COVERAGE_DEF_ROOT,"/#{@argName}PropertyHash"),'r' )
@prdhash = YAML::load(io)
end
|
#endComplexType ⇒ Object
120
121
122
123
124
125
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 120
def endComplexType
endElement = ""
endElement << endSequence
endElement << "</xs:complexType>\n"
endElement
end
|
#endcoverage(*args) ⇒ Object
148
149
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 148
def endcoverage(*args)
end
|
#endElement ⇒ Object
106
107
108
109
110
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 106
def endElement
endElement = ""
endElement << "</xs:element>\n"
endElement
end
|
#endentity(*args) ⇒ Object
159
160
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 159
def endentity(*args)
end
|
#endSchema ⇒ Object
75
76
77
78
79
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 75
def endSchema
endSchema = ""
endSchema << "</xs:schema>\n"
endSchema
end
|
#endSequence ⇒ Object
134
135
136
137
138
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 134
def endSequence
endElement = ""
endElement << "</xs:sequence>\n"
endElement
end
|
#entity(*args) ⇒ Object
151
152
153
154
155
156
157
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 151
def entity(*args)
@erbAry = []
@erb = ""
@argName = "#{args[0]}"
@useDynamicFileMapping == true ? io = open(File.join(@hashesRoot,"/entities/#{@argName}PropertyHash"),'r' ) : io = open(File.join(ENTITY_DEF_ROOT,"/#{@argName}PropertyHash"),'r' )
@prdhash = YAML::load(io)
end
|
#getResult ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 26
def getResult
getResult = ""
getResult << startSchema
@erbAry.each do |a|
b = a.first
getResult << "\t"
getResult << processXPath(a, b)
end
getResult << endSchema
getResult
end
|
#processXPath(*args) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 39
def processXPath(*args)
processXpath = ""
xpath = args[0]
boolEndOfPath = (args[0].length == 1)
processXpath << "\t"
processXpath << startElement(args[0].first, args[1], boolEndOfPath)
xpath.delete_at(0)
if xpath.length > 0
processXpath << startComplexType
processXpath << processXPath(xpath, args[1])
processXpath << endComplexType
end
processXpath << endElement
processXpath
end
|
#startComplexType ⇒ Object
112
113
114
115
116
117
118
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 112
def startComplexType
openElement = ""
openElement << "<xs:complexType>\n"
openElement << startSequence
openElement
end
|
#startElement(*args) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 81
def startElement(*args)
openElement = ""
openElement << "<xs:element name=\"#{args[0]}\""
if (args[2] == true) then
openElement << " type=\"xs:string\">\n"
else
openElement << ">\n"
end
openElement
end
|
#startSchema ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 67
def startSchema
openSchema = ""
openSchema << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
openSchema << "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n"
openSchema
end
|
#startSequence ⇒ Object
127
128
129
130
131
132
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 127
def startSequence
openElement = ""
openElement << "<xs:sequence>\n"
openElement
end
|
#use(*args) ⇒ Object
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 162
def use(*args)
h = ""
lasth = ""
lasta = ""
args.each do |a|
unless a.class == Hash
lasth = String.new(h)
h << "#{a}"
lasta = a
end
end
hashname = @argName + h
specificProperty = false
if !@prdhash.has_key?(hashname)
puts "missing key for #{hashname} when processing:use #{args}"
end
myHash = @prdhash["#{hashname}"].clone
if (myHash.length == 1)
hashname = @argName + lasth
specificProperty = true
if !@prdhash.has_key?(hashname)
puts "missing key for #{hashname} when processing:use #{args}"
end
myHash = @prdhash["#{hashname}"].clone
end
@erb << myHash["#{'xpath'}"]
myHash.each do |property, value|
if (property != 'xpath' and (property =~ /MD$/) == nil) then
if (value == "" && (!specificProperty || (specificProperty && property == "#{lasta}"))) then
@erb << "/"
@erb << property
end
end
end
erbTemp = @erb.split('/')
@erbAry.push(erbTemp)
@erb = ""
end
|