Class: VPMSProductSchemaInterpreter

Inherits:
DslContext show all
Defined in:
lib/VPMSProductSchemaInterpreter.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) ⇒ VPMSProductSchemaInterpreter

Returns a new instance of VPMSProductSchemaInterpreter.



18
19
20
21
22
# File 'lib/VPMSProductSchemaInterpreter.rb', line 18

def initialize(*args)
		@props = args
		@useDynamicFileMapping = (args.length > 0) ? true : false
		@productDSLRoot = (args.length > 0) ? args[0] : ENTITY_DSL_ROOT
end

Instance Method Details

#applyTransform(*args) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/VPMSProductSchemaInterpreter.rb', line 39

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

#conditional_on(*args) ⇒ Object



112
113
# File 'lib/VPMSProductSchemaInterpreter.rb', line 112

def conditional_on(*args)
end

#coverages(*args) ⇒ Object



101
102
103
# File 'lib/VPMSProductSchemaInterpreter.rb', line 101

def coverages(*args)
  @libtype = "coverages"
end

#endcoveragesObject



105
106
107
# File 'lib/VPMSProductSchemaInterpreter.rb', line 105

def endcoverages
  
end

#endentitiesObject



97
98
99
# File 'lib/VPMSProductSchemaInterpreter.rb', line 97

def endentities
  
end

#endproductObject



89
90
91
# File 'lib/VPMSProductSchemaInterpreter.rb', line 89

def endproduct
  
end

#endRootObject



75
76
77
78
79
80
81
# File 'lib/VPMSProductSchemaInterpreter.rb', line 75

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

#endSchemaObject



58
59
60
61
62
# File 'lib/VPMSProductSchemaInterpreter.rb', line 58

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

#entities(*args) ⇒ Object



93
94
95
# File 'lib/VPMSProductSchemaInterpreter.rb', line 93

def entities(*args)
  @libtype = "entities"
end

#for_ABI_codes(*args) ⇒ Object



109
110
# File 'lib/VPMSProductSchemaInterpreter.rb', line 109

def for_ABI_codes(*args)
end

#getDenormalisedSchemaObject



29
30
31
32
33
34
35
36
37
# File 'lib/VPMSProductSchemaInterpreter.rb', line 29

def getDenormalisedSchema
    getSchema = ""
    getSchema << startSchema
    getSchema << startRoot(@classDef)
    getSchema << @schemaFragments
    getSchema << endRoot
    getSchema << endSchema
    getSchema
end

#getResultObject



24
25
26
27
# File 'lib/VPMSProductSchemaInterpreter.rb', line 24

def getResult
    @getResult = ""
    @getResult << getDenormalisedSchema
end

#has(*args) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/VPMSProductSchemaInterpreter.rb', line 123

def has(*args)
 		if (@useDynamicFileMapping == true) then
 			open(File.join(@productDSLRoot,"#{@libtype}/#{args[0]}.oil")) {|f| @contents = f.read }
 		else
 			open(File.join(@productDSLRoot,"/#{args[0]}.oil")) {|f| @contents = f.read }
 		end
   	dsl = @contents.to_s
   	# todo: bit clumsy but need it working
   	if (@useDynamicFileMapping == true) then
   		frag = VPMSComponentSchemaInterpreter.execute(dsl,@useDynamicFileMapping)
   	else
   		frag = VPMSComponentSchemaInterpreter.execute(dsl)
   	end
   	@schemaFragments << applyTransform(frag)
end

#has_between(*args) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/VPMSProductSchemaInterpreter.rb', line 139

def has_between(*args)
		if (@useDynamicFileMapping == true) then
			open(File.join(@productDSLRoot,"#{@libtype}/#{args[2]}.oil")) {|f| @contents = f.read }
		else
			open(File.join(@productDSLRoot,"/#{args[0]}.oil")) {|f| @contents = f.read }
		end
  	dsl = @contents.to_s
  	# todo: bit clumsy but need it working
  	if (@useDynamicFileMapping == true) then
  		frag = VPMSComponentSchemaInterpreter.execute(dsl,@useDynamicFileMapping)
  	else
  		frag = VPMSComponentSchemaInterpreter.execute(dsl)
  	end
  	@schemaFragments << applyTransform(frag)
end

#has_many(*args) ⇒ Object



119
120
121
# File 'lib/VPMSProductSchemaInterpreter.rb', line 119

def has_many(*args)
	has(args)
end

#has_one(*args) ⇒ Object



115
116
117
# File 'lib/VPMSProductSchemaInterpreter.rb', line 115

def has_one(*args)
	has(args)
end

#product(*args) ⇒ Object



83
84
85
86
87
# File 'lib/VPMSProductSchemaInterpreter.rb', line 83

def product(*args)
  @requires = ""
  @schemaFragments = ""
  @classDef = "#{args[0]}"
end

#startRoot(*args) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/VPMSProductSchemaInterpreter.rb', line 64

def startRoot(*args)
  #ToDo: Make this a widget - an element open widget for example
  openElement = ""
  openElement << "<xs:element name=\"#{args[0]}\">\n"
  openElement << "<xs:complexType>\n"
  openElement << "<xs:sequence>\n"
  openElement << "<xs:element name=\"Brand\" type=\"xs:string\"/>\n"
  openElement << "<xs:element name=\"Package\" type=\"xs:string\"/>\n"
  openElement
end

#startSchemaObject



51
52
53
54
55
56
# File 'lib/VPMSProductSchemaInterpreter.rb', line 51

def startSchema
  #ToDo: Make this a widget - a schema open widget for example
  openSchema = ""
  openSchema << "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n"
  openSchema
end