Package jmt.common.exception

Examples of jmt.common.exception.LoadException


        //using its name)
        //nodes[i] = NetSystem.getNode(nodeNames[i]);
        //end OLD

      } else {
        throw new LoadException("Name of the node is not a String");
      }
    }

  }
View Full Code Here


        nodeNames[i] = nodeName;

        //sets the corresponding routing probability
        probabilities[i] = entry.getProbability();
      } else {
        throw new LoadException("Name of the node is not a String");
      }
    }

    //uses the obtained probabilities to create the empirical distribution
    //and its parameter
View Full Code Here

   */
  public void addConnection(String start, String end) throws LoadException {
    if (isNode(start) && isNode(end)) {
      connections.add(new Connection(start, end));
    } else {
      throw new LoadException("Trying to connect nodes that haven't been inserted yet.");
    }
  }
View Full Code Here

      throws LoadException {
    if (true) {
      //TODO: andrebbero aggiunti controlli (nome non univoco, jobs<0, ecc...)
      regions.add(new BlockingRegion(name, maxCapacity, maxCapacityPerClass, classWeights, drop, this, stations));
    } else {
      throw new LoadException("Exception while creating a blocking region.");
    }
  }
View Full Code Here

    for (int i = 0; i < nodes.size(); i++) {
      if ((nodes.get(i)).getNode().getName().equals(name)) {
        return i;
      }
    }
    throw new LoadException("node not found");
  }
View Full Code Here

      this.measureType = measureType;
      this.measure = measure;
      this.measure.measureTarget(nodeName, jClass, measureType);
      this.nodeName = nodeName;
      if (this.nodeName == null) {
        throw new LoadException("Trying to add a measure to a not-existent node.");
      }
    }
View Full Code Here

      try {
        //document parsing
        parser.parse(inputSource);
      } catch (FileNotFoundException e) {
        throw new LoadException("Problems parsing", e);
      }

      //get the w3c document
      document = parser.getDocument();
View Full Code Here

  }

  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) {
View Full Code Here

        }
        //creates the Section with the constructor
        return (NodeSection) constr.newInstance(initargs);
      }
    } catch (ClassNotFoundException e) {
      throw new LoadException("Class of Section Not found", e);
    } catch (InstantiationException e) {
      throw new LoadException("Class of Section cannot be istantiated", e);
    } catch (IllegalAccessException e) {
      throw new LoadException("Class of Section illegal access", e);
    } catch (NoSuchMethodException e) {
      throw new LoadException("Constructor of Section not found", e);
    } catch (InvocationTargetException e) {
      throw new LoadException("problems with Section constructor", e);
    }
  }
View Full Code Here

   * @param param
   * @throws jmt.common.exception.LoadException
   */
  private Object createParameter(Element param) throws LoadException {
    if (!param.getTagName().equals("parameter")) {
      throw new LoadException("trying to use createParameter on a : " + param.getTagName());
    }
    try {
      if (DEBUG) {
        System.out.println("        start creation of parameter = " + param.getAttribute("name"));
      }
      //gets Class Object for the parameter
      String classPath = param.getAttribute("classPath");
      NodeList valueList = XMLParser.getElementsByTagName(param, "value");
      //if value == null the object is a null pointer
      if (valueList.getLength() > 0 && valueList.item(0).getChildNodes().item(0).getNodeValue().equals("null")) {
        if (DEBUG) {
          System.out.println("        parameter null");
        }
        return null;
      }
      Class<?> c = Class.forName(classPath);
      if (DEBUG) {
        System.out.println("        parameter  class found = " + classPath);
      }
      //parameter is an array;
      if (param.getAttribute("array").equals("true")) {
        if (DEBUG) {
          System.out.println("        parameter is an array");
        }
        //check if there are child nodes in the array
        if (!param.hasChildNodes()) {
          if (DEBUG) {
            System.out.println("        creates 0 size array");
          }
          return Array.newInstance(c, 0);//return a 0 element array
        }
        //there are 2 situations: the parameter is an array or a group of subparameters defined per class

        //first situation: just an array without classes
        Object[] arrayElements;
        if (XMLParser.getElementsByTagName(param, "refClass").getLength() == 0) {
          //gets list of first level subParameters
          NodeList childList = XMLParser.getElementsByTagName(param, "subParameter");
          //creates an array of the appropriate length
          arrayElements = new Object[childList.getLength()];
          if (DEBUG) {
            System.out.println("        instance a simple array of size " + arrayElements.length);
          }
          //creates all the elements of the array
          for (int i = 0; i < arrayElements.length; i++) {
            if (DEBUG) {
              System.out.println("creating subparemter = " + ((Element) childList.item(i)).getAttribute("name"));
            }
            arrayElements[i] = createSubParameter((Element) childList.item(i));
          }
          //creates a fake array object
          Object parameter = Array.newInstance(c, childList.getLength());
          //copy inside all the elements
          System.arraycopy(arrayElements, 0, parameter, 0, arrayElements.length);
          if (DEBUG) {
            System.out.println("        created parameter");
          }
          return parameter;

        } else {

          //it's a group parameter! more complicated(the other was easy... :P )
          if (DEBUG) {
            System.out.println("        it's group class parameter");
          }
          //creates an array of Object that has enough element to store
          //subParametes for each class.
          arrayElements = new Object[jobClasses.length];
          NodeList chiList = param.getChildNodes();
          ArrayList<String> classVect = new ArrayList<String>();
          //iterates over the childList, it's like this, it has a list (optional)of classRef
          //followed by a subParameter
          for (int i = 0; i < chiList.getLength(); i++) {
            Node n = chiList.item(i);
            if (n.getNodeType() == 1) {
              //if gets a class it add to list of classes
              if (n.getNodeName().equals("refClass")) {
                classVect.add(n.getFirstChild().getNodeValue());
                if (DEBUG) {
                  System.out.println("        found class " + n.getFirstChild().getNodeValue());
                }
              } else {
                //gets the position of classes
                int[] positions = new int[classVect.size()];
                for (int j = 0; j < positions.length; j++) {
                  positions[j] = findClassPosition(classVect.get(j));
                }
                //gets the subparameter
                for (int j = 0; j < positions.length; j++) {
                  if (DEBUG) {
                    System.out.println("        creating subParameter " + ((Element) n).getAttribute("name") + " for class "
                        + classVect.get(j));
                  }
                  arrayElements[positions[j]] = createSubParameter((Element) n);
                }
                //clears the classes vector
                classVect.clear();
              }
            }
          }
          //creates a fake array object
          Object parameter = Array.newInstance(c, jobClasses.length);
          //copy inside all the elements
          System.arraycopy(arrayElements, 0, parameter, 0, arrayElements.length);
          if (DEBUG) {
            System.out.println("        created parameter");
          }
          return parameter;
        }
      }
      //check for default constructor
      if (!param.hasChildNodes()) {
        if (DEBUG) {
          System.out.println("       created with default constructor");
        }
        return c.newInstance();
      }

      //check if it's a leaf node (it has a value & not subparameters)
      if (valueList != null) {

        String value = valueList.item(0).getFirstChild().getNodeValue();
        if (DEBUG) {
          System.out.println("        parameter is a leaf node, value = " + value);
        }
        //needs to get the String constructor
        Object[] initargs = { value };
        Class<?>[] paramterTypes = { initargs[0].getClass() };
        Constructor<?> constr = getConstructor(c, paramterTypes);
        if (DEBUG) {
          System.out.println("        created parameter");
        }
        return constr.newInstance(initargs);
      } else {
        //leaf node but has subparameters
        NodeList childList = XMLParser.getElementsByTagName(param, "subParameter");
        Object[] initargs = new Object[childList.getLength()];
        if (DEBUG) {
          System.out.println("        parameter is a leaf node with subparameter ");
        }
        Class<?>[] paramClasses = new Class[childList.getLength()];
        //creates iteratevely all the subparamters
        for (int i = 0; i < childList.getLength(); i++) {
          Element e = (Element) childList.item(i);
          if (DEBUG) {
            System.out.println("            creates subparameter = " + e.getAttribute("name"));
          }
          initargs[i] = createSubParameter(e);
          paramClasses[i] = initargs[i].getClass();
        }
        Constructor<?> constr = getConstructor(c, paramClasses);
        return constr.newInstance(initargs);
      }

    } catch (ClassNotFoundException e) {
      throw new LoadException("Class of Parameter not found", e);
    } catch (NoSuchMethodException e) {
      throw new LoadException("there is not a String Constructor", e);
    } catch (InstantiationException e) {
      throw new LoadException("Class of parameter cannot be instantiated", e);
    } catch (IllegalAccessException e) {
      throw new LoadException("Class of parameter cannot be instantiated", e);
    } catch (InvocationTargetException e) {
      throw new LoadException("Class of parameter cannot be instantiated", e);
    }
  }
View Full Code Here

TOP

Related Classes of jmt.common.exception.LoadException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.