Class SmilePersistanceDelegate

  • java.lang.Object
    • uk.ac.qmul.eecs.ccmi.examples.framework.SmilePersistanceDelegate


  • public class SmilePersistanceDelegate
    extends java.lang.Object

    Together with the Node and Edge prototypes, a persistence delegate must also be provided to make your own diagram within the CCmI Diagram Editor framework. A persistence delegate will take care of persisting the inner implementation of the prototypes and it should take care of information, such as the type of nodes and edges ( returned by DiagramElement.getType()), which are relevant to all the objects created from that prototype.

    The prototypes are those nodes and edges which are stored in the Graphic toolbar and which are used to create objects in the graph through clonation. As said, the delegate only takes care of the prototypes. On the contrary, you can persist additional data of each single node and edge in the graph by overriding encode and decode methods in Node and Edge; but make sure you call super, before saving your own data in these methods.

    Persisting prototypes is necessary if you have more than one node/edge type. In this example, where two node prototypes exist, decodeNodePrototype will be called once for each different node that has been previously persisted. It is therefore necessary to write down some information to distinguish between the two node types. One the contrary, since only one edge prototype exists, there is no need to persist any information for it, as decodeEdgePrototype can just return that unique edge type.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      Edge decodeEdgePrototype(org.w3c.dom.Element edgeTag)
      Returns an instance of SmileEdge, the only edge type available
      Node decodeNodePrototype(org.w3c.dom.Element nodeTag)
      Retrieves the smile node prototypes from the information saved in the XML file.
      void encodeEdgePrototype(org.w3c.dom.Document doc, org.w3c.dom.Element parent, Edge e)
      This is an empty method as only one edge type exists in the diagram and decodeEdgePrototype will return that only instance.
      void encodeNodePrototype(org.w3c.dom.Document doc, org.w3c.dom.Element parent, Node n)
      Saves the smile node prototype information into XML format.
      • Methods inherited from class java.lang.Object

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

      • SmilePersistanceDelegate

        public SmilePersistanceDelegate()
    • Method Detail

      • encodeNodePrototype

        public void encodeNodePrototype(org.w3c.dom.Document doc,
                                        org.w3c.dom.Element parent,
                                        Node n)
        Saves the smile node prototype information into XML format.
        Parameters:
        doc - the XML document n is going to be persisted in
        parent - the XML tag representing n
        n - the node to be persisted in the XML document
      • encodeEdgePrototype

        public void encodeEdgePrototype(org.w3c.dom.Document doc,
                                        org.w3c.dom.Element parent,
                                        Edge e)
        This is an empty method as only one edge type exists in the diagram and decodeEdgePrototype will return that only instance.
        See Also:
        decodeEdgePrototype(Element)
      • decodeNodePrototype

        public Node decodeNodePrototype(org.w3c.dom.Element nodeTag)
                                 throws java.io.IOException
        Retrieves the smile node prototypes from the information saved in the XML file.
        Parameters:
        nodeTag - the XML tag where information about the node to return is stored.
        Returns:
        a prototype node
        Throws:
        java.io.IOException
      • decodeEdgePrototype

        public Edge decodeEdgePrototype(org.w3c.dom.Element edgeTag)
                                 throws java.io.IOException
        Returns an instance of SmileEdge, the only edge type available
        Throws:
        java.io.IOException