Class: VPMSPackageSchemaInterpreter

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

Instance Method Details

#applyTransform(*args) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/VPMSPackageSchemaInterpreter.rb', line 89

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, "VPMSPackageSchemaInterpreter.xsl")
    transformed_xml = xslt.serve()
    transformed_xml
end

#endpackageObject



66
67
# File 'lib/VPMSPackageSchemaInterpreter.rb', line 66

def endpackage
end

#endSchemaObject



80
81
82
83
84
85
86
87
# File 'lib/VPMSPackageSchemaInterpreter.rb', line 80

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

#getResultObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/VPMSPackageSchemaInterpreter.rb', line 19

def getResult
  @entities = Hash.new
  @coverages = Hash.new
  getResult = ""
  getResult << startSchema
  if (@arProductsSplit != nil) then
    @arProductsSplit.each do |a|
        open(File.join(a,"/product.oil")) {|f| @contents = f.read }
        dsl = @contents.to_s
        h = CollesceProductInterpreter.execute(dsl)
        @entities.merge!(h[0])
        @coverages.merge!(h[1])
        #open(File.join(a,"/product.oil")) {|f| @contents = f.read }
        #dsl = @contents.to_s
        #frag = VPMSProductSchemaInterpreter.execute(dsl,a)
        #getResult << applyTransform(frag)
    end
    collescedProduct = "product :CommercialProperty\n"
    collescedProduct << "entities\n"
    @entities.each do |k,v|
      collescedProduct << "#{v} :#{k}\n"
    end
    collescedProduct << "entities\n"
    collescedProduct << "coverages\n"
    @coverages.each do |k,v|
      collescedProduct << "#{v} :#{k}\n"
    end
    collescedProduct << "coverages\n"
    collescedProduct << "endproduct"
    #puts collescedProduct
    frag = VPMSProductSchemaInterpreter.execute(collescedProduct,"#{OIL_DSL_ROOT.gsub('*','')}Retailer/DSL")
    getResult << applyTransform(frag)
  end
  getResult << endSchema
end

#package(*args) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/VPMSPackageSchemaInterpreter.rb', line 55

def package(*args)
	theDir = "#{OIL_DSL_ROOT}"
	@schemaFragments = ""
  @arProductsSplit = Array.new
   Dir.glob(File.join(theDir, '*'), File::FNM_PATHNAME) do |p|
    if File.directory?(p)
    	@arProductsSplit.push(p)
    end
   end
end

#startSchemaObject



69
70
71
72
73
74
75
76
77
78
# File 'lib/VPMSPackageSchemaInterpreter.rb', line 69

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 << "<xs:element xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" name=\"CommercialProperty\">\n"
  openSchema << "<xs:complexType>\n"
  openSchema << "<xs:sequence>\n"
  openSchema
end