Search this API

y.io.graphml
Class GraphMLHandler

java.lang.Object
  extended by y.io.graphml.GraphMLHandler
Direct Known Subclasses:
Graph2DGraphMLHandler, LayoutGraphMLHandler

public class GraphMLHandler
extends java.lang.Object

Class for reading/writing graphs from/to GraphML format.

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

 

Nested Class Summary
static class GraphMLHandler.BoolDataAcceptorInputHandler
          Simple implementation of AbstractDataAcceptorInputHandler that can read boolean values.
static class GraphMLHandler.BooleanDataProviderOutputHandler
          Simple implementation of AbstractDataProviderOutputHandler that can write boolean values.
static class GraphMLHandler.DoubleDataAcceptorInputHandler
          Simple implementation of AbstractDataAcceptorInputHandler that can read double values.
static class GraphMLHandler.DoubleDataProviderOutputHandler
          Simple implementation of AbstractDataProviderOutputHandler that can write double values.
static class GraphMLHandler.FloatDataAcceptorInputHandler
          Simple implementation of AbstractDataAcceptorInputHandler that can read float values.
static class GraphMLHandler.FloatDataProviderOutputHandler
          Simple implementation of AbstractDataProviderOutputHandler that can write float values.
static interface GraphMLHandler.InputHandlerQueryPredicate
          Predicate interface used for querying the validity of a GraphML key definition
static class GraphMLHandler.IntDataAcceptorInputHandler
          Simple implementation of AbstractDataAcceptorInputHandler that can read int values.
static class GraphMLHandler.IntDataProviderOutputHandler
          Simple implementation of AbstractDataProviderOutputHandler that can write int values.
static class GraphMLHandler.LongDataAcceptorInputHandler
          Simple implementation of AbstractDataAcceptorInputHandler that can read long values.
static class GraphMLHandler.LongDataProviderOutputHandler
          Simple implementation of AbstractDataProviderOutputHandler that can write long values.
static class GraphMLHandler.StringDataAcceptorInputHandler
          Simple implementation of AbstractDataAcceptorInputHandler that can read string values.
static class GraphMLHandler.StringDataProviderOutputHandler
          Simple implementation of AbstractDataProviderOutputHandler that can write string values.
 
Constructor Summary
GraphMLHandler()
           
 
Method Summary
 void addDeserializationHandler(DeserializationHandler listener)
          Register an event listener that can be used to handle DeserializationEvents.
 void addInputDataAcceptor(GraphMLHandler.InputHandlerQueryPredicate keyDefinitionPredicate, DataAcceptor dataAcceptor, DeserializationHandler deserializationCallback)
          Register a DataAcceptor instance for use as an input data target.
 void addInputDataAcceptor(GraphMLHandler.InputHandlerQueryPredicate keyDefinitionPredicate, DataAcceptor dataAcceptor, KeyType valueType)
          Register a DataAcceptor instance for use as an input data target.
 void addInputDataAcceptor(java.lang.String name, DataAcceptor dataAcceptor, KeyScope scope, DeserializationHandler deserializationCallback)
          Register a DataAcceptor instance for use as an input data target for the actual deserialization.
 void addInputDataAcceptor(java.lang.String name, DataAcceptor dataAcceptor, KeyScope scope, KeyType valueType)
          Register a DataAcceptor instance for use as an input data target for the actual deserialization.
 void addInputDataAcceptor(java.lang.String name, DataAcceptor dataAcceptor, KeyType valueType)
          Register a DataAcceptor instance for use as an input data target.
 void addInputDataAcceptor(java.lang.String name, java.lang.Object dataProviderKey, KeyScope scope, KeyType valueType)
          Use a previously registered DataAcceptor instance for use as an input data target for the actual deserialization.
 Future addInputDataAcceptorFuture(GraphMLHandler.InputHandlerQueryPredicate predicate, KeyType valueType)
          Create a Future instance that wraps an DataMap for use as an input data target.
 Future addInputDataAcceptorFuture(java.lang.String name, KeyScope scope, KeyType valueType)
          Create a Future instance that wraps an DataMap for use as an input data target.
 Future addInputDataAcceptorFuture(java.lang.String name, KeyType valueType)
          Create a Future instance that wraps an DataMap for use as an input data target.
 void addInputHandlerProvider(InputHandlerProvider provider)
          Register an event listener that can be used to handle QueryInputHandlersEvents.
 void addNamespace(java.lang.String namespaceURI, java.lang.String shortName)
          Adds a namespace declaration to the header of a GraphML file.
 void addOutputDataProvider(java.lang.String name, DataProvider dataProvider, KeyScope scope, KeyType type)
          Register a DataProvider instance for use as an output data source This methods creates and configures the necessary handler itself.
 void addOutputDataProvider(java.lang.String name, DataProvider dataProvider, KeyScope scope, SerializationHandler serializationCallback)
          Register a DataProvider instance for use as an output data source.
 void addOutputDataProvider(java.lang.String name, java.lang.String uri, DataProvider dataProvider, KeyScope scope, KeyType type)
          Register a DataProvider instance for use as an output data source This methods creates and configures the necessary handler itself.
 void addOutputDataProvider(java.lang.String name, java.lang.String uri, DataProvider dataProvider, KeyScope scope, KeyType type, SerializationHandler serializationCallback)
          Register a DataProvider instance for use as an output data source.
 void addOutputHandlerProvider(OutputHandlerProvider provider)
          Register an event listener that can be used to handle QueryOutputHandlersEvents.
 void addParseEventListener(ParseEventListener listener)
          Register a ParseEventListener.
 void addRegisteredOutputDataProvider(java.lang.String name, KeyScope scope, KeyType type)
          Use DataProvider instance that has been registered on the underlying graph instance as source for the given GraphML attribute.
 void addRegisteredOutputDataProvider(java.lang.String name, java.lang.Object registryTag, KeyScope scope, KeyType type)
          Use DataProvider instance that has been registered on the underlying graph instance as source for the given GraphML attribute.
 void addRegisteredOutputDataProvider(java.lang.String name, java.lang.String uri, java.lang.Object registryTag, KeyScope scope, KeyType type)
          Use DataProvider instance that has been registered on the underlying graph instance as source for the given GraphML attribute.
 void addSchemaLocation(java.lang.String schemaNamespace, java.lang.String schemaLocation)
          Adds a schema location to the header of a GraphML file.
 void addSerializationHandler(SerializationHandler listener)
          Register an event listener that can be used to handle SerializationEvents.
 void addWriteEventListener(WriteEventListener listener)
          Register a WriteEventListener.
protected  void configureDeserializationHandlers(Graph graph, GraphMLParser parser)
          Configure predefined handlers for the DeserializationEvent event.
protected  void configureDeserializationProperties(Graph graph, GraphMLParser parser)
          Configure important deserialization properties of GraphMLHandler.
protected  void configureGraphMLParser(Graph graph, GraphMLParser parser)
          Configures the specified GraphMLParser to handle the given graph.
protected  void configureGraphMLWriter(Graph graph, GraphMLWriter writer)
          Configures the specified GraphMLWriter for writing the given graph.
protected  void configureInputHandlers(Graph graph, GraphMLParser parser)
          Configures default event handlers for the GraphMLParser.fireQueryInputHandlersEvent(y.io.graphml.input.QueryInputHandlersEvent) event.
protected  void configureLookup(Graph graph, GraphMLParser parser)
          Configure the default lookup map of parser.
protected  void configureLookup(Graph graph, GraphMLWriter writer)
          Configure the default lookup map of writer.
protected  void configureNamespaces(GraphMLWriter writer)
          Configures writer to use the namespace declarations set with addNamespace(String, String).
protected  void configureOutputHandlers(Graph graph, GraphMLWriter writer)
          Configures default event handlers for the QueryOutputHandlersEvent event.
protected  void configureParseEvents(Graph graph, GraphMLParser parser)
          Configure the default parse events of parser.
protected  void configureSchemaLocations(GraphMLWriter writer)
          Configures writer to use the schema locations set with addSchemaLocation(String, String).
protected  void configureSerializationHandlers(Graph graph, GraphMLWriter writer)
          Configure the predefined handlers for the SerializationEvent event.
protected  void configureSerializationProperties(Graph graph, GraphMLWriter writer)
          Configure important serialization properties of GraphMLHandler.
protected  void configureWriteEvents(Graph graph, GraphMLWriter writer)
          Configure the default write events of writer.
protected  void configureXMLWriter(XmlWriter writer)
          Configure writer.
protected  GraphElementFactory createGraphElementFactory(GraphMLParser parser, Graph graph)
          Create an GraphElementFactory instance that creates the graph elements for the graph instance.
protected  GraphMLParser createGraphMLParser(Graph graph)
          Creates a suitable instance of GraphMLParser that can handle the given graph.
protected  GraphMLWriter createGraphMLWriter(Graph graph)
          Creates and configures a new GraphMLWriter that is used for writing the specified graph.
protected  XmlWriter createXMLWriter(java.io.OutputStream os, java.lang.String encoding)
          Factory method that creates and configures a suitable XmlWriter implementation that can write the graph to the given OutputStream with the given settings.
protected  XmlWriter createXMLWriter(java.io.Writer writer)
          Factory method that creates and configures a suitable XmlWriter implementation that can write the graph to the given Writer with the given settings
protected  void fireDeserializationEvent(DeserializationEvent event)
          Notifies all registered DeserializationHandler instances of event.
protected  void fireQueryInputHandlersProviders(QueryInputHandlersEvent event)
          Notifies all registered InputHandlerProvider instances of event.
protected  void fireQueryOutputHandlersEvent(QueryOutputHandlersEvent event)
          Notifies all registered OutputHandlerProvider instances of event.
protected  void fireSerializationEvent(SerializationEvent event)
          Notifies all registered SerializationHandler instances of event.
 java.lang.Object getDeserializationProperty(java.lang.Object key)
          Retrieves a deserialization property that has been set using setDeserializationProperty(Object, Object).
static java.lang.String getKeyName(org.w3c.dom.Element keyDefinition)
          Get the attribute name from an GraphML keyDefinition element.
static KeyScope getKeyScope(org.w3c.dom.Element keyDefinition)
          Get the KeyScope from an GraphML keyDefinition element.
static KeyType getKeyType(org.w3c.dom.Element keyDefinition)
          Get the KeyType from an GraphML keyDefinition element.
static java.lang.String getKeyUri(org.w3c.dom.Element keyDefinition)
          Get the attribute URI from an GraphML keyDefinition element.
 java.lang.Object getSerializationProperty(java.lang.Object key)
          Retrieves a serialization property that has been set using setSerializationProperty(Object, Object).
 boolean isClearGraphBeforeRead()
          Whether to clear an existing graph instance before reading If true, an existing graph instance will be cleared before the graph is read into this instance, otherwise the loaded graph will be merged into the existing one.
 boolean isWriteXMLSchema()
          Gets whether schema locations should be written.
static boolean matchesName(org.w3c.dom.Element keyDefinition, java.lang.String name)
          Utility method that checks whether the attr.name attribute in a GraphML key definition matches name.
static boolean matchesScope(org.w3c.dom.Element keyDefinition, KeyScope scope)
          Utility method that checks whether the for attribute in a GraphML key definition matches scope.
static boolean matchesType(org.w3c.dom.Element keyDefinition, KeyType type)
          Utility method that checks whether the attr.type attribute in a GraphML key definition matches type.
static boolean matchesUri(org.w3c.dom.Element keyDefinition, java.lang.String uri)
          Utility method that checks whether the attr.uri attribute in a GraphML key definition matches uri.
protected  void onGraphMLParserHandleDeserialization(DeserializationEvent e)
          Default event listener that is registered to GraphMLParser.addDeserializationHandler(y.io.graphml.input.DeserializationHandler).
protected  void onGraphMLParserQueryInputHandlers(QueryInputHandlersEvent e)
          Default event listener that is registered to GraphMLParser.addInputHandlerProvider(y.io.graphml.input.InputHandlerProvider).
protected  void onGraphMLWriterHandleSerialization(SerializationEvent e)
          Default event listener that is registered to GraphMLWriter.addSerializationHandler(y.io.graphml.output.SerializationHandler).
protected  void onGraphMLWriterQueryOutputHandlers(QueryOutputHandlersEvent e)
          Default event listener that is registered to GraphMLWriter.addOutputHandlerProvider(y.io.graphml.output.OutputHandlerProvider).
 void read(Graph graph, org.w3c.dom.Document doc)
          Read GraphML from an existing XML document.
 void read(Graph graph, java.io.InputStream stream)
          Reads GraphML content from the given input stream and populates the Graph object.
 void removeDeserializationHandler(DeserializationHandler listener)
          Unregister an event listener that has been registered with addDeserializationHandler(DeserializationHandler).
 void removeDeserializationProperty(java.lang.Object key)
          Removes a deserialization property that has been set using setDeserializationProperty(Object, Object).
 void removeInputHandlerProvider(InputHandlerProvider provider)
          Unregister an event listener that has been registered with addInputHandlerProvider(InputHandlerProvider).
 void removeOutputHandlerProvider(OutputHandlerProvider provider)
          Unregister an event listener that has been registered with addOutputHandlerProvider(OutputHandlerProvider).
 void removeParseEventListener(ParseEventListener listener)
          Unregister a ParseEventListener that has been registered with addParseEventListener(ParseEventListener)
 void removeSerializationHandler(SerializationHandler listener)
          Unregister an event listener that has been registered with addSerializationHandler(y.io.graphml.output.SerializationHandler).
 void removeSerializationProperty(java.lang.Object key)
          Removes the serialization property that has been set using setDeserializationProperty(Object, Object).
 void removeWriteEventListener(WriteEventListener listener)
          Unregister a WriteEventListener that has been registered with addWriteEventListener(y.io.graphml.output.WriteEventListener)
 void setClearGraphBeforeRead(boolean value)
          Whether to clear an existing graph instance before reading If set to true, an existing graph instance will be cleared before the graph is read into this instance, otherwise the loaded graph will be merged into the existing one.
 void setDeserializationProperty(java.lang.Object key, java.lang.Object value)
          Sets a deserialization property that allows to fine tune the parse process.
 void setSerializationProperty(java.lang.Object key, java.lang.Object value)
          Sets a serialization property that allows to fine tune the write process.
 void setWriteXMLSchema(boolean value)
          Sets whether schema locations should be written.
 void write(Graph graph, java.io.OutputStream os)
          Writes the given graph Object to the output stream creating a GraphML file.
 void write(Graph graph, java.io.OutputStream os, java.lang.String encoding)
          Writes the given graph Object to the output stream creating a GraphML file.
 void write(Graph graph, java.io.Writer os)
          Writes the given graph Object to the writer creating a GraphML file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphMLHandler

public GraphMLHandler()
Method Detail

isWriteXMLSchema

public boolean isWriteXMLSchema()
Gets whether schema locations should be written.

Returns:
true if schema locations should be written at all.
See Also:
setWriteXMLSchema(boolean), addSchemaLocation(String,String)

setWriteXMLSchema

public void setWriteXMLSchema(boolean value)
Sets whether schema locations should be written.

Parameters:
value - true if schema locations should be written at all.
See Also:
isWriteXMLSchema(), addSchemaLocation(String,String)

isClearGraphBeforeRead

public boolean isClearGraphBeforeRead()
Whether to clear an existing graph instance before reading

If true, an existing graph instance will be cleared before the graph is read into this instance, otherwise the loaded graph will be merged into the existing one.

Default value is true.

Returns:
true if an existing graph instance should be cleared before writing.
See Also:
setClearGraphBeforeRead(boolean)

setClearGraphBeforeRead

public void setClearGraphBeforeRead(boolean value)
Whether to clear an existing graph instance before reading

If set to true, an existing graph instance will be cleared before the graph is read into this instance, otherwise the loaded graph will be merged into the existing one.

Default value is true

Parameters:
value - true if an existing graph instance should be cleared before writing.
See Also:
isClearGraphBeforeRead()

addNamespace

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

Parameters:
namespaceURI - The namespace URI
shortName - The namespace prefix

addSchemaLocation

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

Parameters:
schemaNamespace - The namespace URI for this schema location
schemaLocation - The schema location
See Also:
setWriteXMLSchema(boolean), isWriteXMLSchema()

write

public void write(Graph graph,
                  java.io.OutputStream os)
           throws GraphMLWriteException
Writes the given graph Object to the output stream creating a GraphML file.

This method just calls write(y.base.Graph,java.io.OutputStream,String) with the default "UTF-8" encoding.

Parameters:
graph - The Graph Object that is to be written to a GraphML file.
os - The output stream where the output is written.
Throws:
java.lang.IllegalArgumentException - if graph or os is null.
GraphMLWriteException

write

public void write(Graph graph,
                  java.io.OutputStream os,
                  java.lang.String encoding)
           throws GraphMLWriteException
Writes the given graph Object to the output stream creating a GraphML file.

Parameters:
graph - The Graph Object that is to be written to a GraphML file.
os - The output stream where the output is written.
encoding - The encoding that should be used for writing
Throws:
java.lang.IllegalArgumentException - if graph or os is null.
GraphMLWriteException

write

public void write(Graph graph,
                  java.io.Writer os)
           throws GraphMLWriteException
Writes the given graph Object to the writer creating a GraphML file.

Parameters:
graph - The Graph Object that is to be written to a GraphML file.
os - The writer where the output is written.
Throws:
java.lang.IllegalArgumentException - if graph or os is null.
GraphMLWriteException

addOutputDataProvider

public void addOutputDataProvider(java.lang.String name,
                                  DataProvider dataProvider,
                                  KeyScope scope,
                                  KeyType type)
Register a DataProvider instance for use as an output data source

This methods creates and configures the necessary handler itself.

Parameters:
name - The name of the attribute
dataProvider - the DataProvider that serves as data source
scope - the type of the keys in the DataProvider
type - the type of the values in the DataProvider

addOutputDataProvider

public void addOutputDataProvider(java.lang.String name,
                                  java.lang.String uri,
                                  DataProvider dataProvider,
                                  KeyScope scope,
                                  KeyType type)
Register a DataProvider instance for use as an output data source

This methods creates and configures the necessary handler itself.

Parameters:
name - The name of the attribute
uri - The URI to add to the key definition to disambiguate keys.
dataProvider - the DataProvider that serves as data source
scope - the type of the keys in the DataProvider
type - the type of the values in the DataProvider

addOutputDataProvider

public void addOutputDataProvider(java.lang.String name,
                                  DataProvider dataProvider,
                                  KeyScope scope,
                                  SerializationHandler serializationCallback)
Register a DataProvider instance for use as an output data source.

This method uses a custom SerializationHandler for the actual serialization and implies KeyType.COMPLEX as serialization type.

This methods creates and configures the necessary handler. itself.

Parameters:
name - The name of the attribute.
dataProvider - The DataProvider that serves as data source.
serializationCallback - Custom serialization callback.

addOutputDataProvider

public void addOutputDataProvider(java.lang.String name,
                                  java.lang.String uri,
                                  DataProvider dataProvider,
                                  KeyScope scope,
                                  KeyType type,
                                  SerializationHandler serializationCallback)
Register a DataProvider instance for use as an output data source. This method uses a custom SerializationHandler for the actual serialization.

Parameters:
name - The name of the attribute
uri - The (optional) attribute URI for more precise attribute identification.
dataProvider - The DataProvider that serves as data source.
scope - The scope of the attribute.
type - The KeyType of the attribute.
serializationCallback - Custom serialization callback.

addRegisteredOutputDataProvider

public void addRegisteredOutputDataProvider(java.lang.String name,
                                            KeyScope scope,
                                            KeyType type)
Use DataProvider instance that has been registered on the underlying graph instance as source for the given GraphML attribute.

Parameters:
name - The GraphML name of the attribute, as well as the tag name of the DataProvider for Graph.getDataProvider(Object)
scope - The scope of the attribute.
type - The KeyType of the attribute.

addRegisteredOutputDataProvider

public void addRegisteredOutputDataProvider(java.lang.String name,
                                            java.lang.Object registryTag,
                                            KeyScope scope,
                                            KeyType type)
Use DataProvider instance that has been registered on the underlying graph instance as source for the given GraphML attribute.

Parameters:
name - The GraphML name of the attribute
registryTag - The tag of the DataProvider for Graph.getDataProvider(Object)
scope - The scope of the attribute.
type - The KeyType of the attribute.

addRegisteredOutputDataProvider

public void addRegisteredOutputDataProvider(java.lang.String name,
                                            java.lang.String uri,
                                            java.lang.Object registryTag,
                                            KeyScope scope,
                                            KeyType type)
Use DataProvider instance that has been registered on the underlying graph instance as source for the given GraphML attribute.

Parameters:
name - The GraphML name of the attribute
uri - The URI to add to the key definition to disambiguate keys.
registryTag - The tag of the DataProvider for Graph.getDataProvider(Object)
scope - The scope of the attribute.
type - The KeyType of the attribute.

createGraphMLWriter

protected GraphMLWriter createGraphMLWriter(Graph graph)
Creates and configures a new GraphMLWriter that is used for writing the specified graph.

Calls configureGraphMLWriter(y.base.Graph, y.io.graphml.output.GraphMLWriter) after creating a new GraphMLWriter instance.

Parameters:
graph - The graph that will be written.
Returns:
A new GraphMLWriter instance that is configured for graph.

configureGraphMLWriter

protected void configureGraphMLWriter(Graph graph,
                                      GraphMLWriter writer)
Configures the specified GraphMLWriter for writing the given graph.

Called from createGraphMLWriter(y.base.Graph).

Parameters:
graph - The graph to write.
writer - The writer to configure.

configureLookup

protected void configureLookup(Graph graph,
                               GraphMLWriter writer)
Configure the default lookup map of writer.

This implementation does not configure any specific lookup implementations

Parameters:
graph - The graph that will be written.
writer - The writer to configure.
See Also:
GraphMLWriter.setLookup(Class,Object)

configureSerializationProperties

protected void configureSerializationProperties(Graph graph,
                                                GraphMLWriter writer)
Configure important serialization properties of GraphMLHandler.

Parameters:
graph - The graph to write.
writer - The writer to configure.
See Also:
GraphMLWriter.setSerializationProperty(Object,Object)

setSerializationProperty

public void setSerializationProperty(java.lang.Object key,
                                     java.lang.Object value)
Sets a serialization property that allows to fine tune the write process.

Parameters:
key - The key for the property.
value - The value of the property.
See Also:
getSerializationProperty(Object)

removeSerializationProperty

public void removeSerializationProperty(java.lang.Object key)
Removes the serialization property that has been set using setDeserializationProperty(Object, Object).

Parameters:
key - The key for the property.
See Also:
setSerializationProperty(Object, Object)

getSerializationProperty

public java.lang.Object getSerializationProperty(java.lang.Object key)
Retrieves a serialization property that has been set using setSerializationProperty(Object, Object).

Parameters:
key - The key for the property.
Returns:
the value of the property.
See Also:
setSerializationProperty(Object, Object)

createXMLWriter

protected XmlWriter createXMLWriter(java.io.Writer writer)
                             throws GraphMLWriteException
Factory method that creates and configures a suitable XmlWriter implementation that can write the graph to the given Writer with the given settings

Parameters:
writer - The serialization destination
Returns:
A suitable XmlWriter instance for the serialization
Throws:
GraphMLWriteException

createXMLWriter

protected XmlWriter createXMLWriter(java.io.OutputStream os,
                                    java.lang.String encoding)
                             throws GraphMLWriteException
Factory method that creates and configures a suitable XmlWriter implementation that can write the graph to the given OutputStream with the given settings.

Parameters:
os - The serialization destination
encoding - The encoding of the stream
Returns:
A suitable XmlWriter instance for the serialization
Throws:
GraphMLWriteException

configureXMLWriter

protected void configureXMLWriter(XmlWriter writer)
Configure writer.

This implementation does nothing.

Parameters:
writer - The writer to configure.

configureSchemaLocations

protected void configureSchemaLocations(GraphMLWriter writer)
Configures writer to use the schema locations set with addSchemaLocation(String, String).

In addition to the schema locations configured with addSchemaLocation(String, String), this method also sets the schema location for the core GraphML namespace if not overridden with addSchemaLocation(String, String).

Parameters:
writer - The writer to configure.

configureNamespaces

protected void configureNamespaces(GraphMLWriter writer)
Configures writer to use the namespace declarations set with addNamespace(String, String).

In addition to the namespace declarations configured with addNamespace(String,String), this method also sets the namespace declarations for the core GraphML namespace, the yFile for Java extensions, and the namespaces for Java framework classes if not overridden with addNamespace(String, String).

Parameters:
writer - The writer to configure.

configureOutputHandlers

protected void configureOutputHandlers(Graph graph,
                                       GraphMLWriter writer)
Configures default event handlers for the QueryOutputHandlersEvent event.

This implementation does not configure any output handlers.

Parameters:
graph - The graph that will be written.
writer - The writer that should be configured.

configureSerializationHandlers

protected void configureSerializationHandlers(Graph graph,
                                              GraphMLWriter writer)
Configure the predefined handlers for the SerializationEvent event.

This implementation does not configure any serialization handlers.

Parameters:
graph - The graph that will be written.
writer - The writer to configure.

configureWriteEvents

protected void configureWriteEvents(Graph graph,
                                    GraphMLWriter writer)
Configure the default write events of writer.

This implementation registers a single write event handler that forwards to listeners registered with addWriteEventListener(y.io.graphml.output.WriteEventListener)

Parameters:
graph - The graph that will be written.
writer - The writer to configure.
See Also:
GraphMLWriter.getWriteEventHandler()

addOutputHandlerProvider

public void addOutputHandlerProvider(OutputHandlerProvider provider)
Register an event listener that can be used to handle QueryOutputHandlersEvents.

Registering a listener allows to use OutputHandlers dynamically, depending on the actual graph data. For each write, a QueryOutputHandlersEvent is fired and propagated to all registered event listeners.

Parameters:
provider - Event listener for the QueryInputHandlersEvent
See Also:
fireQueryOutputHandlersEvent(QueryOutputHandlersEvent), removeOutputHandlerProvider(OutputHandlerProvider), GraphMLWriter.addOutputHandlerProvider(OutputHandlerProvider)

removeOutputHandlerProvider

public void removeOutputHandlerProvider(OutputHandlerProvider provider)
Unregister an event listener that has been registered with addOutputHandlerProvider(OutputHandlerProvider).

Parameters:
provider - Event listener for the QueryOutputHandlersEvent
See Also:
fireQueryOutputHandlersEvent(QueryOutputHandlersEvent), addOutputHandlerProvider(OutputHandlerProvider), GraphMLWriter.removeOutputHandlerProvider(OutputHandlerProvider)

fireQueryOutputHandlersEvent

protected void fireQueryOutputHandlersEvent(QueryOutputHandlersEvent event)
                                     throws GraphMLWriteException
Notifies all registered OutputHandlerProvider instances of event.

For each write, a QueryOutputHandlersEvent is fired and propagated to all registered event listeners.

Parameters:
event - The event that has been raised.
Throws:
GraphMLWriteException
See Also:
OutputHandler, OutputHandlerProvider, addOutputHandlerProvider(OutputHandlerProvider), GraphMLWriter.fireQueryOutputHandlersEvent(QueryOutputHandlersEvent)

onGraphMLWriterQueryOutputHandlers

protected void onGraphMLWriterQueryOutputHandlers(QueryOutputHandlersEvent e)
                                           throws GraphMLWriteException
Default event listener that is registered to GraphMLWriter.addOutputHandlerProvider(y.io.graphml.output.OutputHandlerProvider).

This implementation just propagates the event e to all registered event handlers by calling fireQueryOutputHandlersEvent(y.io.graphml.output.QueryOutputHandlersEvent).

Parameters:
e - The event data.
Throws:
GraphMLWriteException

addSerializationHandler

public void addSerializationHandler(SerializationHandler listener)
Register an event listener that can be used to handle SerializationEvents.

Registering a listener allows to use custom serialization code.

Parameters:
listener - Event listener for the SerializationEvent
See Also:
fireSerializationEvent(SerializationEvent), removeSerializationHandler(y.io.graphml.output.SerializationHandler), GraphMLWriter.addSerializationHandler(y.io.graphml.output.SerializationHandler)

removeSerializationHandler

public void removeSerializationHandler(SerializationHandler listener)
Unregister an event listener that has been registered with addSerializationHandler(y.io.graphml.output.SerializationHandler).

Parameters:
listener - Event listener for the SerializationEvent
See Also:
fireSerializationEvent(SerializationEvent), addSerializationHandler(y.io.graphml.output.SerializationHandler), GraphMLWriter.removeSerializationHandler(y.io.graphml.output.SerializationHandler)

fireSerializationEvent

protected void fireSerializationEvent(SerializationEvent event)
                               throws GraphMLWriteException
Notifies all registered SerializationHandler instances of event.

Usually, this method is called indirectly through calls to GraphMLWriteContext.serialize(Object) to write the XML representation of an object.

Parameters:
event - The event that has been raised.
Throws:
GraphMLWriteException
See Also:
SerializationHandler, addSerializationHandler(y.io.graphml.output.SerializationHandler), GraphMLWriteContext.serialize(Object), GraphMLWriter.fireSerializationEvent(y.io.graphml.output.SerializationEvent)

onGraphMLWriterHandleSerialization

protected void onGraphMLWriterHandleSerialization(SerializationEvent e)
                                           throws GraphMLWriteException
Default event listener that is registered to GraphMLWriter.addSerializationHandler(y.io.graphml.output.SerializationHandler).

This implementation just propagates the event e to all registered event handlers by calling fireSerializationEvent(y.io.graphml.output.SerializationEvent).

Parameters:
e - The event data.
Throws:
GraphMLWriteException

addWriteEventListener

public void addWriteEventListener(WriteEventListener listener)
Register a WriteEventListener.

Parameters:
listener - The listener to add.
See Also:
removeWriteEventListener(y.io.graphml.output.WriteEventListener)

removeWriteEventListener

public void removeWriteEventListener(WriteEventListener listener)
Unregister a WriteEventListener that has been registered with addWriteEventListener(y.io.graphml.output.WriteEventListener)

Parameters:
listener - The listener to remove.
See Also:
addWriteEventListener(y.io.graphml.output.WriteEventListener)

read

public void read(Graph graph,
                 java.io.InputStream stream)
          throws GraphMLParseException
Reads GraphML content from the given input stream and populates the Graph object.

Parameters:
graph - The Graph Object that is to be populated from the stream.
stream - The input stream that holds the GraphML file to be read.
Throws:
java.lang.IllegalArgumentException - stream or graph are null.
GraphMLParseException

read

public void read(Graph graph,
                 org.w3c.dom.Document doc)
          throws GraphMLParseException
Read GraphML from an existing XML document.

Parameters:
graph - The Graph Object that is to be populated from the document.
doc - The XML document.
Throws:
java.lang.IllegalArgumentException - if doc or graph are null.
GraphMLParseException

addInputDataAcceptor

public void addInputDataAcceptor(java.lang.String name,
                                 DataAcceptor dataAcceptor,
                                 KeyType valueType)
Register a DataAcceptor instance for use as an input data target.

This methods creates and configures the necessary handler itself.

Parameters:
valueType - The type of the DataAcceptor values
name - The name of the attribute
dataAcceptor - the DataAcceptor that serves as data target

addInputDataAcceptor

public void addInputDataAcceptor(GraphMLHandler.InputHandlerQueryPredicate keyDefinitionPredicate,
                                 DataAcceptor dataAcceptor,
                                 KeyType valueType)
Register a DataAcceptor instance for use as an input data target.

This methods creates and configures the necessary handler itself.

Parameters:
keyDefinitionPredicate - The predicate function that will determine whether to create an InputHandler for the given key definition.
dataAcceptor - the DataAcceptor that serves as data source
valueType - The type of the DataAcceptor values

addInputDataAcceptor

public void addInputDataAcceptor(java.lang.String name,
                                 DataAcceptor dataAcceptor,
                                 KeyScope scope,
                                 DeserializationHandler deserializationCallback)
Register a DataAcceptor instance for use as an input data target for the actual deserialization.

This methods creates and configures the necessary handler itself.

Parameters:
name - The name of the attribute
dataAcceptor - the DataAcceptor that serves as data source
scope - The type of the DataAcceptor keys
deserializationCallback - custom deserialization callback.

addInputDataAcceptor

public void addInputDataAcceptor(java.lang.String name,
                                 DataAcceptor dataAcceptor,
                                 KeyScope scope,
                                 KeyType valueType)
Register a DataAcceptor instance for use as an input data target for the actual deserialization.

This methods creates and configures the necessary handler itself.

Parameters:
name - The name of the attribute
dataAcceptor - the DataAcceptor that serves as data source
scope - The type of the DataAcceptor keys
valueType - The type of the DataAcceptor values

addInputDataAcceptor

public void addInputDataAcceptor(java.lang.String name,
                                 java.lang.Object dataProviderKey,
                                 KeyScope scope,
                                 KeyType valueType)
Use a previously registered DataAcceptor instance for use as an input data target for the actual deserialization.

This methods creates and configures the necessary handler itself. It is expects that a DataAcceptor instance is registered under the key with Graph.addDataProvider(Object,y.base.DataProvider). This typically means that the instance is a DataMap, such as a NodeMap or EdgeMap.

Parameters:
name - The name of the attribute
dataProviderKey - the DataAcceptor that serves as data source
scope - The type of the DataAcceptor keys
valueType - The type of the DataAcceptor values

addInputDataAcceptor

public void addInputDataAcceptor(GraphMLHandler.InputHandlerQueryPredicate keyDefinitionPredicate,
                                 DataAcceptor dataAcceptor,
                                 DeserializationHandler deserializationCallback)
Register a DataAcceptor instance for use as an input data target. This method uses a DeserializationHandler for the actual deserialization.

This methods creates and configures the necessary handler itself.

Parameters:
keyDefinitionPredicate - The predicate function that will determine whether to create an InputHandler for the given key definition.
dataAcceptor - the DataAcceptor that serves as data source
deserializationCallback - custom deserialization callback.

addInputDataAcceptorFuture

public Future addInputDataAcceptorFuture(java.lang.String name,
                                         KeyType valueType)
Create a Future instance that wraps an DataMap for use as an input data target.

The return value will only contain a value if a matching GraphML attribute has been read, which can be queried with Future.hasValue This methods creates and configures the necessary handler itself.

Parameters:
name - The name of the attribute
valueType - The type of the DataAcceptor values
Returns:
A Future instance that wraps an DataMap that actually holds the data.

addInputDataAcceptorFuture

public Future addInputDataAcceptorFuture(java.lang.String name,
                                         KeyScope scope,
                                         KeyType valueType)
Create a Future instance that wraps an DataMap for use as an input data target.

The return value will only contain a value if a matching GraphML attribute has been read, which can be queried with Future.hasValue This methods creates and configures the necessary handler itself.

Parameters:
name - The name of the attribute.
valueType - The type of the DataAcceptor values.
scope - The scope of the attribute.
Returns:
A Future instance that wraps an DataMap that actually holds the data.

addInputDataAcceptorFuture

public Future addInputDataAcceptorFuture(GraphMLHandler.InputHandlerQueryPredicate predicate,
                                         KeyType valueType)
Create a Future instance that wraps an DataMap for use as an input data target.

The return value will only contain a value if a matching GraphML attribute has been read, which can be queried with Future.hasValue This methods creates and configures the necessary handler itself.

Parameters:
predicate - The predicate that will determine whether to create an InputHandler for the given key definition.
valueType - The type of the DataAcceptor values.
Returns:
A Future instance that wraps an DataMap that actually holds the data.

matchesName

public static boolean matchesName(org.w3c.dom.Element keyDefinition,
                                  java.lang.String name)
Utility method that checks whether the attr.name attribute in a GraphML key definition matches name.

Parameters:
keyDefinition - The key definition element to check.
name - The name to check.
Returns:
true iff the key definition contains a matching attr.name attribute or if name is null.

matchesUri

public static boolean matchesUri(org.w3c.dom.Element keyDefinition,
                                 java.lang.String uri)
Utility method that checks whether the attr.uri attribute in a GraphML key definition matches uri.

Parameters:
keyDefinition - The key definition element to check.
uri - The URI to check.
Returns:
true iff the key definition contains a matching attr.uri attribute or if uri is null.

matchesType

public static boolean matchesType(org.w3c.dom.Element keyDefinition,
                                  KeyType type)
Utility method that checks whether the attr.type attribute in a GraphML key definition matches type.

Parameters:
keyDefinition - The key definition element to check.
type - The attribute type to check.
Returns:
true iff the key definition contains a matching attr.type attribute.

matchesScope

public static boolean matchesScope(org.w3c.dom.Element keyDefinition,
                                   KeyScope scope)
Utility method that checks whether the for attribute in a GraphML key definition matches scope.

Parameters:
keyDefinition - The key definition element to check.
scope - The attribute scope to check.
Returns:
true iff the key definition contains a matching for attribute.

getKeyScope

public static KeyScope getKeyScope(org.w3c.dom.Element keyDefinition)
Get the KeyScope from an GraphML keyDefinition element.

If no for attribute is present, this method returns KeyScope.ALL.

Parameters:
keyDefinition - The GraphML key definition to parse.
Returns:
The KeyScope from keyDefinition.

getKeyType

public static KeyType getKeyType(org.w3c.dom.Element keyDefinition)
Get the KeyType from an GraphML keyDefinition element.

If no attr.type attribute is present, this method returns KeyType.COMPLEX.

Parameters:
keyDefinition - The GraphML key definition to parse.
Returns:
The KeyType from keyDefinition.

getKeyName

public static java.lang.String getKeyName(org.w3c.dom.Element keyDefinition)
Get the attribute name from an GraphML keyDefinition element.

If no attr.name attribute is present, this method returns an empty string.

Parameters:
keyDefinition - The GraphML key definition to parse.
Returns:
The attribute name from keyDefinition.

getKeyUri

public static java.lang.String getKeyUri(org.w3c.dom.Element keyDefinition)
Get the attribute URI from an GraphML keyDefinition element.

If no attr.uri attribute is present, this method returns an empty string.

Parameters:
keyDefinition - The GraphML key definition to parse.
Returns:
The attribute URI from keyDefinition.

createGraphElementFactory

protected GraphElementFactory createGraphElementFactory(GraphMLParser parser,
                                                        Graph graph)
Create an GraphElementFactory instance that creates the graph elements for the graph instance.

Parameters:
parser - The parser to use.
graph - The graph that is populated.
Returns:
An GraphElementFactory instance that is configured for the given parameters.

createGraphMLParser

protected GraphMLParser createGraphMLParser(Graph graph)
Creates a suitable instance of GraphMLParser that can handle the given graph.

Calls configureGraphMLParser(y.base.Graph, y.io.graphml.input.GraphMLParser) after creating a new GraphMLParser instance.

Parameters:
graph - The graph that should be filled by this instance
Returns:
a suitable instance of GraphMLParser that can handle the given graph

configureGraphMLParser

protected void configureGraphMLParser(Graph graph,
                                      GraphMLParser parser)
Configures the specified GraphMLParser to handle the given graph.

Called from createGraphMLParser(y.base.Graph).

Parameters:
graph - The graph that should be filled by this instance.
parser - The parser to configure.

configureParseEvents

protected void configureParseEvents(Graph graph,
                                    GraphMLParser parser)
Configure the default parse events of parser.

This implementation registers a single parse event handler that forwards to listeners registered with addParseEventListener(y.io.graphml.input.ParseEventListener)

Parameters:
graph - The graph that will be populated.
parser - The parser to configure.

configureLookup

protected void configureLookup(Graph graph,
                               GraphMLParser parser)
Configure the default lookup map of parser.

This implementation does not configure any specific lookup implementations

Parameters:
graph - The graph that will be populated.
parser - The parser to configure.
See Also:
GraphMLParser.setLookup(Class,Object)

configureInputHandlers

protected void configureInputHandlers(Graph graph,
                                      GraphMLParser parser)
Configures default event handlers for the GraphMLParser.fireQueryInputHandlersEvent(y.io.graphml.input.QueryInputHandlersEvent) event.

This implementation does not configure any input handlers.

Parameters:
parser - The parser that should be configured.

configureDeserializationHandlers

protected void configureDeserializationHandlers(Graph graph,
                                                GraphMLParser parser)
Configure predefined handlers for the DeserializationEvent event.

This implementation does not configure any serialization handlers.

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

configureDeserializationProperties

protected void configureDeserializationProperties(Graph graph,
                                                  GraphMLParser parser)
Configure important deserialization properties of GraphMLHandler.

Parameters:
graph - The graph to parse.
parser - The parser to configure.
See Also:
GraphMLParser.setDeserializationProperty(Object,Object)

setDeserializationProperty

public void setDeserializationProperty(java.lang.Object key,
                                       java.lang.Object value)
Sets a deserialization property that allows to fine tune the parse process.

Parameters:
key - The key for the property.
value - The value of the property.
See Also:
getDeserializationProperty(Object)

removeDeserializationProperty

public void removeDeserializationProperty(java.lang.Object key)
Removes a deserialization property that has been set using setDeserializationProperty(Object, Object).

Parameters:
key - The key for the property.
See Also:
setDeserializationProperty(Object, Object)

getDeserializationProperty

public java.lang.Object getDeserializationProperty(java.lang.Object key)
Retrieves a deserialization property that has been set using setDeserializationProperty(Object, Object).

Parameters:
key - The key for the property.
Returns:
the value of the property.
See Also:
setDeserializationProperty(Object, Object)

addInputHandlerProvider

public void addInputHandlerProvider(InputHandlerProvider provider)
Register an event listener that can be used to handle QueryInputHandlersEvents.

Registering a listener allows to use InputHandlers dynamically, depending on the actual input. For each key definition, a QueryInputHandlersEvent is fired and propagated to all registered event listeners.

Parameters:
provider - Event listener for the QueryInputHandlersEvent
See Also:
fireQueryInputHandlersProviders(QueryInputHandlersEvent), removeInputHandlerProvider(InputHandlerProvider), GraphMLParser.addInputHandlerProvider(InputHandlerProvider)

removeInputHandlerProvider

public void removeInputHandlerProvider(InputHandlerProvider provider)
Unregister an event listener that has been registered with addInputHandlerProvider(InputHandlerProvider).

Parameters:
provider - Event listener for the QueryInputHandlersEvent
See Also:
fireQueryInputHandlersProviders(QueryInputHandlersEvent), addInputHandlerProvider(InputHandlerProvider), GraphMLParser.removeInputHandlerProvider(InputHandlerProvider)

fireQueryInputHandlersProviders

protected void fireQueryInputHandlersProviders(QueryInputHandlersEvent event)
                                        throws GraphMLParseException
Notifies all registered InputHandlerProvider instances of event.

For each graphml key definition, a QueryInputHandlersEvent is fired and propagated to all registered event listeners.

Parameters:
event - The event that has been raised.
Throws:
GraphMLParseException
See Also:
InputHandler, InputHandlerProvider, addInputHandlerProvider(InputHandlerProvider), GraphMLParser.fireQueryInputHandlersEvent(QueryInputHandlersEvent)

onGraphMLParserQueryInputHandlers

protected void onGraphMLParserQueryInputHandlers(QueryInputHandlersEvent e)
                                          throws GraphMLParseException
Default event listener that is registered to GraphMLParser.addInputHandlerProvider(y.io.graphml.input.InputHandlerProvider).

This implementation just propagates the event e to all registered event handlers by calling fireQueryInputHandlersProviders(y.io.graphml.input.QueryInputHandlersEvent).

Parameters:
e - The event data.
Throws:
GraphMLParseException

addDeserializationHandler

public void addDeserializationHandler(DeserializationHandler listener)
Register an event listener that can be used to handle DeserializationEvents.

Registering a listener allows to use custom deserialization code.

Parameters:
listener - Event listener for the DeserializationEvent
See Also:
fireDeserializationEvent(DeserializationEvent), removeDeserializationHandler(DeserializationHandler), GraphMLParser.addDeserializationHandler(DeserializationHandler)

removeDeserializationHandler

public void removeDeserializationHandler(DeserializationHandler listener)
Unregister an event listener that has been registered with addDeserializationHandler(DeserializationHandler).

Parameters:
listener - Event listener for the DeserializationEvent
See Also:
fireDeserializationEvent(DeserializationEvent), addDeserializationHandler(DeserializationHandler), GraphMLParser.removeDeserializationHandler(DeserializationHandler)

fireDeserializationEvent

protected void fireDeserializationEvent(DeserializationEvent event)
                                 throws GraphMLParseException
Notifies all registered DeserializationHandler instances of event.

Usually, this method is called indirectly through calls to GraphMLParseContext.deserialize(GraphMLParseContext,Node,Class) to parse Xml content to an object.

Parameters:
event - The event that has been raised.
Throws:
GraphMLParseException
See Also:
DeserializationHandler, addDeserializationHandler(DeserializationHandler), GraphMLParseContext.deserialize(GraphMLParseContext,Node,Class), GraphMLParser.fireDeserializationEvent(DeserializationEvent)

onGraphMLParserHandleDeserialization

protected void onGraphMLParserHandleDeserialization(DeserializationEvent e)
                                             throws GraphMLParseException
Default event listener that is registered to GraphMLParser.addDeserializationHandler(y.io.graphml.input.DeserializationHandler).

This implementation just propagates the event e to all registered event handlers by calling fireDeserializationEvent(y.io.graphml.input.DeserializationEvent).

Parameters:
e - The event data.
Throws:
GraphMLParseException

addParseEventListener

public void addParseEventListener(ParseEventListener listener)
Register a ParseEventListener.

Parameters:
listener - The listener to add.
See Also:
removeParseEventListener(ParseEventListener)

removeParseEventListener

public void removeParseEventListener(ParseEventListener listener)
Unregister a ParseEventListener that has been registered with addParseEventListener(ParseEventListener)

Parameters:
listener - The listener to remove.
See Also:
addParseEventListener(ParseEventListener)

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