Class: VPMSComponentSchemaInterpreter

Inherits:
DslContext
  • Object
show all
Defined in:
lib/VPMSComponentSchemaInterpreter.rb

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

#initialize(*args) ⇒ VPMSComponentSchemaInterpreter

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

#applyTransform(*args) ⇒ Object



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

#endComplexTypeObject



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

#endElementObject



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

#endSchemaObject



75
76
77
78
79
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 75

def endSchema
  endSchema = ""
  endSchema << "</xs:schema>\n"
  endSchema
end

#endSequenceObject



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

#getResultObject



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
      #a.to_s
      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

#startComplexTypeObject



112
113
114
115
116
117
118
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 112

def startComplexType
  #ToDo: Make this a widget - a schema open widget for example
  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)
  #ToDo: Make this a widget - an element open widget for example
  openElement = ""
  openElement << "<xs:element name=\"#{args[0]}\""
  #ToDo: do something better to get type info - 
  #if this is the ultimate point in the xpath, this pushes in a data type of string - thats all
  if (args[2] == true) then
    openElement << " type=\"xs:string\">\n"
  else
    openElement << ">\n"
  end
  #ToDo: Read the element type and other atts off the MD hash metadata.
  #args 1 is the full xpath of the element used potentially to key into the md hash 
  #Potentially do this if args 2 is true (it's the last xpath step) and use args 1 for the key
  #args 2 represents a key into a hash
  #the @metaProps hash for example - see 'coverage'
  #If there is an entry in that hash for this element's xpath, then a type attribute can be
  #determined for it and gets used from the md hash - When the element is nesting a ct, there's no type attribute
  #This key would be used to read off values in that hash, if it is a hash of hashes - 
  #i.e. if the buildingsCoverSumInsuredAmount key in the metaProps referenced a hash of metadata:
  #It would also be possible to reference entries for this element in the existing 
  #xml dictionary, which is keyed on this element's xpath
  openElement
end

#startSchemaObject



67
68
69
70
71
72
73
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 67

def startSchema
  #ToDo: Make this a widget - a schema open widget for example
  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

#startSequenceObject



127
128
129
130
131
132
# File 'lib/VPMSComponentSchemaInterpreter.rb', line 127

def startSequence
  #ToDo: Make this a widget - a schema open widget for example
  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
  
  #now figure out whether the last arg above leads to an empty hash
  #i.e. it is really a single value field
  #if so backup a level and read the property whose name = the last arg value passed in
  
  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
         #In progress
         #@metaprop = @erb.sub('/', '') stands as an xpath key to the metadata in the 'element properties' hash
         
       end
     end
   end
   
   erbTemp = @erb.split('/')
   @erbAry.push(erbTemp)
   @erb = ""

end