org.graphdrawing.graphml.reader.dom
Class DOMGraphMLParser

java.lang.Object
  extended byorg.graphdrawing.graphml.reader.dom.DOMGraphMLParser

public class DOMGraphMLParser
extends Object

DOM implementation of a GraphML parser. In order to use the parser, an instance of GraphElementFactory has to be provided which is reponsible for the creation of the graph elements defined in the input data. To process data defined in key/data elements, instances of DOMInputHandler can be registered.


Field Summary
protected  boolean validationEnabled
          validation
 
Constructor Summary
DOMGraphMLParser()
          Create a new instance of this parser
 
Method Summary
 void addDOMInputHandler(DOMInputHandler handler)
          Adds an input handler.
 void addXMLAttributeParser(XMLAttributesParser handler)
          Adds an XML attributes parser.
protected  DOMGraphMLParseContext createParseContext()
          Create a new parse context.
 DocumentBuilderFactory getDocumentBuilderFactory()
          Returns the Document Builder Factory used that is.
 String getGraphmlCoreNS()
          Deprecated. The core graphml namespace is determined automatically now
 IdAcceptor getIdAcceptor()
          Get the IdAcceptor instance that has been registered previously with setIdAcceptor(org.graphdrawing.graphml.reader.IdAcceptor).
 GraphMLParseErrorHandler getParseErrorHandler()
          Get the error handler instance that is used for this parse process.
 Object parse(InputStream is)
          Parses the content of an input stream.
 Object parse(InputStream is, EntityResolver resolver)
          Parses the content of an input stream.
protected  void parseDataNodes(Map dataNodes, DOMInputHandler handler)
          Called whenever an input handler should parse one or more data tags that are associated with a core graphml element.
 Object parseDocument(Document doc)
          Start parsing a given document.
protected  void parseEdgeNode(Node edgeNode)
          Called whenever the edge tag in the graphml input is encountered.
protected  void parseEndPointNode(Node endPointNode)
          Called whenever the node tag for a hyperedge is encountered
 Object parseGraphMLNode(Node graphMLNode)
          Parses the graphml node in a DOM tree.
protected  void parseGraphNode(Node graphNode)
          Called whenever the graph tag in the graphml input is encountered.
protected  void parseHyperEdgeNode(Node hyperedgeNode)
          Called whenever the hyperedge tag in the graphml input is encountered.
protected  void parseKeyNode(Node keyNode)
          Called whenever the key tag for a data attribute definition is encountered
protected  void parseNodeNode(Node nodeNode)
          Called whenever the node tag in the graphml input is encountered.
protected  void parsePortNode(Node portNode)
          Called whenever the port tag in the graphml input is encountered.
 void removeDOMInputHandler(DOMInputHandler handler)
          Removes an input handler.
 void removeXMLAttributeParser(XMLAttributesParser handler)
          Removes an XML attributes parser.
 void setContextLookup(Class c, Object o)
          Set a lookup value that will be used by all parse contexts that are created by this parser.
 void setContextProperty(String name, Object o)
          Set a property value that will be used by all parse contexts that are created by this parser.
 void setGraphElementFactory(GraphElementFactory factory)
          Sets the factory for graph element creation.
 void setGraphmlCoreNS(String graphmlCoreNS)
          Deprecated. The core graphml namespace is determined automatically now
 void setIdAcceptor(IdAcceptor idAcceptor)
          Set a custom IdAcceptor instance that can be used to store the special id attribute of core graphml elements.
 void setParseErrorHandler(GraphMLParseErrorHandler customParseErrorHandler)
          Register a custom error handler instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

validationEnabled

protected boolean validationEnabled
validation

Constructor Detail

DOMGraphMLParser

public DOMGraphMLParser()
Create a new instance of this parser

Method Detail

setParseErrorHandler

public void setParseErrorHandler(GraphMLParseErrorHandler customParseErrorHandler)
Register a custom error handler instance. If this is not set, a default implementation will be used.

Parameters:
customParseErrorHandler - the custom error handler instance, or null if the default implementation should be used.

getParseErrorHandler

public GraphMLParseErrorHandler getParseErrorHandler()
Get the error handler instance that is used for this parse process. If no custom instance has been registered with setParseErrorHandler(org.graphdrawing.graphml.reader.GraphMLParseErrorHandler), a default implementation will be returned.

Returns:
the error handler instance that is currently in effect

getGraphmlCoreNS

public String getGraphmlCoreNS()
Deprecated. The core graphml namespace is determined automatically now

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)
Deprecated. The core graphml namespace is determined automatically now

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

getIdAcceptor

public IdAcceptor getIdAcceptor()
Get the IdAcceptor instance that has been registered previously with setIdAcceptor(org.graphdrawing.graphml.reader.IdAcceptor). By default, no IdAcceptor is registered.

Returns:
the custom IdAcceptor instance

setIdAcceptor

public void setIdAcceptor(IdAcceptor idAcceptor)
Set a custom IdAcceptor instance that can be used to store the special id attribute of core graphml elements. By default, no IdAcceptor is registered.

Returns:
the custom IdAcceptor instance

getDocumentBuilderFactory

public DocumentBuilderFactory getDocumentBuilderFactory()
Returns the Document Builder Factory used that is.


setGraphElementFactory

public void setGraphElementFactory(GraphElementFactory factory)
Sets the factory for graph element creation.

Parameters:
factory - the GraphElementFactory used for element creation

addDOMInputHandler

public void addDOMInputHandler(DOMInputHandler handler)
Adds an input handler.

Parameters:
handler - the new input handler

removeDOMInputHandler

public void removeDOMInputHandler(DOMInputHandler handler)
Removes an input handler.

Parameters:
handler - the input handler to remove

addXMLAttributeParser

public void addXMLAttributeParser(XMLAttributesParser handler)
Adds an XML attributes parser.

Parameters:
handler - the new XML attributes parser

removeXMLAttributeParser

public void removeXMLAttributeParser(XMLAttributesParser handler)
Removes an XML attributes parser.

Parameters:
handler - the XML attributes parser to remove

parse

public Object parse(InputStream is)
             throws GraphMLParseException
Parses the content of an input stream.

Parameters:
is - an input stream which contains graphML data.
Returns:
the object returned by the createGraphML method of the current GraphElementFactory.
Throws:
GraphMLParseException

parse

public Object parse(InputStream is,
                    EntityResolver resolver)
             throws GraphMLParseException
Parses the content of an input stream.

Parameters:
is - an input stream which contains graphML data.
Returns:
the object returned by the createGraphML method of the current GraphElementFactory.
Throws:
GraphMLParseException

parseDocument

public Object parseDocument(Document doc)
                     throws GraphMLParseException
Start parsing a given document.

Parameters:
doc - a document with root node graphml.
Throws:
GraphMLParseException

parseGraphMLNode

public Object parseGraphMLNode(Node graphMLNode)
                        throws GraphMLParseException
Parses the graphml node in a DOM tree.

Parameters:
graphMLNode - a node with value graphml.
Throws:
GraphMLParseException - if something failed

parseGraphNode

protected void parseGraphNode(Node graphNode)
                       throws GraphMLParseException
Called whenever the graph tag in the graphml input is encountered.

Parameters:
graphNode - the DOM node for the graph element
Throws:
GraphMLParseException - if something failed

parsePortNode

protected void parsePortNode(Node portNode)
                      throws GraphMLParseException
Called whenever the port tag in the graphml input is encountered. Currently, this method has no effect.

Parameters:
portNode - the DOM node for the port element
Throws:
GraphMLParseException - if something failed

parseNodeNode

protected void parseNodeNode(Node nodeNode)
                      throws GraphMLParseException
Called whenever the node tag in the graphml input is encountered.

Parameters:
nodeNode - the DOM node for the node element
Throws:
GraphMLParseException - if something failed

parseEdgeNode

protected void parseEdgeNode(Node edgeNode)
                      throws GraphMLParseException
Called whenever the edge tag in the graphml input is encountered.

Parameters:
edgeNode - the DOM node for the edge element
Throws:
GraphMLParseException - if something failed

parseHyperEdgeNode

protected void parseHyperEdgeNode(Node hyperedgeNode)
                           throws GraphMLParseException
Called whenever the hyperedge tag in the graphml input is encountered.

Parameters:
hyperedgeNode - the DOM node for the hyperedge element
Throws:
GraphMLParseException - if something failed

parseEndPointNode

protected void parseEndPointNode(Node endPointNode)
                          throws GraphMLParseException
Called whenever the node tag for a hyperedge is encountered

Parameters:
endPointNode - the DOM node for the endpoint element
Throws:
GraphMLParseException - if something failed

parseKeyNode

protected void parseKeyNode(Node keyNode)
                     throws GraphMLParseException
Called whenever the key tag for a data attribute definition is encountered

Parameters:
keyNode - the DOM node for the key element
Throws:
GraphMLParseException - if something failed

parseDataNodes

protected void parseDataNodes(Map dataNodes,
                              DOMInputHandler handler)
                       throws GraphMLParseException
Called whenever an input handler should parse one or more data tags that are associated with a core graphml element. This method can be called multiple times for the same set of data nodes, if there are multiple input handlers registered

Parameters:
dataNodes - Map that contains as keys a data tag refid, as values a list of data elements that have this refid attribute set
handler - the current input handler
Throws:
GraphMLParseException - if something failed

setContextLookup

public void setContextLookup(Class c,
                             Object o)
Set a lookup value that will be used by all parse contexts that are created by this parser.

Parameters:
c - The class key for the lookup
o - the implementation object
See Also:
GraphMLParseContext.lookup(Class)

createParseContext

protected DOMGraphMLParseContext createParseContext()
Create a new parse context. This implementation fills the context's lookup and property maps

Returns:
a new DOMGraphMLParseContext instance

setContextProperty

public void setContextProperty(String name,
                               Object o)
Set a property value that will be used by all parse contexts that are created by this parser.

Parameters:
name - The name of the property
o - the value of the property
See Also:
GraphMLParseContext.setProperty(String,Object)


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