-
Notifications
You must be signed in to change notification settings - Fork 0
/
AWTParser.java
134 lines (103 loc) · 4.57 KB
/
AWTParser.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package cyclients.psIterator;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
public class AWTParser {
// Save the parent information <booleanFactor booleanFactorType="attrOpConst">
static HashMap<String,String> booleanFactorInfo = new HashMap<String,String>();
/* Save the child Information | Get value by booleanFactorTypechildInfo.get(0);
* <dbAttr dbAttrName="Salary" dbAttrType="integer" dbRelAliasName="e" dbRelName="Emp" />
<comparisonOp opType=">" />
<dbConstValue constType="integer" constValue="70000" />
*
*/
static ArrayList<HashMap<String,String>> booleanFactorTypechildInfo = new ArrayList<HashMap<String,String>>();
/*
* Function used To parse the AWT-XML
*/
public static ArrayList<HashMap<String,String>> parseAWT(String Path) throws SAXException, IOException, ParserConfigurationException{
// path = "Path Of AWT-XML"
File inputFile = new File(Path);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder;
dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(inputFile);
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("booleanFactor");
if (nList.getLength() > 0){
for (int i=0; i<nList.getLength(); i++){
Node n1 = nList.item(i);
if (n1.getNodeType() == Node.ELEMENT_NODE)
{
booleanFactorInfo.put("booleanFactorType",n1.getAttributes().getNamedItem("booleanFactorType").getNodeValue());
NodeList childNode = n1.getChildNodes();
HashMap<String,String> temp = new HashMap<String,String>();
for(int j = 0;j<childNode.getLength();j++){
if(childNode.item(j).getNodeType() == Node.ELEMENT_NODE){
if(childNode.item(j).getNodeName().equals("dbAttr")){
temp.put("dbAttrName", childNode.item(j).getAttributes().getNamedItem("dbAttrName").getNodeValue());
temp.put("dbAttrType", childNode.item(j).getAttributes().getNamedItem("dbAttrType").getNodeValue());
temp.put("dbRelAliasName", childNode.item(j).getAttributes().getNamedItem("dbRelAliasName").getNodeValue());
temp.put("dbRelName", childNode.item(j).getAttributes().getNamedItem("dbRelName").getNodeValue());
}
else if(childNode.item(j).getNodeName().equals("comparisonOp")){
temp.put("opType", childNode.item(j).getAttributes().getNamedItem("opType").getNodeValue());
}
else if(childNode.item(j).getNodeName().equals("dbConstValue")){
temp.put("constType", childNode.item(j).getAttributes().getNamedItem("constType").getNodeValue());
temp.put("constValue", childNode.item(j).getAttributes().getNamedItem("constValue").getNodeValue());
}
}
}
// System.out.println(temp.keySet());
booleanFactorTypechildInfo.add(temp);
}
}
}
return booleanFactorTypechildInfo;
}
/*
* Function Used To Print Xml
*/
public static void printAWT(){
String s = "booleanFactorType";
String boolFactorType = booleanFactorInfo.get(s);
// System.out.println("booleanFactorType ----:"+boolFactorType);
/*
* Map contains all the child attributes information
*
*/
HashMap<String,String> childinfo =booleanFactorTypechildInfo.get(0);
String s0 =childinfo.get("dbAttrName");
System.out.println("dbAttrName :"+s0);
String s1 = childinfo.get("dbAttrType");
System.out.println("dbAttrType :"+s1);
String s2 = childinfo.get("dbRelAliasName");
System.out.println("dbRelAliasName :"+s2);
String s3 = childinfo.get("dbRelName");
System.out.println("dbRelName :"+s3);
String s4 = childinfo.get("opType");
System.out.println("opType :"+s4);
String s5 = childinfo.get("constType");
System.out.println("constType :"+s5);
String s6 = childinfo.get("constValue");
System.out.println("constValue :"+s6);
}
/*
* To Test
*
*/
public static void main(String[] args){
try{
parseAWT("AST.xml");
printAWT();
}
catch(Exception e){
}
}
}