1 package com.instantbank.collections.commonQueuing.web;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.IOException;
5 import java.io.PrintWriter;
6 import java.io.StringWriter;
7 import oracle.xml.parser.v2.DOMParser;
8 import oracle.xml.parser.v2.XMLDocument;
9 import oracle.xml.parser.v2.XMLNode;
10 import oracle.xml.parser.v2.XMLParseException;
11 import oracle.xml.parser.v2.XSLException;
12 import org.w3c.dom.Element;
13 import org.w3c.dom.NodeList;
14 import org.xml.sax.SAXException;
15 import com.instantbank.collections.util.InstantbankException;
16 import com.instantbank.collections.util.XMLUtils;
17
18 public class ClassTransformer {
19 long companyId;
20 XMLDocument doc;
21 FieldsTransformer ft = null;
22 String objectType = "A";
23
24
25
32 public ClassTransformer(Long companyId, String objectType) throws InstantbankException {
33 this.ft = new FieldsTransformer(companyId, objectType);
34 this.objectType = objectType;
35 this.companyId = companyId.longValue();
36 }
37
38
39 public String getDescription() {
40 return getValueOf("Class/description");
41 }
42
43
44 public String getFieldsArray() {
45 return ft.getFieldsArray();
46 }
47
48
49 public String getId() {
50 return getValueOf("Class/id");
51 }
52
53
54 public String getLastChangedBy() {
55 return getValueOf("Class/lastchangedby");
56 }
57
58
59 public String getLastChangedDate() {
60 return getValueOf("Class/lastchangeddate");
61 }
62
63
64 public String getName() {
65 return getValueOf("Class/name");
66 }
67
68
69 public String getMenusArray() {
70 return ft.getMenus();
71 }
72
73
74 public String getPriority() {
75 return getValueOf("Class/priority");
76 }
77
78
79 public String getRulesArray() throws InstantbankException {
80 XMLNode node;
81 NodeList nodeList;
82 PrintWriter pw;
83 Element root;
84 String rules;
85 StringWriter sw;
86 String varArrays = "";
87
88 try {
89 root = doc.getDocumentElement();
90 nodeList = root.getChildNodes();
91 for(int i = 0; i < nodeList.getLength(); i++) {
92 node = (XMLNode)nodeList.item(i);
93 if(node.getNodeName().equals("RulesList")) {
94 sw = new StringWriter();
95 pw = new PrintWriter(sw);
96 node.print(pw);
97 rules = XMLUtils.xmlHeader();
98 rules += sw.toString();
99 varArrays += ft.getRulesArray(rules);
100 }
101 }
102 }
103 catch(Exception e) {
104 varArrays += "/* Exception: " + e.getClass().getName() + " " + e.getMessage() + " */";
105 }
106 return varArrays;
107 }
108
109
110 public String getStartDate() {
111 return getValueOf("Class/startdate");
112 }
113
114
115 public String getStatus() {
116 return getValueOf("Class/status");
117 }
118
119
120 private String getValueOf(String nodeName) {
121 try {
122 return doc.valueOf(nodeName);
123 }
124 catch(Exception e) {
125 return "";
126 }
127 }
128
129
130 public void setData(String xml) throws XMLParseException, XSLException, SAXException, IOException {
131 DOMParser docParser = new DOMParser();
132 ByteArrayInputStream stream = null;
133
134 stream = new ByteArrayInputStream(xml.getBytes());
135 docParser.setValidationMode(false);
136 docParser.parse(stream);
137 doc = docParser.getDocument();
138 }
139 }
140
141