Class SmilePersistanceDelegate
- java.lang.Object
-
- uk.ac.qmul.eecs.ccmi.examples.framework.SmilePersistanceDelegate
-
public class SmilePersistanceDelegate extends java.lang.Object
Together with the
Node
andEdge
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 byDiagramElement.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
anddecode
methods inNode
andEdge
; but make sure you callsuper
, 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, asdecodeEdgePrototype
can just return that unique edge type.
-
-
Constructor Summary
Constructors Constructor and Description SmilePersistanceDelegate()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description Edge
decodeEdgePrototype(org.w3c.dom.Element edgeTag)
Returns an instance ofSmileEdge
, the only edge type availableNode
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 anddecodeEdgePrototype
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.
-
-
-
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 documentn
is going to be persisted inparent
- the XML tag representingn
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 anddecodeEdgePrototype
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 ofSmileEdge
, the only edge type available- Throws:
java.io.IOException
-
-