public class GraphMLWriter extends Object
This class allows for low-level customization of the writing process. Usually, it is used by one of
GraphMLIOHandler's Write methods which calls one the various Write method overloads. It
should rarely be necessary to use this class directly.
GraphMLIOHandler| Constructor and Description |
|---|
GraphMLWriter() |
| Modifier and Type | Method and Description |
|---|---|
void |
addHandleSerializationListener(IEventHandler<HandleSerializationEventArgs> handleSerializationEvent)
Adds the given listener for the
HandleSerialization event that occurs when XML content is about to be
serialized. |
void |
addQueryOutputHandlersListener(IEventHandler<QueryOutputHandlersEventArgs> queryOutputHandlersEvent)
Adds the given listener for the
QueryOutputHandlers event that occurs when IOutputHandlers are queried. |
void |
addQueryReferenceIdListener(IEventHandler<QueryReferenceIdEventArgs> queryReferenceIdEvent)
Adds the given listener for the
QueryReferenceId event that occurs when a reference is queried. |
void |
addWritingListener(IEventHandler<WriteEventArgs> writingEvent)
Adds the given listener for the
Writing event that occurs when the writing of a document is just about to
begin. |
void |
addWrittenListener(IEventHandler<WriteEventArgs> writtenEvent)
Adds the given listener for the
Written event that occurs when the writing of a document has just been
finished. |
protected IWriteContext |
createWriteContext(IGraph graph,
IXmlWriter writer)
Create the initial
IWriteContext instance. |
Iterable<IOutputHandler> |
getOutputHandlers(IWriteContext context,
KeyScope scope)
Dynamically retrieve all
IOutputHandler that should be used for the current write process. |
<T> T |
getSerializationProperty(TypedKey<T> key)
Retrieve a serialization property that has been set by
setSerializationProperty(TypedKey, Object). |
IWriteEvents |
getWriteEvents()
This property allows to access the events in the internal
IWriteEvents implementation. |
protected Object |
lookup(Class type)
Dynamically retrieve an instance of
type. |
protected void |
onHandleSerialization(HandleSerializationEventArgs args)
Fires the
HandleSerialization event. |
protected void |
onQueryOutputHandlers(QueryOutputHandlersEventArgs args)
Fires the
QueryOutputHandlers event. |
protected void |
onQueryReferenceId(QueryReferenceIdEventArgs args)
Fires the
QueryReferenceId event. |
protected void |
onWriting(WriteEventArgs args)
Raises the
Writing event. |
protected void |
onWritten(WriteEventArgs args)
Raises the
Written event. |
void |
removeHandleSerializationListener(IEventHandler<HandleSerializationEventArgs> handleSerializationEvent)
Removes the given listener for the
HandleSerialization event that occurs when XML content is about to be
serialized. |
<T> void |
removeLookup(Class<T> tType)
Remove an implementation of
T that has been set with setLookup(Class, Object). |
void |
removeQueryOutputHandlersListener(IEventHandler<QueryOutputHandlersEventArgs> queryOutputHandlersEvent)
Removes the given listener for the
QueryOutputHandlers event that occurs when
IOutputHandlers are queried. |
void |
removeQueryReferenceIdListener(IEventHandler<QueryReferenceIdEventArgs> queryReferenceIdEvent)
Removes the given listener for the
QueryReferenceId event that occurs when a reference is queried. |
<T> void |
removeSerializationProperty(TypedKey<T> key)
Remove a serialization property that has been set by
setSerializationProperty(TypedKey, Object). |
void |
removeWritingListener(IEventHandler<WriteEventArgs> writingEvent)
Removes the given listener for the
Writing event that occurs when the writing of a document is just about to
begin. |
void |
removeWrittenListener(IEventHandler<WriteEventArgs> writtenEvent)
Removes the given listener for the
Written event that occurs when the writing of a document has just been
finished. |
protected <T> void |
serialize(Type targetType,
IWriteContext context,
T item)
Serialize
item. |
<T> void |
setLookup(Class<T> tType,
T instance)
Register an implementation of
T for use with lookup(Class). |
<T> void |
setSerializationProperty(TypedKey<T> key,
T value)
Set a serialization property that allows to fine tune the write process.
|
void |
write(IGraph graph,
IXmlWriter writer)
Write the GraphML representation of
graph, using writer for the actual XML generation. |
public final void addHandleSerializationListener(IEventHandler<HandleSerializationEventArgs> handleSerializationEvent)
HandleSerialization event that occurs when XML content is about to be
serialized.
Subscribe to this event to provide custom serialization handling for XML content.
The event handlers added to this event are called in inverse order, i.e. handlers that have been added later are called earlier.
The current item is provided by Item.
handleSerializationEvent - The listener to add.GraphMLIOHandler.addHandleSerializationListener(IEventHandler),
removeHandleSerializationListener(IEventHandler)public final void addQueryOutputHandlersListener(IEventHandler<QueryOutputHandlersEventArgs> queryOutputHandlersEvent)
QueryOutputHandlers event that occurs when IOutputHandlers are queried.
Subscribe to this event to dynamically register one or more IOutputHandler instance(s) for a given GraphML
attribute key definition.
The event handlers added to this event are called in inverse order, i.e. handlers that have been added later are called earlier.
If you want to register an IOutputHandler for this GraphML attribute, you can add the handler with
QueryOutputHandlersEventArgs.addOutputHandler(IOutputHandler).
queryOutputHandlersEvent - The listener to add.GraphMLIOHandler.addQueryOutputHandlersListener(IEventHandler),
removeQueryOutputHandlersListener(IEventHandler)public final void addQueryReferenceIdListener(IEventHandler<QueryReferenceIdEventArgs> queryReferenceIdEvent)
QueryReferenceId event that occurs when a reference is queried.
This event can be used to provide names of external references for objects.
These reference targets are not serialized to the GraphML file.
queryReferenceIdEvent - The listener to add.GraphMLIOHandler.addQueryReferenceIdListener(IEventHandler),
removeQueryReferenceIdListener(IEventHandler)public final void addWritingListener(IEventHandler<WriteEventArgs> writingEvent)
Writing event that occurs when the writing of a document is just about to
begin.
This event can be used to register to the fine-grained events available in the
Context's WriteEvents and to configure
the writing process on a per write case.
writingEvent - The listener to add.onWriting(WriteEventArgs),
removeWritingListener(IEventHandler)public final void addWrittenListener(IEventHandler<WriteEventArgs> writtenEvent)
Written event that occurs when the writing of a document has just been
finished.writtenEvent - The listener to add.onWritten(WriteEventArgs),
removeWrittenListener(IEventHandler)protected IWriteContext createWriteContext(IGraph graph, IXmlWriter writer)
IWriteContext instance.graph - The graph that is written.writer - The core IXmlWriter instance that does the actual writing of XML content.IWriteContext instance that is suitable for graph.public Iterable<IOutputHandler> getOutputHandlers(IWriteContext context, KeyScope scope)
IOutputHandler that should be used for the current write process.
Typically, this method is called only indirectly by the write process. This implementation calls
onQueryOutputHandlers(QueryOutputHandlersEventArgs), which in turn raises the QueryOutputHandlers
event.
context - The current write context.scope - The scope to get output handlers for.IOutputHandlers.public <T> T getSerializationProperty(TypedKey<T> key)
setSerializationProperty(TypedKey, Object).
The return value is automatically converted to type T.
T - The target type of the property.key - The key for the property.IWriteContext.getSerializationProperty(TypedKey)public final IWriteEvents getWriteEvents()
IWriteEvents implementation.
You can subscribe to any of the events in the returned IWriteEvents instance to react to various steps in the
writing process
protected Object lookup(Class type)
type.type - The type for which an implementation is needed.type, or null.protected void onHandleSerialization(HandleSerializationEventArgs args)
HandleSerialization event.args - The arguments that get passed to the HandleSerialization event.GraphMLIOHandler.onHandleSerialization(HandleSerializationEventArgs)protected void onQueryOutputHandlers(QueryOutputHandlersEventArgs args)
QueryOutputHandlers event.args - The arguments that get passed to the QueryOutputHandlers event.GraphMLIOHandler.onQueryOutputHandlers(QueryOutputHandlersEventArgs)protected void onQueryReferenceId(QueryReferenceIdEventArgs args)
QueryReferenceId event.args - The arguments that get passed to the QueryReferenceId event.GraphMLIOHandler.onQueryReferenceId(QueryReferenceIdEventArgs)protected void onWriting(WriteEventArgs args)
Writing event.
This method is called just before the writing starts and before DocumentWriting
is called for the first time.
args - The WriteEventArgs instance containing the event data.addWritingListener(IEventHandler)protected void onWritten(WriteEventArgs args)
Written event.
This method is called just before the writing has been finished and after DocumentWritten
is called for the last time.
args - The WriteEventArgs instance containing the event data.addWrittenListener(IEventHandler)public final void removeHandleSerializationListener(IEventHandler<HandleSerializationEventArgs> handleSerializationEvent)
HandleSerialization event that occurs when XML content is about to be
serialized.
Subscribe to this event to provide custom serialization handling for XML content.
The event handlers added to this event are called in inverse order, i.e. handlers that have been added later are called earlier.
The current item is provided by Item.
handleSerializationEvent - The listener to remove.GraphMLIOHandler.addHandleSerializationListener(IEventHandler),
addHandleSerializationListener(IEventHandler)public <T> void removeLookup(Class<T> tType)
T that has been set with setLookup(Class, Object).public final void removeQueryOutputHandlersListener(IEventHandler<QueryOutputHandlersEventArgs> queryOutputHandlersEvent)
QueryOutputHandlers event that occurs when
IOutputHandlers are queried.
Subscribe to this event to dynamically register one or more IOutputHandler instance(s) for a given GraphML
attribute key definition.
The event handlers added to this event are called in inverse order, i.e. handlers that have been added later are called earlier.
If you want to register an IOutputHandler for this GraphML attribute, you can add the handler with
QueryOutputHandlersEventArgs.addOutputHandler(IOutputHandler).
queryOutputHandlersEvent - The listener to remove.GraphMLIOHandler.addQueryOutputHandlersListener(IEventHandler),
addQueryOutputHandlersListener(IEventHandler)public final void removeQueryReferenceIdListener(IEventHandler<QueryReferenceIdEventArgs> queryReferenceIdEvent)
QueryReferenceId event that occurs when a reference is queried.
This event can be used to provide names of external references for objects.
These reference targets are not serialized to the GraphML file.
queryReferenceIdEvent - The listener to remove.GraphMLIOHandler.addQueryReferenceIdListener(IEventHandler),
addQueryReferenceIdListener(IEventHandler)public <T> void removeSerializationProperty(TypedKey<T> key)
setSerializationProperty(TypedKey, Object).key - The key for the property.IWriteContext.getSerializationProperty(TypedKey)public final void removeWritingListener(IEventHandler<WriteEventArgs> writingEvent)
Writing event that occurs when the writing of a document is just about to
begin.
This event can be used to register to the fine-grained events available in the
Context's WriteEvents and to configure
the writing process on a per write case.
writingEvent - The listener to remove.onWriting(WriteEventArgs),
addWritingListener(IEventHandler)public final void removeWrittenListener(IEventHandler<WriteEventArgs> writtenEvent)
Written event that occurs when the writing of a document has just been
finished.writtenEvent - The listener to remove.onWritten(WriteEventArgs),
addWrittenListener(IEventHandler)protected <T> void serialize(Type targetType, IWriteContext context, T item) throws SerializationNotSupportedException
item.
Typically, this method is called only indirectly by calls to IWriteContext.serialize(Type, IWriteContext, Object)
or IWriteContext.serialize(Type, Object). This implementation calls
onHandleSerialization(HandleSerializationEventArgs), which in turn raises the HandleSerialization
event.
SerializationNotSupportedException - SerializationNotSupportedException if item cannot be serialized.T - The desired type of the result.targetType - The desired type of the result.context - The current parse context.item - The object that should be serialized.IWriteContext.serialize(Type, IWriteContext, Object),
IWriteContext.serialize(Type, Object),
addHandleSerializationListener(IEventHandler)public <T> void setLookup(Class<T> tType, T instance)
T for use with lookup(Class).T - The type of instance.tType - The type of instance.instance - The implementation of T for lookup retrieval.public <T> void setSerializationProperty(TypedKey<T> key, T value)
key - The key for the property.value - The property value.IWriteContext.getSerializationProperty(TypedKey)public void write(IGraph graph, IXmlWriter writer) throws IOException
graph, using writer for the actual XML generation.
Typically, this method is called indirectly from
GraphMLIOHandler.write(IGraph, java.io.Writer).
IOExceptiongraph - The graph instance that is populated.writer - The writer that actually writes the XML content.GraphMLIOHandler.write(IGraph, java.io.Writer)