}
private void load(InputStream is) throws LoadException {
if (is == null) {
throw new LoadException("File not Found");
}
InputSource inputSource = new InputSource(is);
//create a parser
DOMParser parser = new DOMParser();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
try {
// turn on schema validation ( note need to set both sax and dom validation )
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
//NEW
//TODO: setto lo schema xsd con cui fare il parsing
String externalSchemaLocation = XSDSchemaLoader.loadSchema(XSDSchemaLoader.JSIM_MODEL_DEFINITION);
parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", externalSchemaLocation);
//end NEW
try {
//document parsing
parser.parse(inputSource);
} catch (FileNotFoundException e) {
throw new LoadException("Problems while parsing", e);
}
//get the w3c document
document = parser.getDocument();
if (DEBUG) {
System.out.println(" created document");
}
//gets root
Element root = document.getDocumentElement();
if (DEBUG) {
System.out.println("root = " + root.getAttribute("name"));
}
//recovers the name of the simulation & creates a getLog with the same
//name
if (root.getNodeName() == null) {
throw new LoadException("Problems loading");
} else if (!root.getNodeName().equalsIgnoreCase("sim")) {
throw new LoadException("Problems loading");
}
//OLD
//sim = new Simulation(root.getAttribute("name"), root.getAttribute("debug").equals("true"));
//NEW
//@author Stefano Omini
//default values
long seed = -1;
String simName = "";
if (root.hasAttribute("name")) {
simName = root.getAttribute("name");
}
//vraiable debug is no longer USED
if (root.getAttribute("seed") != "") {
seed = Long.parseLong(root.getAttribute("seed"));
}
if (simName.equalsIgnoreCase("")) {
//NEW
//@author Stefano Omini
//no name specified: uses current time as name
String datePattern = "yyyyMMdd_HHmmss";
SimpleDateFormat formatter = new SimpleDateFormat(datePattern);
Date today = new Date();
String todayString = formatter.format(today);
simName = "jSIM_" + todayString;
//OLD
//sim = new Simulation(seed, null, debug);
sim = new Simulation(seed, simName);
//end NEW
} else {
//OLD
//sim = new Simulation(seed, simName, debug);
sim = new Simulation(seed, simName);
}
sim.setXmlSimModelDefPath(simModelPath);
//end NEW
//-------------- SIM PARAMETERS -------------------//
//TODO: codice per fissare i sim parameters
// Create a class SimParameter, whose parameters will be shared by all
// dynamic data analyzer in order to compute confidence intervals.
// For example, number of batches, batch size, ecc..
//this constructor will use default values
SimParameters simParam = new SimParameters();
//TODO: qui dovrei mettere blocchi tipo if (has attribute("batch")) then set(..) ecc
//una volta aggiunti nello schema dell'xml, vanno letti e
//inseriti coi rispettivi metodi set
// {......}
//TODO: finita la parte con parsing e set degli attributi, si mette questo metodo
//(che per il momento si limita a settare i valori di default)
//sets the reference in sim object
sim.setSimParameters(simParam);
//gets the default value of maxsamples
//(max number of samples for each measure)
int maxSamples = simParam.getMaxSamples();
// Gets the timestamp value
simParam.setTimestampValue(Long.toString(System.currentTimeMillis()));
//-------------- end SIM PARAMETERS -------------------//
// NEW Bertoli Marco -- Read MAX Samples if specified
if (root.getAttribute("maxSamples") != "") {
maxSamples = Integer.parseInt(root.getAttribute("maxSamples"));
simParam.setMaxSamples(maxSamples);
}
// END
// NEW Bertoli Marco -- Disables condidence interval as stopping criteria
if (root.hasAttribute("disableStatisticStop")) {
simParam.setDisableStatisticStop(root.getAttribute("disableStatisticStop").equalsIgnoreCase(Boolean.TRUE.toString()));
}
//END
// MF08 0.7.4 Michael Fercu (Bertoli Marco) -- re-defines global logger attributes
// for the purpose of passing them to the Logger constructor
if (root.hasAttribute("logPath")) {
String temp_lp = root.getAttribute("logPath");
simParam.setLogPath(temp_lp);
}
if (root.hasAttribute("logDelimiter")) {
String temp_ld = root.getAttribute("logDelimiter");
simParam.setLogDelimiter(temp_ld);
}
if (root.hasAttribute("logDecimalSeparator")) {
String temp_ld = root.getAttribute("logDecimalSeparator");
simParam.setLogDecimalSeparator(temp_ld);
}
if (root.hasAttribute("logReplaceMode")) {
String temp_lr = root.getAttribute("logReplaceMode");
simParam.setLogReplaceMode(temp_lr);
}
if (root.hasAttribute("lastRunTime")) {
String temp_ltv = root.getAttribute("lastRunTime");
simParam.setTimestampValue(temp_ltv);
}
//END MF08
//FIXME read measure logging attributes here...
//Returns a NodeList of all the Elements with a given tag name in the order in which they
//are encountered in a preorder traversal of the Document tree.
NodeList nodeList = root.getElementsByTagName("node");
NodeList classList = root.getElementsByTagName("userClass");
NodeList measureList = root.getElementsByTagName("measure");
NodeList connectionList = root.getElementsByTagName("connection");
//class array creation
jobClasses = new JobClass[classList.getLength()];
for (int i = 0; i < classList.getLength(); i++) {
//OLD
//jobClasses[i] = new JobClass(((Element) classList.item(i)).getAttribute("name"));
//NEW
//@author Stefano Omini
Element currentJobClass = (Element) classList.item(i);
//parse class attributes: name, type and priority
String currentClassName = currentJobClass.getAttribute("name");
String currentClassType = currentJobClass.getAttribute("type");
String currentClassPriority = currentJobClass.getAttribute("priority");
String referenceNode = currentJobClass.getAttribute("referenceSource");
int type, priority;
if (currentClassType.equalsIgnoreCase("closed")) {
type = JobClass.CLOSED_CLASS;
//TODO: al momento non viene letto l'attributo opzionale "customers"
//(che comunque non � necessario: i job vengono creati dal terminal o precaricati
//nelle code)
} else {
type = JobClass.OPEN_CLASS;
}
priority = Integer.parseInt(currentClassPriority);
if (priority < 0) {
//negative priorities not allowed
priority = 0;
}
//add job class
jobClasses[i] = new JobClass(currentClassName, priority, type, referenceNode);
//end NEW
if (DEBUG) {
System.out.println("Class " + jobClasses[i].getName() + " created");
}
}
//inserts all JobClasses in the Simulation object
sim.addClasses(jobClasses);
if (DEBUG) {
System.out.println("classes added\n");
}
//creates the nodes from xml & adds them to the simulation object
for (int i = 0; i < nodeList.getLength(); i++) {
Element node = (Element) nodeList.item(i);
if (DEBUG) {
System.out.println("start creation of node = " + node.getAttribute("name"));
}
//gets list of sections
NodeList sectionList = node.getElementsByTagName("section");
NodeSection[] sections = new NodeSection[3];
//creates all sections (max is 3)
for (int j = 0; j < sectionList.getLength(); j++) {
if (DEBUG) {
System.out.println(" start creation of section = " + ((Element) sectionList.item(j)).getAttribute("className"));
}
NodeSection ns = createSection((Element) sectionList.item(j));
if (DEBUG) {
System.out.println(" finished creation of " + ((Element) sectionList.item(j)).getAttribute("className") + "\n");
}
if (ns instanceof InputSection) {
sections[0] = ns;
} else if (ns instanceof ServiceSection) {
sections[1] = ns;
} else if (ns instanceof OutputSection) {
sections[2] = ns;
} else {
throw new LoadException("trying to cast the wrong Class type");
}
}
//adds node.
sim.addNode(node.getAttribute("name"), (InputSection) sections[0], (ServiceSection) sections[1], (OutputSection) sections[2]);
if (DEBUG) {