Observation[] valori;
String[] selName;
int[] selType;
double[] valLst;
int numObs, numVar, i, j, id;
MatrixOsservazioni m = null;
VariableMapping[] map;
DOMParser domP;
NodeList tmpNodeLst, resNodeList = null;
Node tmpNode;
String tmpVal;
String curType;
DataInputStream dis;
//Extracting zipped files in temp dir
updateInfos(1, "Reading XML file", false);
//System.out.println("Entry " + file+JwatSession.XMLext);
//load xml file
domP = new DOMParser();
domP.parse(new InputSource(zis));
Document doc = domP.getDocument();
//parse variables
tmpNodeLst = doc.getElementsByTagName(JwatSession.ROOT);
curType = tmpNodeLst.item(0).getAttributes().getNamedItem("type").getNodeValue();
if (JwatSession.WORKLOAD_SAVE.equals(curType)) {
res = new WorkloadResultLoader();
} else {
if (JwatSession.TRAFFIC_SAVE.equals(curType)) {
res = new WorkloadResultLoader();
}
}
tmpNodeLst = doc.getElementsByTagName("Variables");
tmpNode = tmpNodeLst.item(0);
tmpVal = tmpNode.getAttributes().getNamedItem("num").getNodeValue();
numVar = Integer.parseInt(tmpVal);
selName = new String[numVar];
selType = new int[numVar];
tmpNodeLst = tmpNode.getChildNodes();
//System.out.println(tmpNodeLst.getLength());
j = 0;
updateInfos(2, "Reading Variables", false);
for (i = 0; i < tmpNodeLst.getLength(); i++) {
tmpNode = tmpNodeLst.item(i);
//System.out.println("VARIABLES:");
if (tmpNode.getNodeType() == Node.ELEMENT_NODE) {
tmpVal = tmpNode.getAttributes().getNamedItem("name").getNodeValue();
//System.out.println("NOME " + tmpVal);
selName[j] = tmpVal;
tmpVal = tmpNode.getAttributes().getNamedItem("type").getNodeValue();
//System.out.println("TIPO " + tmpVal);
selType[j] = Integer.parseInt(tmpVal);
j++;
}
}
//parse data
updateInfos(3, "Reading Data", false);
tmpNodeLst = doc.getElementsByTagName("Data");
tmpNode = tmpNodeLst.item(0);
tmpVal = tmpNode.getAttributes().getNamedItem("size").getNodeValue();
numObs = Integer.parseInt(tmpVal);
file = tmpNode.getAttributes().getNamedItem("filename").getNodeValue();
resNodeList = doc.getElementsByTagName("Results");
valori = new Observation[numObs];
map = new VariableMapping[numVar];
valLst = new double[numVar];
//System.out.println("Reading varaibles mapping");
updateInfos(3, "Reading Mapping", false);
for (j = 0; j < numVar; j++) {
if (selType[j] == JWATConstants.DATE) {
map[j] = new DataMapping();
}
if (selType[j] == JWATConstants.NUMERIC) {
map[j] = null;
}
if (selType[j] == JWATConstants.STRING) {
map[j] = loadVarMapping(zf, selName[j]);
//System.out.println(selName[j] + " " + selType[j]);
}
}
//load data file
zis = zf.getInputStream(new ZipEntry(file));
//System.out.println("Entry " + file);
dis = new DataInputStream(zis);
for (i = 0; i < numObs; i++) {
id = dis.readInt();
for (j = 0; j < numVar; j++) {
valLst[j] = dis.readDouble();
}
valori[i] = new Observation(valLst, id);
}
//System.out.println("Create matrix");
updateInfos(5, "Create matrix", false);
m = new MatrixOsservazioni(valori, selName, selType, map);
session.getDataModel().setMatrix(m);
return resNodeList;
}