com.yworks.yfiles.server.graphml.support
Class GraphMLLayoutGraphIOHandler

java.lang.Object
  extended bycom.yworks.yfiles.server.graphml.support.GraphMLLayoutGraphIOHandler

public class GraphMLLayoutGraphIOHandler
extends Object

IOHandler for (de)serializing graphs from/to GraphML format. GraphMLLayoutGraphIOHandler supports (de)serialization of custom GraphML attributes that hold data of simple type, as well as ids, and styles as DocumentFragments.

For more information about the GraphML file format please refer to the GraphML Primer.


Field Summary
protected  List edgeOutputHandlers
           
protected  List graphmlOutputHandlers
           
protected  List graphOutputHandlers
           
protected  List inputHandlers
           
protected  List nodeOutputHandlers
           
protected  List portOutputHandlers
           
protected  boolean validationEnabled
           
protected  boolean writeDTDEnabled
           
protected  boolean writeXMLSchemaEnabled
           
 
Constructor Summary
GraphMLLayoutGraphIOHandler()
          Creates a new instance of GraphMLIOHandler.
 
Method Summary
 void addAttribute(DataMap map, String attrName, int type, int scope)
          Adds a GraphML attribute with node scope that holds data of simple type.
 void addEdgeAttribute(DataProvider out, DataAcceptor in, String attrName, int type)
          Adds a GraphML attribute with edge scope that holds data of simple type.
 void addGraphAttribute(DataProvider out, DataAcceptor in, String attrName, int type)
          Adds a GraphML attribute with graph scope that holds data of simple type.
 void addInputHandler(DOMInputHandler inputHandler)
          Adds a subordinate input handler to this GraphMLIOHandler.
 void addInputHandler(DOMInputHandler inputHandler, int scope)
          Deprecated. Use addInputHandler(org.graphdrawing.graphml.reader.dom.DOMInputHandler) instead
 void addNamespace(String namespaceURI, String shortName)
          Adds a namespace declaration to the GraphML file.
 void addNodeAttribute(DataProvider out, DataAcceptor in, String attrName, int type)
          Adds a GraphML attribute with node scope that holds data of simple type.
 void addOutputHandler(OutputHandler outputHandler, int scope)
          Adds a subordinate output handler for the given element scope to this GraphMLIOHandler.
 void addSchemaLocation(String namespace, String schemaLocation)
          Adds a schema location to the header of a GraphML file.
 boolean canRead()
          Returns true.
 boolean canWrite()
          Returns true.
 void clearInputHandlers()
          Clear all input handlers
protected  void configureParser(DOMGraphMLParser graphMLParser, Graph graph)
          Configures the parser for the read operations.
protected  DirectGraphMLWriter createDirectGraphMLWriter()
          Creates and returns a GraphML writer instance.
protected  YGraphElementFactory createGraphElementFactory(Graph graph)
          Create the factory instance used for reading the graph
protected  GraphElementProvider createGraphElementProvider(Graph graph)
          Create the provider instance used for writing the graph
 GraphMLParseErrorHandler getErrorHandler()
          Return the parse error handler that is used by this instance.
 String getFileFormatString()
          Returns the GraphML file format string.
 String getFileNameExtension()
          Returns the default file name extension for GraphML files.
 DataAcceptor getGraphIdAcceptor()
          Return the DataAcceptor instance for graph ids that has been previously registered with setGraphIdAcceptor(y.base.DataAcceptor)
 DataProvider getGraphIdProvider()
          Return the DataProvider instance for graph ids that has been previously registered with setGraphIdProvider(y.base.DataProvider)
 String getGraphmlCoreNS()
          Get the namespace URI where the core GraphML elements live.
 DataAcceptor getIdDataAcceptor()
          Return the DataAcceptor instance for graph element ids that has been previously registered with setIdDataAcceptor(y.base.DataAcceptor)
 DataProvider getIdDataProvider()
          Return the DataProvider instance for graph element ids that has been previously registered with setIdDataProvider(y.base.DataProvider)
 Collection getInputHandlers()
          Returns the registered input handlers for GraphML attributes that are registered with this GraphMLIOHandler.
 Collection getInputHandlers(int scope)
          Deprecated. Use getInputHandlers() instead
 String getOutputEncoding()
          Get the output encoding that is used by this handler instance.
 Collection getOutputHandlers(int scope)
          Returns an editable view on the registered output handlers for GraphML attributes with given scope that are registered with this GraphMLIOHandler.
 SerializerRegistry getSerializerRegistry()
           
 boolean isReadEmbeddedResources()
          Returns whether embedded resources should be evaluated.
 boolean isValidationEnabled()
          Returns if a validating parser is used.
 boolean isWriteDTDEnabled()
          Returns if a reference to the GraphML DTD should be written.
 boolean isWriteEmbeddedResources()
          Returns whether embedded resources should be written in a separate block.
 boolean isWriteXMLSchemaEnabled()
          Returns if a reference to the GraphML XML Schema definition should be written.
 void read(Graph graph, InputStream is)
          Reads a GraphML file from the given input stream and populates the Graph2D object.
 void read(Graph graph, Node n)
          Reads a Graph from a preparsed DOM tree object.
 void read(Graph graph, String name)
          Fills the contents of the given graph from a file.
 void read(Graph graph, URL url)
          Fills the contents of the given graph from a URL.
 void removeInputHandler(DOMInputHandler handler)
          unregister an inputhandler
 void setErrorHandler(GraphMLParseErrorHandler errorHandler)
          Set a custom parse error handler that is used by this instance.
 void setGraphIdAcceptor(DataAcceptor graphIdAcceptor)
          Register a DataAcceptor instance that stores graphml graph element ids for each graph itself.
 void setGraphIdProvider(DataProvider graphIdProvider)
          Register a DataProvider instance that provides graphml element ids for each graph itself.
 void setGraphmlCoreNS(String graphmlCoreNS)
          Set the namespace URI where the core GraphML elements live.
 void setIdDataAcceptor(DataAcceptor idDataAcceptor)
          Register a DataAcceptor instance that stores graphml element ids.
 void setIdDataProvider(DataProvider idDataProvider)
          Register a DataProvider instance that provides graphml element ids for each element.
 void setOutputEncoding(String outputEncoding)
          Set a specific encoding for the output.
 void setReadEmbeddedResources(boolean readEmbeddedResource)
          Set whether embedded resources should be evaluated.
 void setSerializerRegistry(SerializerRegistry serializerRegistry)
           
 void setValidationEnabled(boolean b)
          Sets if a validating parser is used.
 void setWriteDTDEnabled(boolean b)
          Sets if a reference to the GraphML DTD should be written.
 void setWriteEmbeddedResources(boolean writeEmbeddedResource)
          Set whether embedded resources should be written in a separate block.
 void setWriteXMLSchemaEnabled(boolean b)
          Returns if a reference to the GraphML XML Schema definition should be written.
 void write(Graph graph, OutputStream os)
          Writes the given Graph2D object to the output stream creating a GraphML file.
 void write(Graph graph, Result result)
          Writes the given Graph2D object to a Transformer result.
 void write(Graph graph, String name)
          Writes the contents of the given graph to a file.
 void write(Graph graph, Writer writer)
          Writes the given Graph2D object to the output stream creating a GraphML file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

writeDTDEnabled

protected boolean writeDTDEnabled

writeXMLSchemaEnabled

protected boolean writeXMLSchemaEnabled

validationEnabled

protected boolean validationEnabled

inputHandlers

protected List inputHandlers

graphOutputHandlers

protected List graphOutputHandlers

graphmlOutputHandlers

protected List graphmlOutputHandlers

portOutputHandlers

protected List portOutputHandlers

nodeOutputHandlers

protected List nodeOutputHandlers

edgeOutputHandlers

protected List edgeOutputHandlers
Constructor Detail

GraphMLLayoutGraphIOHandler

public GraphMLLayoutGraphIOHandler()
Creates a new instance of GraphMLIOHandler. By default, realizer serializers for all yFiles node and edge realizer implementations as found in package y.view are already registered. Also provided by default is support for post-processors.

See Also:
PostprocessorInputHandler
Method Detail

getOutputEncoding

public String getOutputEncoding()
Get the output encoding that is used by this handler instance. Default is UTF-8

Returns:
the current output encoding

setOutputEncoding

public void setOutputEncoding(String outputEncoding)
Set a specific encoding for the output. Default is UTF-8

Parameters:
outputEncoding - custom output encoding

isReadEmbeddedResources

public boolean isReadEmbeddedResources()
Returns whether embedded resources should be evaluated. If false, no resources are read from an embedded resource data tag. The exact behaviour in this case depends on the InputHandler used (i.e. resolve an external URL instead). Default is true.

Returns:
whether embedded resources should be read if present.

setReadEmbeddedResources

public void setReadEmbeddedResources(boolean readEmbeddedResource)
Set whether embedded resources should be evaluated. If false, no resources are read from an embedded resource data tag. The exact behaviour in this case depends on the InputHandler used (i.e. resolve an external URL instead). Default is true.

Parameters:
readEmbeddedResource - whether embedded resources should be read if present.

isWriteEmbeddedResources

public boolean isWriteEmbeddedResources()
Returns whether embedded resources should be written in a separate block. If false, no resources are embedded in the graphml file. The exact behaviour in this case depends on the OutputHandler used. Default is true.

Returns:
whether embedded resources should be written in a separate block.

setWriteEmbeddedResources

public void setWriteEmbeddedResources(boolean writeEmbeddedResource)
Set whether embedded resources should be written in a separate block. If false, no resources are embedded in the graphml file. The exact behaviour in this case depends on the OutputHandler used. Default is true.

Parameters:
writeEmbeddedResource - whether embedded resources should be written in a separate block.

getErrorHandler

public GraphMLParseErrorHandler getErrorHandler()
Return the parse error handler that is used by this instance.

Returns:
the parse error handler that is used by this instance.

setErrorHandler

public void setErrorHandler(GraphMLParseErrorHandler errorHandler)
Set a custom parse error handler that is used by this instance. If this is not set, a default implementation that handles some common cases is used.

Parameters:
errorHandler - the parse error handler that should be used by this instance.

getGraphmlCoreNS

public String getGraphmlCoreNS()
Get the namespace URI where the core GraphML elements live. By default, this is set to "http://graphml.graphdrawing.org/xmlns/graphml" for compatibility with older yfiles GraphML releases, however, the official GraphML namespace is now "http://graphml.graphdrawing.org/xmlns"

Returns:
the namespace URI where the core GraphML elements live

setGraphmlCoreNS

public void setGraphmlCoreNS(String graphmlCoreNS)
Set the namespace URI where the core GraphML elements live. By default, this is set to "http://graphml.graphdrawing.org/xmlns/graphml" for compatibility with older yfiles GraphML releases, however, the official GraphML namespace is now "http://graphml.graphdrawing.org/xmlns"

Parameters:
graphmlCoreNS - the namespace URI where the core GraphML elements live

getSerializerRegistry

public SerializerRegistry getSerializerRegistry()

setSerializerRegistry

public void setSerializerRegistry(SerializerRegistry serializerRegistry)

getFileFormatString

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


getFileNameExtension

public String getFileNameExtension()
Returns the default file name extension for GraphML files.

Returns:
graphml

canRead

public boolean canRead()
Returns true.


canWrite

public boolean canWrite()
Returns true.


addInputHandler

public void addInputHandler(DOMInputHandler inputHandler,
                            int scope)
Deprecated. Use addInputHandler(org.graphdrawing.graphml.reader.dom.DOMInputHandler) instead

Adds a subordinate input handler for the given element scope to this GraphMLIOHandler. This is deprecated, use addInputHandler(org.graphdrawing.graphml.reader.dom.DOMInputHandler) and test the scope in DOMInputHandler.acceptKey(org.w3c.dom.NamedNodeMap,int) instead

Parameters:
inputHandler - the input handler to be added.
scope - This parameter is unused

addInputHandler

public void addInputHandler(DOMInputHandler inputHandler)
Adds a subordinate input handler to this GraphMLIOHandler. The scope is determined by the for attribute of the key node

Parameters:
inputHandler - the input handler to be added.

addOutputHandler

public void addOutputHandler(OutputHandler outputHandler,
                             int scope)
Adds a subordinate output handler for the given element scope to this GraphMLIOHandler.

Parameters:
outputHandler - the output handler to be added.
scope - Scope specifier; one of GraphMLConstants.SCOPE_GRAPH, GraphMLConstants.SCOPE_GRAPHML, GraphMLConstants.SCOPE_NODE, or GraphMLConstants.SCOPE_EDGE.

getInputHandlers

public Collection getInputHandlers()
Returns the registered input handlers for GraphML attributes that are registered with this GraphMLIOHandler.

Returns:
All registered subordinate input handlers for GraphML.

getInputHandlers

public Collection getInputHandlers(int scope)
Deprecated. Use getInputHandlers() instead

Returns the registered input handlers for GraphML attributes that are registered with this GraphMLIOHandler. This is deprecated, use addInputHandler(org.graphdrawing.graphml.reader.dom.DOMInputHandler) and test the scope in DOMInputHandler.acceptKey(org.w3c.dom.NamedNodeMap,int) instead

Parameters:
scope - This parameter is unused
Returns:
All registered subordinate input handlers for GraphML.

clearInputHandlers

public void clearInputHandlers()
Clear all input handlers


removeInputHandler

public void removeInputHandler(DOMInputHandler handler)
unregister an inputhandler

Parameters:
handler -

getOutputHandlers

public Collection getOutputHandlers(int scope)
Returns an editable view on the registered output handlers for GraphML attributes with given scope that are registered with this GraphMLIOHandler. Output handlers can be added or removed from the returned collection.

Parameters:
scope - Scope specifier; one of GraphMLConstants.SCOPE_GRAPH, GraphMLConstants.SCOPE_NODE, or GraphMLConstants.SCOPE_EDGE.
Returns:
All registered subordinate output handlers for GraphML attributes with given scope.

createDirectGraphMLWriter

protected DirectGraphMLWriter createDirectGraphMLWriter()
Creates and returns a GraphML writer instance. Note that this method is also invoked to create the GraphML writer that is used with this GraphMLIOHandler.


addAttribute

public void addAttribute(DataMap map,
                         String attrName,
                         int type,
                         int scope)
Adds a GraphML attribute with node scope that holds data of simple type. Supported are Java types such as boolean, int, long, float, double, and String.

Note that the currently used yFiles data accessor implementations type-cast Java types long and float to int and double, respectively.

Parameters:
map - The node map that is accessed by both input and output handler whenever actual data for a node is to be read from or written to a GraphML file.
attrName - The name that is used inside the GraphML file with the XML attr.name attribute of the GraphML <key> element.
type - Type specifier as defined in interface AttributeConstants.
scope - the GraphMLConstants scope to use.

addGraphAttribute

public void addGraphAttribute(DataProvider out,
                              DataAcceptor in,
                              String attrName,
                              int type)
Adds a GraphML attribute with graph scope that holds data of simple type. Supported are Java types such as boolean, int, long, float, double, and String.

Note that the currently used yFiles data accessor implementations type-cast Java types long and float to int and double, respectively.

Parameters:
out - The data provider that is accessed by the output handler whenever actual data for a graph is to be written to a GraphML file.
in - The data acceptor that is accessed by the input handler whenever actual data for a graph is to be read from a GraphML file.
attrName - The name that is used inside the GraphML file with the XML attr.name attribute of the GraphML <key> element.
type - Type specifier as defined in interface AttributeConstants.

addNodeAttribute

public void addNodeAttribute(DataProvider out,
                             DataAcceptor in,
                             String attrName,
                             int type)
Adds a GraphML attribute with node scope that holds data of simple type. Supported are Java types such as boolean, int, long, float, double, and String.

Note that the currently used yFiles data accessor implementations type-cast Java types long and float to int and double, respectively.

Parameters:
out - The data provider that is accessed by the output handler whenever actual data for a node is to be written to a GraphML file.
in - The data acceptor that is accessed by the input handler whenever actual data for a node is to be read from a GraphML file.
attrName - The name that is used inside the GraphML file with the XML attr.name attribute of the GraphML <key> element.
type - Type specifier as defined in interface AttributeConstants.

addEdgeAttribute

public void addEdgeAttribute(DataProvider out,
                             DataAcceptor in,
                             String attrName,
                             int type)
Adds a GraphML attribute with edge scope that holds data of simple type. Supported are Java types such as boolean, int, long, float, double, and String.

Parameters:
out - The data provider that is accessed by the output handler whenever actual data for an edge is to be written to a GraphML file.
in - The data acceptor that is accessed by the input handler whenever actual data for an edge is to be read from a GraphML file.
attrName - The name that is used inside the GraphML file with the XML attr.name attribute of the GraphML <key> element.
type - Type specifier as defined in interface AttributeConstants.

isValidationEnabled

public boolean isValidationEnabled()
Returns if a validating parser is used.


isWriteDTDEnabled

public boolean isWriteDTDEnabled()
Returns if a reference to the GraphML DTD should be written.


isWriteXMLSchemaEnabled

public boolean isWriteXMLSchemaEnabled()
Returns if a reference to the GraphML XML Schema definition should be written.


setValidationEnabled

public void setValidationEnabled(boolean b)
Sets if a validating parser is used.


setWriteDTDEnabled

public void setWriteDTDEnabled(boolean b)
Sets if a reference to the GraphML DTD should be written.


setWriteXMLSchemaEnabled

public void setWriteXMLSchemaEnabled(boolean b)
Returns if a reference to the GraphML XML Schema definition should be written.


addNamespace

public void addNamespace(String namespaceURI,
                         String shortName)
Adds a namespace declaration to the GraphML file.


addSchemaLocation

public void addSchemaLocation(String namespace,
                              String schemaLocation)
Adds a schema location to the header of a GraphML file.


write

public void write(Graph graph,
                  String name)
           throws IOException
Writes the contents of the given graph to a file.

Parameters:
name - The name of the output file
Throws:
IOException

read

public void read(Graph graph,
                 String name)
          throws IOException
Fills the contents of the given graph from a file.

Parameters:
name - The name of the file to be read.
Throws:
IOException

read

public void read(Graph graph,
                 URL url)
          throws IOException
Fills the contents of the given graph from a URL.

Parameters:
url - The url of the resource to be read.
Throws:
IOException

write

public void write(Graph graph,
                  OutputStream os)
           throws IOException
Writes the given Graph2D object to the output stream creating a GraphML file. The proper DTD (Document Type Definition), or alternatively XML Schema definition, as well as the XML header is also written.

Note that the graph element provider that is used by the encoder logic to write the GraphML file is chosen depending on whether the Graph2D object has a HierarchyManager associated or not.

Parameters:
graph - The Graph2D object that is to be written to a GraphML file.
os - The output stream that becomes the GraphML file.
Throws:
IOException
See Also:
YGraphElementProvider

write

public void write(Graph graph,
                  Writer writer)
           throws IOException
Writes the given Graph2D object to the output stream creating a GraphML file. The proper DTD (Document Type Definition), or alternatively XML Schema definition, as well as the XML header is also written.

Note that the graph element provider that is used by the encoder logic to write the GraphML file is chosen depending on whether the Graph2D object has a HierarchyManager associated or not.

Parameters:
graph - The Graph2D object that is to be written to a GraphML file.
writer - The writer that becomes the GraphML file.
Throws:
IOException
See Also:
YGraphElementProvider, YHierarchyGraphElementProvider

write

public void write(Graph graph,
                  Result result)
           throws IOException
Writes the given Graph2D object to a Transformer result. The proper DTD (Document Type Definition), or alternatively XML Schema definition, as well as the XML header is also written.

Note that the graph element provider that is used by the encoder logic to write the GraphML file is chosen depending on whether the Graph2D object has a HierarchyManager associated or not.

This method is especially useful if the result should be postprocessed by other XML applications directly (i.e. without re-reading and parsing)

Parameters:
graph - The Graph2D object that is to be written to a GraphML file.
result - The Transformer result that stores the output.
Throws:
IOException
See Also:
YGraphElementProvider, YHierarchyGraphElementProvider

createGraphElementProvider

protected GraphElementProvider createGraphElementProvider(Graph graph)
Create the provider instance used for writing the graph


getIdDataProvider

public DataProvider getIdDataProvider()
Return the DataProvider instance for graph element ids that has been previously registered with setIdDataProvider(y.base.DataProvider)

Returns:
the DataProvider instance for graph element ids that has been previously registered with setIdDataProvider(y.base.DataProvider)

setIdDataProvider

public void setIdDataProvider(DataProvider idDataProvider)
Register a DataProvider instance that provides graphml element ids for each element.

Parameters:
idDataProvider -

getIdDataAcceptor

public DataAcceptor getIdDataAcceptor()
Return the DataAcceptor instance for graph element ids that has been previously registered with setIdDataAcceptor(y.base.DataAcceptor)

Returns:
the DataAcceptor instance for graph element ids that has been previously registered with setIdDataAcceptor(y.base.DataAcceptor)

setIdDataAcceptor

public void setIdDataAcceptor(DataAcceptor idDataAcceptor)
Register a DataAcceptor instance that stores graphml element ids. This stores a graphml element id for each graph element, except for nested graphs (see setGraphIdAcceptor(y.base.DataAcceptor)

Parameters:
idDataAcceptor -

getGraphIdAcceptor

public DataAcceptor getGraphIdAcceptor()
Return the DataAcceptor instance for graph ids that has been previously registered with setGraphIdAcceptor(y.base.DataAcceptor)

Returns:
the DataAcceptor instance for graph ids that has been previously registered with setGraphIdAcceptor(y.base.DataAcceptor)

setGraphIdAcceptor

public void setGraphIdAcceptor(DataAcceptor graphIdAcceptor)
Register a DataAcceptor instance that stores graphml graph element ids for each graph itself. This stores a graph id for each group node in hierarchic graphs.
  • Note: This is used for nested graphs, when a graphML graph element has no corresponding ygraph object (i.e. for group nodes)
  • Parameters:
    graphIdAcceptor -

    getGraphIdProvider

    public DataProvider getGraphIdProvider()
    Return the DataProvider instance for graph ids that has been previously registered with setGraphIdProvider(y.base.DataProvider)

    Returns:
    the DataProvider instance for graph ids that has been previously registered with setGraphIdProvider(y.base.DataProvider)

    setGraphIdProvider

    public void setGraphIdProvider(DataProvider graphIdProvider)
    Register a DataProvider instance that provides graphml element ids for each graph itself. This should provide a graph id for each group node in hierarchic graphs.

    Parameters:
    graphIdProvider -

    read

    public void read(Graph graph,
                     InputStream is)
              throws IOException
    Reads a GraphML file from the given input stream and populates the Graph2D object.

    Note that the graph element factory that is used by the parser logic to create new graph elements (and eventually also new graphs) is chosen depending on whether the Graph2D object has a HierarchyManager associated or not.

    Parameters:
    graph - The Graph2D object that is to be populated with nodes and edges as read from the GraphML file.
    is - The input stream that holds the GraphML file to be read.
    Throws:
    IOException
    See Also:
    YGraphElementFactory, YHierarchyGraphElementFactory

    read

    public void read(Graph graph,
                     Node n)
              throws IOException
    Reads a Graph from a preparsed DOM tree object.

    Note that the graph element factory that is used by the parser logic to create new graph elements (and eventually also new graphs) is chosen depending on whether the Graph2D object has a HierarchyManager associated or not. This overload is useful if the IOHandler is used after a chain of TRaX transformations

    Note: No validation is performed on the DOM tree by this overload.

    Parameters:
    graph - The Graph2D object that is to be populated with nodes and edges as read from the GraphML file.
    n - The root node of the preparsed DOM tree.
    Throws:
    IOException
    See Also:
    YGraphElementFactory, YHierarchyGraphElementFactory

    configureParser

    protected void configureParser(DOMGraphMLParser graphMLParser,
                                   Graph graph)
    Configures the parser for the read operations.

    Parameters:
    graphMLParser - The parser to configure
    graph - the graph that will be parsed.

    createGraphElementFactory

    protected YGraphElementFactory createGraphElementFactory(Graph graph)
    Create the factory instance used for reading the graph



    Copyright © 2000-2007 yWorks GmbH. All rights reserved