Class: VPMSSchemaInterpreter

Inherits:
DslContext show all
Defined in:
lib/VPMSSchemaInterpreter.rb

Instance Method Summary collapse

Methods inherited from DslContext

bubble, execute, polish_text

Instance Method Details

#coverage(*args) ⇒ Object



114
115
116
117
118
119
120
121
122
# File 'lib/VPMSSchemaInterpreter.rb', line 114

def coverage(*args)
  @erbAry = []
  @metaProps = {}
  @erb = ""
  @metaprop = ""
  @argName = "#{args[0]}"
  io = open(File.join(COVERAGE_DEF_ROOT,"/#{@argName}PropertyHash"),'r' )
  @prdhash = YAML::load(io)
end

#endComplexTypeObject



94
95
96
97
98
99
# File 'lib/VPMSSchemaInterpreter.rb', line 94

def endComplexType
  endElement = ""
  endElement << endSequence
  endElement << "</xs:complexType>\n"
  endElement
end

#endcoverage(*args) ⇒ Object



124
125
# File 'lib/VPMSSchemaInterpreter.rb', line 124

def endcoverage(*args)
end

#endElementObject



80
81
82
83
84
# File 'lib/VPMSSchemaInterpreter.rb', line 80

def endElement
  endElement = ""
  endElement << "</xs:element>\n"
  endElement
end

#endSchemaObject



49
50
51
52
53
# File 'lib/VPMSSchemaInterpreter.rb', line 49

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

#endSequenceObject



108
109
110
111
112
# File 'lib/VPMSSchemaInterpreter.rb', line 108

def endSequence
  endElement = ""
  endElement << "</xs:sequence>\n"
  endElement
end

#getResultObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/VPMSSchemaInterpreter.rb', line 14

def getResult
    getResult = ""
    getResult << startSchema
    @erbAry.each do |a|
      b = a.to_s
      getResult << "\t"
      getResult << processXPath(a, b)
    end
    getResult << endSchema
end

#processXPath(*args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/VPMSSchemaInterpreter.rb', line 25

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



86
87
88
89
90
91
92
# File 'lib/VPMSSchemaInterpreter.rb', line 86

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



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/VPMSSchemaInterpreter.rb', line 55

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



41
42
43
44
45
46
47
# File 'lib/VPMSSchemaInterpreter.rb', line 41

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



101
102
103
104
105
106
# File 'lib/VPMSSchemaInterpreter.rb', line 101

def startSequence
  #ToDo: Make this a widget - a schema open widget for example
  openElement = ""
  openElement << "<xs:sequence>\n"
  openElement
end

#use(*args) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/VPMSSchemaInterpreter.rb', line 127

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    
  myHash = @prdhash["#{hashname}"].clone
  if (myHash.length == 1)
    hashname = @argName + lasth
    specificProperty = true
    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 = ""
   
   #xpaths each now in erbArray

end