org.graphdrawing.graphml.writer
Class DirectGraphMLWriter

java.lang.Object
  extended byorg.graphdrawing.graphml.writer.DirectGraphMLWriter

public class DirectGraphMLWriter
extends Object

This class is an output driver class for GraphML. It uses XmlWriter and GraphElementProvider instances for the actual low level writing process


Constructor Summary
DirectGraphMLWriter()
          Create a new writer instance
 
Method Summary
 void addEdgeOutputHandler(OutputHandler handler)
          Add an output handler for edge scope
 void addGraphElementProvider(GraphElementProvider provider)
          Add a new GraphElementProvider instance that is used to access the elements of the graph.
 void addGraphOutputHandler(OutputHandler handler)
          Add an output handler for graph scope
 void addNamespace(String URI, String prefix)
           
 void addNodeOutputHandler(OutputHandler handler)
          Add an output handler for node scope
 void addOutputHandler(OutputHandler handler, int scopeType)
          Add an output handler for the specified scope
 void addSchemaLocation(String URI, String location)
          Add a new schema location that can be optionally written
 void addXMLAttributeProvider(XMLAttributesProvider provider)
          Add a XMLAttributesProvider instance that will be used to write additional XML attributes to standard GraphML elements
 void clearGraphElementProviders()
          Clear the list of all GraphElementProviders for this writer
protected  GraphMLWriteContext createGraphMLWriteContext()
          Create a new write context that stores the current state of the writing process.
 String getDtd()
          Return the optional DTD SYSID
 String getGraphmlCoreNS()
          Get the namespace URI where the core GraphML elements live.
protected  String getHandlerIds(OutputHandler oh)
          Return the list of ids that a handler will handle for the current document
 IdProvider getIdProvider()
          Return the IdProvider implementation that will be used by this instance.
 GraphMLWriteErrorHandler getWriteErrorHandler()
          Get the error handler that is used currently.
 boolean isWriteXMLSchemaEnabled()
          Return whether the XML schema attribute at the document root should be written.
 void setContextLookup(Class c, Object impl)
          Set a key/value pair that shoud be used for the current write context
 void setContextProperty(String name, Object o)
          Set special properties for the context.
 void setDtd(String sysId)
          Set the optional DTD SYSID.
 void setGraphElementProvider(GraphElementProvider provider)
          Set a new GraphElementProvider instance that is used to access the elements of the graph.
 void setGraphmlCoreNS(String graphmlCoreNS)
          Set the namespace URI where the core GraphML elements live.
 void setIdProvider(IdProvider idProvider)
          Set the IdProvider implementation that will be used by this instance.
 void setWriteErrorHandler(GraphMLWriteErrorHandler customWriteErrorHandler)
          Set a custom error handler
 void setWriteXMLSchemaEnabled(boolean writeXMLSchemaEnabled)
          Set whether the XML schema attribute at the document root should be written.
 void write(XmlWriter coreWriter)
          Start the writing process.
protected  void writeData(XmlWriter writeOutput, GraphMLWriteContext context)
          This method is called whenever a new write process is started.
protected  void writeDataElement(OutputHandler oh, XmlWriter writeOutput, GraphMLWriteContext context)
          Write a single data element with the given output handler.
protected  void writeEdge(GraphElementProvider provider, Object edge, XmlWriter writeOutput, GraphMLWriteContext context)
          Writes an edge element.
protected  void writeGraphElement(GraphElementProvider provider, XmlWriter writeOutput, boolean topLevel, GraphMLWriteContext context)
          Write the <graph> elemenmt that represents the graph that is accessed through the GraphElementProvider provider.
protected  void writeHyperEdge(GraphElementProvider provider, Object hyperedge, XmlWriter writeOutput, GraphMLWriteContext context)
          Writes a hyperedge element.
protected  void writeKeyDefinition(OutputHandler oh, XmlWriter writeOutput, int scope, GraphMLWriteContext context)
          Writes a single key definition for the given OutputHandler.
protected  void writeKeyDefinitions(XmlWriter writeOutput, GraphMLWriteContext context)
          Writes all key definitions.
protected  void writeNode(GraphElementProvider provider, Object node, XmlWriter writeOutput, GraphMLWriteContext context)
          Writes a node element.
protected  void writePort(GraphElementProvider provider, Object port, XmlWriter writeOutput, GraphMLWriteContext context)
          Writes a port element.
protected  void writeRootElement(XmlWriter writeOutput, GraphMLWriteContext context)
          Method that writes the <graphml> element and everything contained to the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DirectGraphMLWriter

public DirectGraphMLWriter()
Create a new writer instance

Method Detail

setWriteXMLSchemaEnabled

public void setWriteXMLSchemaEnabled(boolean writeXMLSchemaEnabled)
Set whether the XML schema attribute at the document root should be written. Default value is true

Parameters:
writeXMLSchemaEnabled - true if the the XML schema attribute should be written.

isWriteXMLSchemaEnabled

public boolean isWriteXMLSchemaEnabled()
Return whether the XML schema attribute at the document root should be written. Default value is true

Returns:
true if the the XML schema attribute should be written.

getIdProvider

public IdProvider getIdProvider()
Return the IdProvider implementation that will be used by this instance. If no custom instance has been set, a default implementation that writes in canonical format will be returned.

Returns:
the IdProvider implementation that will be used by this instance

setIdProvider

public void setIdProvider(IdProvider idProvider)
Set the IdProvider implementation that will be used by this instance. If no custom instance is been set, a default implementation that writes in canonical format will be used.

Parameters:
idProvider - the IdProvider implementation that will be used by this instance, or null to use the default implementation

getDtd

public String getDtd()
Return the optional DTD SYSID

Returns:
the optional DTD SYSID

setDtd

public void setDtd(String sysId)
Set the optional DTD SYSID. If this is null (the default), no DTD reference will be written.

Parameters:
sysId - the optional DTD SYSID

setWriteErrorHandler

public void setWriteErrorHandler(GraphMLWriteErrorHandler customWriteErrorHandler)
Set a custom error handler

Parameters:
customWriteErrorHandler - the custom error handler, or null to use a default
See Also:
getWriteErrorHandler()

getWriteErrorHandler

public GraphMLWriteErrorHandler getWriteErrorHandler()
Get the error handler that is used currently. If no custom instance has been set, a default implementation will be returned

Returns:
the error handler that is used currently
See Also:
setWriteErrorHandler(GraphMLWriteErrorHandler)

addSchemaLocation

public void addSchemaLocation(String URI,
                              String location)
Add a new schema location that can be optionally written

Parameters:
URI - namespace for the schema
location - the schema
See Also:
setWriteXMLSchemaEnabled(boolean), isWriteXMLSchemaEnabled()

addNamespace

public void addNamespace(String URI,
                         String prefix)

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"

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"

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

setGraphElementProvider

public void setGraphElementProvider(GraphElementProvider provider)
Set a new GraphElementProvider instance that is used to access the elements of the graph. This is equivalent to calling clearGraphElementProviders() and addGraphElementProvider(GraphElementProvider)

Parameters:
provider - new provider instance

clearGraphElementProviders

public void clearGraphElementProviders()
Clear the list of all GraphElementProviders for this writer


addGraphElementProvider

public void addGraphElementProvider(GraphElementProvider provider)
Add a new GraphElementProvider instance that is used to access the elements of the graph. The new provider will be accessed last. This can be used to write

Parameters:
provider - new provider instance

getHandlerIds

protected String getHandlerIds(OutputHandler oh)
Return the list of ids that a handler will handle for the current document

Parameters:
oh - the handler
Returns:
list of associated ids

addNodeOutputHandler

public void addNodeOutputHandler(OutputHandler handler)
Add an output handler for node scope

Parameters:
handler - the new output handler

addEdgeOutputHandler

public void addEdgeOutputHandler(OutputHandler handler)
Add an output handler for edge scope

Parameters:
handler - the new output handler

addGraphOutputHandler

public void addGraphOutputHandler(OutputHandler handler)
Add an output handler for graph scope

Parameters:
handler - the new output handler

addOutputHandler

public void addOutputHandler(OutputHandler handler,
                             int scopeType)
Add an output handler for the specified scope

Parameters:
handler - the new output handler
scopeType - the scope for the handler, one of GraphMLConstants.SCOPE_ALL, GraphMLConstants.SCOPE_GRAPHML, GraphMLConstants.SCOPE_EDGE, GraphMLConstants.SCOPE_NODE, GraphMLConstants.SCOPE_HYPEREDGE,

addXMLAttributeProvider

public void addXMLAttributeProvider(XMLAttributesProvider provider)
Add a XMLAttributesProvider instance that will be used to write additional XML attributes to standard GraphML elements

Parameters:
provider -

write

public void write(XmlWriter coreWriter)
           throws IOException
Start the writing process. This serializes all graphs that can be access through the GraphElementProvider instances set on this instances with the help of the coreWriter that handles the low level XML write process.

Parameters:
coreWriter - the low level XMLWriter instance that handles all xml write requests
Throws:
IOException - if the document could not be written.

writeData

protected void writeData(XmlWriter writeOutput,
                         GraphMLWriteContext context)
                  throws GraphMLWriteException
This method is called whenever a new write process is started.

Parameters:
writeOutput - the low level XMLWriter instance that handles all xml write requests
context - the current write context
Throws:
GraphMLWriteException - if an error occured

writeRootElement

protected void writeRootElement(XmlWriter writeOutput,
                                GraphMLWriteContext context)
                         throws GraphMLWriteException
Method that writes the <graphml> element and everything contained to the output stream.

Parameters:
writeOutput - the low level XMLWriter instance that handles all xml write requests
context - the current write context
Throws:
GraphMLWriteException - if an error occured

writeKeyDefinitions

protected void writeKeyDefinitions(XmlWriter writeOutput,
                                   GraphMLWriteContext context)
                            throws GraphMLWriteException
Writes all key definitions. This delegates to writeKeyDefinition(OutputHandler,XmlWriter,int,GraphMLWriteContext)

Parameters:
writeOutput - the low level XMLWriter instance that handles all xml write requests
context - the current write context
Throws:
GraphMLWriteException - if an error occured

writeKeyDefinition

protected void writeKeyDefinition(OutputHandler oh,
                                  XmlWriter writeOutput,
                                  int scope,
                                  GraphMLWriteContext context)
                           throws GraphMLWriteException
Writes a single key definition for the given OutputHandler.

Parameters:
oh - the OutputHandler for which the key defintion is written
writeOutput - the low level XMLWriter instance that handles all xml write requests
scope - the scope of the attribute
context - the current write context
Throws:
GraphMLWriteException - if an error occured

writeDataElement

protected void writeDataElement(OutputHandler oh,
                                XmlWriter writeOutput,
                                GraphMLWriteContext context)
Write a single data element with the given output handler. This delegates to oh to write the content of the data tag.

Parameters:
oh - the OutputHandler that writes the tag
writeOutput - the low level XMLWriter instance that handles all xml write requests
context - the current write context
Throws:
GraphMLWriteException - if an error occured

writeGraphElement

protected void writeGraphElement(GraphElementProvider provider,
                                 XmlWriter writeOutput,
                                 boolean topLevel,
                                 GraphMLWriteContext context)
Write the <graph> elemenmt that represents the graph that is accessed through the GraphElementProvider provider.

Parameters:
provider - the GraphElementProvider that represents the current graph
writeOutput - the low level XMLWriter instance that handles all xml write requests
topLevel - true iff this is a toplevel graph element.
context - the current write context
Throws:
GraphMLWriteException - if an error occured

writeEdge

protected void writeEdge(GraphElementProvider provider,
                         Object edge,
                         XmlWriter writeOutput,
                         GraphMLWriteContext context)
Writes an edge element.

Parameters:
edge - the edge object to write.
provider - the GraphElementProvider that represents the current graph
writeOutput - the low level XMLWriter instance that handles all xml write requests
context - the current write context
Throws:
GraphMLWriteException - if an error occured

writeNode

protected void writeNode(GraphElementProvider provider,
                         Object node,
                         XmlWriter writeOutput,
                         GraphMLWriteContext context)
Writes a node element.

Parameters:
node - the node object to write.
provider - the GraphElementProvider that represents the current graph
writeOutput - the low level XMLWriter instance that handles all xml write requests
context - the current write context
Throws:
GraphMLWriteException - if an error occured

writePort

protected void writePort(GraphElementProvider provider,
                         Object port,
                         XmlWriter writeOutput,
                         GraphMLWriteContext context)
Writes a port element.

Parameters:
port - the port object to write.
provider - the GraphElementProvider that represents the current graph
writeOutput - the low level XMLWriter instance that handles all xml write requests
context - the current write context
Throws:
GraphMLWriteException - if an error occured

writeHyperEdge

protected void writeHyperEdge(GraphElementProvider provider,
                              Object hyperedge,
                              XmlWriter writeOutput,
                              GraphMLWriteContext context)
Writes a hyperedge element.

Parameters:
hyperedge - the hyperedge object to write.
provider - the GraphElementProvider that represents the current graph
writeOutput - the low level XMLWriter instance that handles all xml write requests
context - the current write context
Throws:
GraphMLWriteException - if an error occured

createGraphMLWriteContext

protected GraphMLWriteContext createGraphMLWriteContext()
Create a new write context that stores the current state of the writing process. This method will be called by write(XmlWriter) whenever a new writing process starts, so each write process has a new associated context

Returns:
a new GraphMLWriteContext instance

setContextLookup

public void setContextLookup(Class c,
                             Object impl)
Set a key/value pair that shoud be used for the current write context

Parameters:
c - the class that serves as lookup key
impl - an object that should provide a suitable implementation of c
See Also:
GraphMLWriteContext.setLookup(Class,Object)

setContextProperty

public void setContextProperty(String name,
                               Object o)
Set special properties for the context. This is typically used to set implementation dependent behaviour through a facade class

Parameters:
name -
o -
See Also:
GraphMLWriteContext.setProperty(String,Object)


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