Search this API

y.io.graphml.output
Class GraphMLWriter

java.lang.Object
  extended by y.io.graphml.output.GraphMLWriter

public class GraphMLWriter
extends java.lang.Object

Writer class for GraphML.

This class allows for low-level customization of the writing process. Usually, it is used by one of GraphMLHandler's write methods which calls one the various write method overloads. It should rarely be necessary to use this class directly.

See Also:
GraphMLHandler
 

Constructor Summary
GraphMLWriter()
           
 
Method Summary
 void addOutputHandlerProvider(OutputHandlerProvider provider)
          Register an event listener that can be used to handle QueryOutputHandlersEvents.
 void addSerializationHandler(SerializationHandler listener)
          Register an event listener that can be used to handle SerializationEvents.
protected  void configureDefaultOutputHandlers()
          Register default event handlers for the QueryOutputHandlersEvent event.
protected  void configureDefaultSerializationHandlers()
          Register default event handlers for the fireSerializationEvent(y.io.graphml.output.SerializationEvent) event.
protected  GraphMLWriteContext createWriteContext(Graph graph, XmlWriter writer)
          Create the initial GraphMLWriteContext instance.
protected  void fireQueryOutputHandlersEvent(QueryOutputHandlersEvent event)
          Notifies all registered OutputHandlerProvider instances of event.
protected  void fireSerializationEvent(SerializationEvent event)
          Notifies all registered SerializationHandler instances of event.
protected  java.util.Map getOutputHandlers(GraphMLWriteContext context)
          Dynamically retrieve all OutputHandler that should be used for the current write process.
 java.lang.Object getSerializationProperty(java.lang.Object key)
          Retrieve a serialization property that has been set by setSerializationProperty(Object,Object).
 WriteEventHandler getWriteEventHandler()
          Return a WriteEventHandler that can be used to subscribe to various events in the write process.
protected  java.lang.Object lookup(java.lang.Class type)
          Dynamically retrieve an instance of type.
 void removeLookup(java.lang.Class t)
          Remove an implementation oft that has been set with setLookup(Class,Object).
 void removeOutputHandlerProvider(OutputHandlerProvider provider)
          Unregister an event listener that has been registered with addOutputHandlerProvider(OutputHandlerProvider).
 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)
          Remove a serialization property that has been set by setSerializationProperty(Object,Object).
protected  void serialize(GraphMLWriteContext context, java.lang.Object item, java.lang.Class serializationType)
          Serialize item to XML content.
 void setLookup(java.lang.Class t, java.lang.Object instance)
          Register an initial implementation of t for use with Lookup.
 void setSerializationProperty(java.lang.Object key, java.lang.Object value)
          Set an initial serialization property that allows to fine tune the write process.
 void write(Graph graph, XmlWriter writer)
          Write the GraphML representation of graph, Typically, this method is called indirectly from GraphMLHandler.write(Graph,java.io.OutputStream) and it's overloads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphMLWriter

public GraphMLWriter()
Method Detail

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.

Usually, this method should not be used directly, register event listeners with GraphMLHandler.addOutputHandlerProvider(OutputHandlerProvider) on an GraphMLHandler instance instead.

Parameters:
provider - Event listener for the QueryInputHandlersEvent
See Also:
fireQueryOutputHandlersEvent(QueryOutputHandlersEvent), removeOutputHandlerProvider(OutputHandlerProvider), GraphMLHandler.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), GraphMLHandler.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), GraphMLHandler.fireQueryOutputHandlersEvent(QueryOutputHandlersEvent)

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.

Usually, this method should not be used directly, register event listeners with GraphMLHandler.addSerializationHandler(SerializationHandler) on an GraphMLHandler instance instead.

Parameters:
listener - Event listener for the SerializationEvent
See Also:
fireSerializationEvent(SerializationEvent), removeSerializationHandler(y.io.graphml.output.SerializationHandler), GraphMLHandler.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), GraphMLHandler.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), GraphMLHandler.fireSerializationEvent(y.io.graphml.output.SerializationEvent)

configureDefaultSerializationHandlers

protected void configureDefaultSerializationHandlers()
Register default event handlers for the fireSerializationEvent(y.io.graphml.output.SerializationEvent) event.

This implementation does not register any default event handlers

See Also:
GraphMLHandler.configureSerializationHandlers(y.base.Graph,y.io.graphml.output.GraphMLWriter)

configureDefaultOutputHandlers

protected void configureDefaultOutputHandlers()
Register default event handlers for the QueryOutputHandlersEvent event.

This implementation does not register any default event handlers

See Also:
GraphMLHandler.configureOutputHandlers(y.base.Graph,GraphMLWriter)

getOutputHandlers

protected java.util.Map getOutputHandlers(GraphMLWriteContext context)
                                   throws GraphMLWriteException
Dynamically retrieve all OutputHandler that should be used for the current write process.

Typically, this method is called only indirectly by the write process. This implementation calls fireQueryOutputHandlersEvent(QueryOutputHandlersEvent), which in turn raises the QueryOutputHandlersEvent event.

Parameters:
context - The current write context.
Returns:
A dictionary with KeyScopes as keys and a list of OutputHandler for each scope as values.
Throws:
GraphMLWriteException

serialize

protected void serialize(GraphMLWriteContext context,
                         java.lang.Object item,
                         java.lang.Class serializationType)
                  throws GraphMLWriteException
Serialize item to XML content.

Typically, this method is called only indirectly by calls to one of GraphMLWriteContext's serialize . * methods. This implementation calls fireSerializationEvent(y.io.graphml.output.SerializationEvent).

Parameters:
context - The current write context.
item - The object should be serialized.
Throws:
GraphMLWriteException
See Also:
GraphMLWriteContext.serialize(Object), GraphMLWriteContext.serialize(GraphMLWriteContext, Object, Class)

setSerializationProperty

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

To dynamically set or change property values during the write process, create a new ChildWriteContext and set the property with the corresponding property handling methods.

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

removeSerializationProperty

public void removeSerializationProperty(java.lang.Object key)
Remove a serialization property that has been set by setSerializationProperty(Object,Object).

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

getSerializationProperty

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

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

setLookup

public void setLookup(java.lang.Class t,
                      java.lang.Object instance)
Register an initial implementation of t for use with Lookup.

To dynamically modify lookup behaviour during the write process, create a new ChildWriteContext and use the corresponding lookup handling methods.

Parameters:
t - The type for which an implementation should be registered
instance - The implementation of t for lookup retrieval.
See Also:
lookup, Lookup.lookup(Class)

removeLookup

public void removeLookup(java.lang.Class t)
Remove an implementation oft that has been set with setLookup(Class,Object).

To dynamically modify lookup behaviour during the parse process, create a new ChildWriteContext and use the corresponding lookup handling methods.

Parameters:
t - The type for which an implementation should be removed
See Also:
setLookup(Class,Object), lookup, Lookup.lookup(Class)

lookup

protected java.lang.Object lookup(java.lang.Class type)
Dynamically retrieve an instance of type.

Parameters:
type - The type for which an implementation is needed.
Returns:
An implementation of type, or null.
See Also:
Lookup.lookup(Class), setLookup(Class,Object)

createWriteContext

protected GraphMLWriteContext createWriteContext(Graph graph,
                                                 XmlWriter writer)
Create the initial GraphMLWriteContext instance.

Parameters:
graph - The graph that is written.
writer - The core XmlWriter instance that does the actual writing of XML content.
Returns:
An GraphMLWriteContext instance that is suitable for graph.

write

public void write(Graph graph,
                  XmlWriter writer)
           throws GraphMLWriteException
Write the GraphML representation of graph,

Typically, this method is called indirectly from GraphMLHandler.write(Graph,java.io.OutputStream) and it's overloads.

Parameters:
graph - The graph instance that is populated.
writer - The writer that actually writes the XML content.
Throws:
GraphMLWriteException
See Also:
GraphMLHandler.write(Graph,java.io.OutputStream), GraphMLHandler.write(Graph,java.io.OutputStream,String), GraphMLHandler.write(Graph,java.io.Writer)

getWriteEventHandler

public WriteEventHandler getWriteEventHandler()
Return a WriteEventHandler that can be used to subscribe to various events in the write process.

Returns:
A WriteEventHandler implementation.

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