-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXmlReader.java
More file actions
130 lines (114 loc) · 4.59 KB
/
Copy pathXmlReader.java
File metadata and controls
130 lines (114 loc) · 4.59 KB
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
package ToArrayExcel;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.File;
import java.util.ArrayList;
/**
*
* @author Administrator
*/
public class XmlReader {
private String saveFile;
private File file;
private DocumentBuilder docBuilder;
private Document doc;
public String nssPath;
public ArrayList<ThroughputArraySet> throughputSet;
public ArrayList<TrustArraySet> trustSet;
public ArrayList<ParentArraySet> parentSet;
public XmlReader(String saveFile) {
try {
this.saveFile = saveFile;
nssPath = null;
throughputSet = null;
trustSet = null;
parentSet = null;
file = new File(saveFile);
docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
doc = docBuilder.parse(file);
this.parse();
} catch (Exception e) {
e.printStackTrace();
}
}
public void parse() {
parseNssPath();
parseThroughput();
parseParent();
parseTrust();
}
private void parseNssPath() {
nssPath = new String();
NodeList rowList = doc.getDocumentElement().getElementsByTagName("nss");
if (rowList.getLength() == 1) {
Element e = (Element)rowList.item(0);
nssPath = e.getAttribute("path");
} else {
nssPath = null;
}
}
private void parseParent(){
parentSet = new ArrayList<ParentArraySet>();
NodeList rowList = doc.getDocumentElement().getElementsByTagName("parent");
if (rowList.getLength() > 0) {
for (int i = 0; i < rowList.getLength(); i++) {
Element e = (Element)rowList.item(i);
int transaction = Integer.parseInt(e.getAttribute("transaction"));
int source = Integer.parseInt(e.getAttribute("source"));
int target = Integer.parseInt(e.getAttribute("target"));
ParentArraySet pas = null;
if(!parentSet.isEmpty()){
pas = parentSet.get(parentSet.size() - 1);
if(pas.isNewTransaction(transaction)){
pas = new ParentArraySet(transaction);
parentSet.add(pas);
}
} else {
pas = new ParentArraySet(transaction);
parentSet.add(pas);
}
if(pas.isSameTransaction(transaction) && !pas.isRouteExist(source, target)){
pas.add(source, target);
}
}
}
else parentSet = null;
}
private void parseThroughput() {
NodeList rowList = doc.getDocumentElement().getElementsByTagName("throughput");
if (rowList.getLength() > 0) {
throughputSet = new ArrayList<ThroughputArraySet>();
for (int i = 0; i < rowList.getLength(); i++) {
Element e = (Element)rowList.item(i);
ThroughputArraySet tas = new ThroughputArraySet();
tas.add(Integer.parseInt(e.getAttribute("transaction")), Float.parseFloat(e.getAttribute("value")));
throughputSet.add(tas);
}
}
else throughputSet = null;
}
private void parseTrust() {
NodeList rowList = doc.getDocumentElement().getElementsByTagName("trust");
if (rowList.getLength() > 0) {
trustSet = new ArrayList<TrustArraySet>();
for (int i = 0; i < rowList.getLength(); i++) {
Element e = (Element)rowList.item(i);
TrustArraySet tas = new TrustArraySet(Integer.parseInt(e.getAttribute("source")), Integer.parseInt(e.getAttribute("target")));
int transaction = Integer.parseInt(e.getAttribute("transaction"));
long time = Integer.parseInt(e.getAttribute("time"));
float trustFP = Float.parseFloat(e.getAttribute("trustFP"));
// float trustLP = Float.parseFloat(e.getAttribute("trustLP"));
float trustPR = Float.parseFloat(e.getAttribute("trustPR"));
float overall = Float.parseFloat(e.getAttribute("overall"));
// tas.addTrustValues(transaction, time, trustFP, trustRH, trustAV, trustLP, trustPR, overall);
tas.addTrustValues(transaction, time, trustFP, /*trustLP,*/ trustPR, overall);
trustSet.add(tas);
}
}
else trustSet = null;
}
}