y.io
Class YGFIOHandler

java.lang.Object
  extended by y.io.IOHandler
      extended by y.io.YGFIOHandler

public class YGFIOHandler
extends IOHandler

Reading and Writing graphs in Y Graph Format (YGF).

 
Your browser does not support SVG content.

Nested Class Summary
static interface YGFIOHandler.DataHandler
          Implementations of this interface can be added to this IOHandler in order to read and write additional data for graphs, nodes and edges.
 
Field Summary
protected static Map decode2encodeMap
           
protected static Map encode2decodeMap
           
 
Constructor Summary
YGFIOHandler()
          Instantiates a new YGFIOHandler.
 
Method Summary
 void addDataHandler(String key, YGFIOHandler.DataHandler dataHandler)
          Register a DataHandler with this class.
static void addEncoding(String encodedName, String decodedName)
          Adds a new class name encoding to YGFIOHandler.
protected  Graph2D createInnerGraph(Node anchorNode)
          Creates a new graph instance that is used as inner graph for a Graph2DNodeRealizer in case the read in graph is not part of a graph hierarchy.
static String decode(String encodedName)
          Decodes the external class name string generated by encode(String).
static String encode(String decodedName)
          Returns the external form of a given class name string.
 YGFIOHandler.DataHandler getDataHandler(String key)
          Returns the DataHandler registered with the given key.
 String getFileFormatString()
          Returns the YGF file format string.
 String getFileNameExtension()
          Returns the YGF file name extension, i.e.
 void read(Graph2D graph, InputStream in)
          Adds the contents that are read from the stream to the given graph.
protected  void read(Graph2D graph, ObjectInputStream in)
          Fills the contents of the given graph from an ObjectInputStream.
protected  void readEdgeInfo(Graph2D graph, Edge e, ObjectInputStream in)
          Reads edge information from the given input stream.
protected  void readEdgeRealizer(Graph2D graph, Edge e, ObjectInputStream in)
          Reads edge realizer information from the input stream.
protected  void readFolderNodeInfo(Graph2D graph, Node v, ObjectInputStream in)
          Reads in folder node information if the given graph was part of a graph hierarchy.
protected  void readGroupNodeInfo(Graph2D graph, Node v, ObjectInputStream in)
          Reads in group node information if the given graph was part of a graph hierarchy and contained grouped nodes.
protected  void readInterEdgeInfo(Graph2D graph, Edge e, ObjectInputStream in)
          Reads graph hierarchic inter-edge information from the given input stream.
protected  void readNodeInfo(Graph2D graph, Node v, ObjectInputStream in)
          Reads node information from the input stream.
protected  void readNodeRealizer(Graph2D graph, Node v, ObjectInputStream in)
          Reads node realizer information from the input stream.
 void removeDataHandler(String key)
          Removes the DataHandler registered with the given ID.
protected  void write(Graph2D graph, ObjectOutputStream out)
          Writes the contents of the given graph to an ObjectOutputStream.
 void write(Graph2D graph, OutputStream out)
          Writes the contents of the given graph in YGF format to a stream.
protected  void writeEdgeInfo(Graph2D graph, Edge e, ObjectOutputStream out)
          Writes edge information to the output stream.
protected  void writeEdgeRealizer(Graph2D graph, Edge e, ObjectOutputStream out)
          Writes edge realizer information to the given output stream.
protected  void writeFolderNodeInfo(Graph2D graph, Node v, ObjectOutputStream out)
          Writes out folder node information if the given graph is part of a graph hierarchy.
protected  void writeGroupNodeInfo(Graph2D graph, Node v, ObjectOutputStream out)
          Writes out group node information if the given graph is part of a graph hierarchy.
protected  void writeInterEdgeInfo(Graph2D graph, Edge e, ObjectOutputStream out)
          Writes graph hierarchic inter-edge information to the given output stream.
protected  void writeNodeInfo(Graph2D graph, Node v, ObjectOutputStream out)
          Writes node information to the output stream.
protected  void writeNodeRealizer(Graph2D graph, Node v, ObjectOutputStream out)
          Writes node realizer information to the output stream.
 
Methods inherited from class y.io.IOHandler
canRead, canWrite, canWriteSubset, createObjectInputStream, createObjectOutputStream, hide, read, read, shouldSerialize, shouldSerialize, write, writeSubset, writeSubset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

encode2decodeMap

protected static Map encode2decodeMap

decode2encodeMap

protected static Map decode2encodeMap
Constructor Detail

YGFIOHandler

public YGFIOHandler()
Instantiates a new YGFIOHandler.

Method Detail

addEncoding

public static void addEncoding(String encodedName,
                               String decodedName)
Adds a new class name encoding to YGFIOHandler. The methods encode(String) and decode(String) can be used to translate between encoded and decoded names.


encode

public static String encode(String decodedName)
Returns the external form of a given class name string. If the given name can't be encoded, the decoded name itself will be returned.


decode

public static String decode(String encodedName)
Decodes the external class name string generated by encode(String). If the given name can't be decoded, the encoded name itself will be returned.


getFileFormatString

public String getFileFormatString()
Returns the YGF file format string.

Specified by:
getFileFormatString in class IOHandler

getFileNameExtension

public String getFileNameExtension()
Returns the YGF file name extension, i.e. "ygf"

Specified by:
getFileNameExtension in class IOHandler

write

public void write(Graph2D graph,
                  OutputStream out)
           throws IOException
Writes the contents of the given graph in YGF format to a stream.

Specified by:
write in class IOHandler
Throws:
IOException

write

protected void write(Graph2D graph,
                     ObjectOutputStream out)
              throws IOException
Writes the contents of the given graph to an ObjectOutputStream.

Throws:
IOException

writeEdgeInfo

protected void writeEdgeInfo(Graph2D graph,
                             Edge e,
                             ObjectOutputStream out)
                      throws IOException
Writes edge information to the output stream. Edge information includes realizer information and graph hierarchic inter-edge information. Subclasses may want to refine this method.

Throws:
IOException
Parameters:
e - The edge for which information is written out

writeEdgeRealizer

protected void writeEdgeRealizer(Graph2D graph,
                                 Edge e,
                                 ObjectOutputStream out)
                          throws IOException
Writes edge realizer information to the given output stream.

Throws:
IOException

writeInterEdgeInfo

protected void writeInterEdgeInfo(Graph2D graph,
                                  Edge e,
                                  ObjectOutputStream out)
                           throws IOException
Writes graph hierarchic inter-edge information to the given output stream.

Throws:
IOException

writeNodeInfo

protected void writeNodeInfo(Graph2D graph,
                             Node v,
                             ObjectOutputStream out)
                      throws IOException
Writes node information to the output stream. Node information includes realizer information and graph hierarchic inner graph information Subclasses may want to overwrite this method.

Throws:
IOException
Parameters:
v - The node for which information is written out

writeNodeRealizer

protected void writeNodeRealizer(Graph2D graph,
                                 Node v,
                                 ObjectOutputStream out)
                          throws IOException
Writes node realizer information to the output stream.

Throws:
IOException
Parameters:
v - The node for which information is written out

writeFolderNodeInfo

protected void writeFolderNodeInfo(Graph2D graph,
                                   Node v,
                                   ObjectOutputStream out)
                            throws IOException
Writes out folder node information if the given graph is part of a graph hierarchy.

Throws:
IOException

writeGroupNodeInfo

protected void writeGroupNodeInfo(Graph2D graph,
                                  Node v,
                                  ObjectOutputStream out)
                           throws IOException
Writes out group node information if the given graph is part of a graph hierarchy.

Throws:
IOException

read

public void read(Graph2D graph,
                 InputStream in)
          throws IOException
Description copied from class: IOHandler
Adds the contents that are read from the stream to the given graph. The given graph will not be cleared when the content of the file will be added to it.

Specified by:
read in class IOHandler
Throws:
IOException

read

protected void read(Graph2D graph,
                    ObjectInputStream in)
             throws IOException
Fills the contents of the given graph from an ObjectInputStream.

Throws:
IOException

readNodeInfo

protected void readNodeInfo(Graph2D graph,
                            Node v,
                            ObjectInputStream in)
                     throws IOException
Reads node information from the input stream. Subclasses may want to overwrite this method.

Throws:
IOException
Parameters:
v - The node for which information is read in
graph - The graph that is the owner of the given node.

readNodeRealizer

protected void readNodeRealizer(Graph2D graph,
                                Node v,
                                ObjectInputStream in)
                         throws IOException
Reads node realizer information from the input stream. Subclasses may want to overwrite this method.

Throws:
IOException
Parameters:
v - The node for which information is read in
graph - The graph that is the owner of the given node.

createInnerGraph

protected Graph2D createInnerGraph(Node anchorNode)
Creates a new graph instance that is used as inner graph for a Graph2DNodeRealizer in case the read in graph is not part of a graph hierarchy.

Parameters:
anchorNode - the anchor node for which to create an inner graph.
Returns:
returns a Graph2D object. Subclasses may want to overwrite this method to return a specialized version of Graph2D.

readFolderNodeInfo

protected void readFolderNodeInfo(Graph2D graph,
                                  Node v,
                                  ObjectInputStream in)
                           throws IOException
Reads in folder node information if the given graph was part of a graph hierarchy.

Throws:
IOException

readGroupNodeInfo

protected void readGroupNodeInfo(Graph2D graph,
                                 Node v,
                                 ObjectInputStream in)
                          throws IOException
Reads in group node information if the given graph was part of a graph hierarchy and contained grouped nodes.

Throws:
IOException

readEdgeInfo

protected void readEdgeInfo(Graph2D graph,
                            Edge e,
                            ObjectInputStream in)
                     throws IOException
Reads edge information from the given input stream. Edge information includes realizer information and graph hierarchic inter-edge information. Subclasses may want to refine this method.

Throws:
IOException
Parameters:
e - The edge for which information is read in.

readEdgeRealizer

protected void readEdgeRealizer(Graph2D graph,
                                Edge e,
                                ObjectInputStream in)
                         throws IOException
Reads edge realizer information from the input stream.

Throws:
IOException
Parameters:
e - The edge for which information is read in
graph - The graph that is the owner of the given edge

readInterEdgeInfo

protected void readInterEdgeInfo(Graph2D graph,
                                 Edge e,
                                 ObjectInputStream in)
                          throws IOException
Reads graph hierarchic inter-edge information from the given input stream.

Throws:
IOException

addDataHandler

public void addDataHandler(String key,
                           YGFIOHandler.DataHandler dataHandler)
Register a DataHandler with this class.

Parameters:
key - unique key that identifies the data that is being read and written by the DataHandler. This key is part of the serialized data. the associated data can only be read by DataHandlers that are registered with the same key.
dataHandler -

getDataHandler

public YGFIOHandler.DataHandler getDataHandler(String key)
Returns the DataHandler registered with the given key.

Returns:
either the DataHandler registered with the given key or null if no DataHandler is registered with the given key.

removeDataHandler

public void removeDataHandler(String key)
Removes the DataHandler registered with the given ID.


© Copyright 2000-2008,
yWorks GmbH.
All rights reserved.