Class XMLReader

java.lang.Object
common.xml.XMLReader
All Implemented Interfaces:
CommonConstants, EngineNodeConstants, XMLConstantNames

public class XMLReader extends Object implements XMLConstantNames, CommonConstants

Title: XML Reader

Description: Reads model information from an XML file. This class provides methods for model load.

Author:
Bertoli Marco Date: 27-lug-2005 Time: 13.59.48
  • Field Details

  • Constructor Details

    • XMLReader

      public XMLReader()
  • Method Details

    • loadModel

      public static boolean loadModel(String fileName, CommonModel model)
      Loads a model saved in an XML file, given the name of the file. If specified file is a jmodel archive, extracts model informations from it and uses them to reconstruct the model. This method is provided to be used with JSIM
      Parameters:
      fileName - name of the file to be opened
      model - data structure where model should be created (a new data structure is the best choice)
      Returns:
      true iff model was recognized and loaded, false otherwise
    • loadModel

      public static boolean loadModel(File xmlFile, CommonModel model)
      Loads a model saved in an XML file, given the handler to the file. If specified file is a jmodel archive, extracts model informations from it and uses them to reconstruct the model. This method is provided to be used with JSIM
      Parameters:
      xmlFile - handler to the file to be opened
      model - data structure where model should be created (a new data structure is the best choice)
      Returns:
      true iff model was recognized and loaded, false otherwise
    • parseXML

      public static void parseXML(Element root, CommonModel model)
      Parses given XML Document to reconstruct simulation model.
      Parameters:
      root - root of document to be parsed
      model - data model to be elaborated
    • parseXML

      public static void parseXML(Document xml, CommonModel model)
      Parses given XML Document to reconstruct simulation model.
      Parameters:
      xml - Document to be parsed
      model - data model to be elaborated
    • findText

      protected static String findText(Node elem)
      Helper method that searches for first text node, between all children of current node and returns its value. (This is needed to garbage out all comments)
      Parameters:
      elem - root node to begin search
      Returns:
      parsed text if found, otherwise null
    • parseClasses

      protected static void parseClasses(Element root, CommonModel model)
      Parses userclasses information. Note that distributions for open class will be set lately and reference station information is stored into refStations data structure as will be used later
      Parameters:
      root - root element of XML Document
      model - data structure where all properties have to be set
    • parseStations

      protected static void parseStations(Element root, CommonModel model)
      Parses all station related informations and puts them into data structure
      Parameters:
      root - root element of XML Document
      model - data structure where all properties have to be set
    • parseClassStationSoftDeadlines

      protected static void parseClassStationSoftDeadlines(NodeList classSoftDeadlines, CommonModel model, Object key)
    • parseQuantaSize

      protected static void parseQuantaSize(NodeList quantaSize, CommonModel model, Object key)
    • parseQuantumSwitchoverTime

      protected static void parseQuantumSwitchoverTime(NodeList quantumSwitchoverTime, CommonModel model, Object key)
    • parseSourceSection

      protected static void parseSourceSection(Element section, CommonModel model, Object key, String stationName)
      Parses all informations regarding Source section. If this source is reference class for any kind of open class, uses service time informations stored here to set distribution for this class.
      Parameters:
      section - input section of source station
      model - link to data structure
      key - key of search for this source station into data structure
      stationName - Name of current station. This is used to correctly set reference station distribution. That cannot be derived from model.getStationName(key) as JSim can change source name upon opening a model stored with JModel.
    • parseQueueSection

      protected static void parseQueueSection(Element section, CommonModel model, Object key)
      Parses all informations regarding Queue section.
      Parameters:
      section - input section of queue or delay station
      model - link to data structure
      key - key of search for this queue or delay station into data structure
    • parseQueueSectionDelay

      protected static void parseQueueSectionDelay(Element section, CommonModel model, Object key)
      Parses all information regarding enabling, inhibiting and resource conditions for a delay station
      Parameters:
      section - input section of delay station
      model - link to data structure
      key - key of search for this delay station into data structure
    • parseDelaySection

      protected static void parseDelaySection(Element section, CommonModel model, Object key)
      Parses all informations regarding Delay section.
      Parameters:
      section - service section of delay station
      model - link to data structure
      key - key of search for this delay station into data structure
    • parseServerSection

      protected static void parseServerSection(Element section, CommonModel model, Object key)
      Parses all informations regarding Server section.
      Parameters:
      section - service section of queue station
      model - link to data structure
      key - key of search for this queue station into data structure
    • parseParameterRefclassArray

      protected static Map<String,Node> parseParameterRefclassArray(Element parameterNode)
      Parses a Parameter array and returns a Map of ClassName -> subParameter
      Parameters:
      parameterNode -
      Returns:
      a Map of ClassName -> subParameter
    • parseParameterArray

      protected static Vector<Node> parseParameterArray(Element parameterNode)
      Parses a parameter array and returns Vector of found subParameters
      Parameters:
      parameterNode -
      Returns:
      Vector with found subParameters
    • parseRouterSection

      protected static void parseRouterSection(Element section, CommonModel model, Object key)
      Parses router section
      Parameters:
      section - router section
      model - data structure
      key - station's key
    • parseClassSwitchSection

      protected static void parseClassSwitchSection(Element section, CommonModel model, Object stationKey)
      Parses class switch section
      Parameters:
      section - class switch section
      model - data structure
      stationKey - station's key
    • parseLoggerSection

      protected static void parseLoggerSection(Element section, CommonModel model, Object key)
      Parses all parameters for a Logger section from the XML document. The information from parseLogger is passed to LogTunnel.
      Parameters:
      section - service section of logger station
      model - link to data structure
      key - key of search for this logger station into data structure
      See Also:
    • parseForkSection

      protected static void parseForkSection(Element section, CommonModel model, Object key)
      Parses all informations regarding Fork section.
      Parameters:
      section - output section of fork station
      model - link to data structure
      key - key of search for this fork station into data structure
    • parseJoinSection

      protected static void parseJoinSection(Element section, CommonModel model, Object key)
      Parses all informations regarding Join section.
      Parameters:
      section - input section of join station
      model - link to data structure
      key - key of search for this join station into data structure
    • parseSemaphoreSection

      protected static void parseSemaphoreSection(Element section, CommonModel model, Object key)
      Parses all informations regarding Semaphore section.
      Parameters:
      section - input section of semaphore station
      model - link to data structure
      key - key of search for this semaphore station into data structure
    • parseStorageSection

      protected static void parseStorageSection(Element section, CommonModel model, Object key)
      Parses all informations regarding Storage section.
      Parameters:
      section - input section of place station
      model - link to data structure
      key - key of search for this place station into data structure
    • parseEnablingSection

      protected static void parseEnablingSection(Element section, CommonModel model, Object key)
      Parses all informations regarding Enabling section.
      Parameters:
      section - input section of transition station
      model - link to data structure
      key - key of search for this transition station into data structure
    • parseTimingSection

      protected static void parseTimingSection(Element section, CommonModel model, Object key)
      Parses all informations regarding Timing section.
      Parameters:
      section - service section of transition station
      model - link to data structure
      key - key of search for this transition station into data structure
    • parseFiringSection

      protected static void parseFiringSection(Element section, CommonModel model, Object key)
      Parses all informations regarding Firing section.
      Parameters:
      section - output section of transition station
      model - link to data structure
      key - key of search for this transition station into data structure
    • parseServiceStrategy

      protected static Object parseServiceStrategy(Element serviceTimeStrategy)
      Parses service section informations contained in serviceTimeStrategy element to create a correct Distribution or LDStrategy object
      Parameters:
      serviceTimeStrategy - Element that holds all distribution informations
      Returns:
      created Distribution or LDStrategy or null if this field is set to null
    • parseDistribution

      protected static Distribution parseDistribution(Element distr, Element distrPar)
      Parses a distribution, given its distribution and distributionPar nodes
      Parameters:
      distr - distribution node
      distrPar - distribution's parameter node
      Returns:
      parsed distribution
    • getStationType

      protected static String getStationType(Element station)
      Returns the type of a station, reconstructing it from section names. This method must be modified if a new station type is inserted.
      Parameters:
      station - element containing sections
      Returns:
      station type as expected by CommonModel / JMODELModel
    • parseMeasures

      protected static void parseMeasures(Element root, CommonModel model)
      Parses all informations on measures to be taken during simulation
      Parameters:
      root - root element of XML Document
      model - data structure where all properties have to be set
    • parseConnections

      protected static void parseConnections(Element root, CommonModel model)
      Parses all informations on connections to be made into model
      Parameters:
      root - root element of XML Document
      model - data structure where all properties have to be set
    • parsePreloading

      protected static void parsePreloading(Element root, CommonModel model)
      Parses all informations on preloading to be added to the model
      Parameters:
      root - root element of XML Document
      model - data structure where all properties have to be set
    • parseBlockingRegions

      protected static void parseBlockingRegions(Element root, CommonModel model)
      Parses all informations on blocking regions to be added to the model
      Parameters:
      root - root element of XML Document
      model - data structure where all properties have to be set
    • loadXML

      public static Document loadXML(String filename, String schemaSource)
      Loads an XML file, returning the Document representation of it. This method is generic and can be used to load every xml file. Actually it is used by XMLReader and by GuiXMLReader. This method will validate input file.
      Parameters:
      filename - name of the file to be loaded
      schemaSource - url of schema to be used to validate the model
      Returns:
      Document representation of input xml file
    • loadXML

      public static Document loadXML(String filename)
      Loads an XML file, returning the Document representation of it. This method is generic and can be used to load every xml file. Actually it is used by XMLReader and by GuiXMLReader. This method will not validate input file.
      Parameters:
      filename - name of the file to be loaded
      Returns:
      Document representation of input xml file
    • write

      protected static void write(Node node)
      This method is used for debug purpose to write a portion of xml on standard output. This can be removed freely!
      Parameters:
      node - node to be written on standard output
    • normalizeClassPath

      protected static String normalizeClassPath(String cp)
      Strips legacy "jmt.engine." or "jmt.gui." prefix for backwards-compatible classPath matching.