Class XmlConnector

  • All Implemented Interfaces:
    StorageConnector

    public class XmlConnector
    extends java.lang.Object
    implements StorageConnector
    This class implements a StorageConnector for XML-file-based storages.
    Author:
    Kapeluch, El-Sharkawy
    • Constructor Summary

      Constructors 
      Constructor Description
      XmlConnector​(java.lang.String xmlFilePath, PathEnvironment pathEnv)
      Sole constructor for this class.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void appendAttribute​(java.lang.StringBuffer xml, java.util.Map.Entry<java.lang.String,​java.lang.String> attr)
      Appends a given attribute to an existing xml String.
      private void createEntities​(org.w3c.dom.Node node, Model model)
      Parsed the xml structure, created Entitys and adds them to the given Model.
      private org.w3c.dom.Document createXMLDocument()
      Creates an object model for the xml document, which should be parsed.
      PathEnvironment getPathEnvironment()
      Returns the path environment used for making paths relative.
      java.lang.String getProjectID()
      Returns the UUID of a given pl project.
      private java.lang.String getXmlFromEntity​(Entity entity, java.lang.String indent)
      Returns xml-formatted string from given entity.
      void loadModels​(Model... models)
      Loads the specified models.
      void loadModels​(PersistentProject project)
      Method for loading models out of a persistent file/database.
      void saveModels​(PersistentProject project)
      Saves data from given model to storage.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • xmlFilePath

        private java.lang.String xmlFilePath
    • Constructor Detail

      • XmlConnector

        public XmlConnector​(java.lang.String xmlFilePath,
                            PathEnvironment pathEnv)
        Sole constructor for this class.
        Parameters:
        xmlFilePath - The absolute path for retrieving the xml configuration file.
        pathEnv - a path environment for making files and paths relative
    • Method Detail

      • loadModels

        public void loadModels​(PersistentProject project)
                        throws PersistenceException
        Description copied from interface: StorageConnector
        Method for loading models out of a persistent file/database.
        Specified by:
        loadModels in interface StorageConnector
        Parameters:
        project - A PersistentProject holding an empty array of Models for storing the information read in a persistent file/database. These models must only contain the correct ModelTypes, for managing which parts should be loaded.
        Throws:
        PersistenceException - Will be thrown if an error is occurred during reading the persistent information.
      • createXMLDocument

        private org.w3c.dom.Document createXMLDocument()
                                                throws PersistenceException
        Creates an object model for the xml document, which should be parsed.
        Returns:
        A new DOM Document object.
        Throws:
        PersistenceException - If an error occurred while parsing the xml document.
      • createEntities

        private void createEntities​(org.w3c.dom.Node node,
                                    Model model)
        Parsed the xml structure, created Entitys and adds them to the given Model.
        Parameters:
        node - the node within the current xml document representing the given model.
        model - The model related to the given node for saving the read entities.
        Since:
        14.09.2011
      • getXmlFromEntity

        private java.lang.String getXmlFromEntity​(Entity entity,
                                                  java.lang.String indent)
        Returns xml-formatted string from given entity.
        Parameters:
        entity - The entity to generate xml-code from
        indent - The indent of the current level
        Returns:
        XML-string
        Since:
        22.09.2011
      • appendAttribute

        private void appendAttribute​(java.lang.StringBuffer xml,
                                     java.util.Map.Entry<java.lang.String,​java.lang.String> attr)
        Appends a given attribute to an existing xml String.
        Parameters:
        xml - The xml string, which should be extended
        attr - The attribute, which should be inserted into the xml string.
      • getProjectID

        public java.lang.String getProjectID()
        Description copied from interface: StorageConnector
        Returns the UUID of a given pl project.
        Specified by:
        getProjectID in interface StorageConnector
        Returns:
        the id or null if the specified project has no configuration file.