1: CLASS-ID. XmlConfiguration as "CoolThings.Commons.XmlConfiguration".
2:
3: environment division.
4: configuration section.
5: repository.
6: class SystemException as "System.Exception"
7: class SystemString as "System.String"
8: class SystemXmlDocument as "System.Xml.XmlDocument"
9: class SystemXmlNode as "System.Xml.XmlNode"
10: class SystemIOFileNotFoundException as "System.IO.FileNotFoundException"
11: class SystemNullReferenceException as "System.NullReferenceException"
12: class SystemEnvironment as "System.Environment"
13: class SystemInt32 as "System.Int32"
14:
15: *> object properties
16: property InnerText as "InnerText"
17: property StringValue as "StringValue"
18: property StringEmpty as "Empty".
19:
20: static.
21: data division.
22: working-storage section.
23: 01 instance usage object reference XmlConfiguration is private.
24:
25: procedure division.
26: method-id. GetInstance AS "GetInstance".
27: data division.
28: linkage section.
29: 01 localSingleton usage object reference XmlConfiguration.
30:
31: procedure division returning localSingleton.
32: if (instance equal null) then
33: invoke XmlConfiguration "NEW" returning localSingleton
34: set instance to localSingleton
35: else
36: set localSingleton to instance
37: end-if
38:
39: end method GetInstance.
40: end static.
41:
42: *> Instance's data and methods
43: object.
44: environment division.
45: data division.
46: working-storage section.
47:
48: 01 xmlDocument usage object reference SystemXmlDocument is private.
49: 01 xmlNode usage object reference SystemXmlNode is private.
50: 01 envName usage object reference SystemString is private.
51: 01 emptyString usage object reference SystemString is private.
52:
53: 01 nullReferenceException usage object reference SystemNullReferenceException.
54: 01 sysException usage object reference SystemException.
55: 01 fileNotFoundException usage object reference SystemIOFileNotFoundException.
56:
57: procedure division.
58:
59: method-id. NEW is private.
60: data division.
61: working-storage section.
62: 01 environmentVariable usage object reference SystemEnvironment.
63: procedure division.
64: *> Retrieve file name from environment variable "XML_CONFIGFILE"
65: *> If XML_CONFIGFILE is not set then the default would be "application.config"
66:
67: invoke SystemEnvironment "GetEnvironmentVariable" using "XML_CONFIGFILE" returning envName
68:
69: if (SystemString::"Equals"(NULL, envName)= b"1") then
70: set envName to "app.config"
71: end-if
72:
73: *> Load the xml document
74: invoke SystemXmlDocument "NEW" returning xmlDocument
75: try
76: invoke xmlDocument "Load" using envName
77:
78: catch fileNotFoundException
79: display "File not found" *> TODO: to replace with a logger
80:
81: end-try.
82:
83: end method NEW.
84:
85: method-id. GetKey as "GetKey".
86: data division.
87: working-storage section.
88: linkage section.
89: 01 aKey usage object reference SystemString.
90: 01 keyValue usage object reference SystemString.
91:
92: procedure division using aKey returning keyValue.
93:
94: try
95: invoke self "ValidateKey" using aKey
96:
97: set aKey to SystemString::"Concat"(n"/", aKey)
98:
99: invoke xmlDocument "SelectSingleNode" using aKey returning xmlNode
100:
101: set keyValue to InnerText OF xmlNode
102:
103: catch SysException
104: set keyValue to SystemString::"Concat"(n"@@Invalid key:", aKey)
105:
106: end-try
107:
108: end method GetKey.
109:
110: method-id. ValidateKey as "ValidateKey" is private.
111: data division.
112: working-storage section.
113: 01 valueZeros USAGE BINARY-LONG SIGNED value zeros.
114: 01 valueMinusOne USAGE BINARY-LONG SIGNED value -1.
115:
116: linkage section.
117: 01 aKey usage object reference SystemString.
118:
119: procedure division using aKey raising SystemException.
120: set valueMinusOne to aKey::"IndexOf"("//") 121: set valueZeros to aKey::"IndexOf"("/") 122:
123: if valueMinusOne not = -1 or valueZeros not equal zeros then
124: invoke SystemException "NEW" returning sysException
125: exit method raising SysException
126: end-if
127: end method ValidateKey.
128:
129: end object.
130: END CLASS XmlConfiguration.
131:
132:
1: CLASS-ID. Utils as "AFP.Utils".
2: environment division.
3: configuration section.
4: repository.
5: class ClassXmlConfiguration as "CoolThings.Commons.XmlConfiguration"
6: class SystemString as "System.String"
7: class CollectionHashTable as "System.Collections.Hashtable".
8:
9: static.
10: data division.
11: working-storage section.
12: 01 xmlConfig usage object reference ClassXmlConfiguration.
13: 01 driverName usage object reference SystemString.
14: 01 keyValue pic n(200).
15: procedure division.
16: method-id. GetCheckoutDrivers as "GetCheckoutDrivers" is public.
17: data division.
18: linkage section.
19: 01 hashTable usage object reference CollectionHashTable.
20:
21: procedure division returning hashTable.
22: invoke ClassXmlConfiguration "GetInstance" returning xmlConfig
23:
24: invoke CollectionHashTable "NEW" returning hashTable
25:
26: set keyValue to xmlConfig::"GetKey"(n"/configuration/checkout/currentSupplier")
27: set keyValue to SystemString::"Concat"(keyValue, n"/currentSet")
28: set keyValue to xmlConfig::"GetKey"(keyValue)
29: set driverName to SystemString::"Concat"(keyValue, n"/cashDrawer")
30: set driverName to xmlConfig::"GetKey"(driverName)
31:
32: invoke hashTable "Add" using "CashDrawer", driverName
33: set driverName to SystemString::"Concat"(keyValue, n"/receiptPrinter")
34: set driverName to xmlConfig::"GetKey"(driverName)
35:
36: invoke hashTable "Add" using "ReceiptPrinter", driverName.
37:
38: end method GetCheckoutDrivers.
39: end static.
40: END CLASS Utils.