Search this API

y.io.graphml.output
Class ChildWriteContext

java.lang.Object
  extended by y.io.graphml.output.ChildWriteContext
All Implemented Interfaces:
Lookup, GraphMLWriteContext

public class ChildWriteContext
extends java.lang.Object
implements GraphMLWriteContext

An GraphMLWriteContext implementation for use in the context of GraphMLWriter that wraps a given instance and delegates most of the calls to it but allows for modifying setLookup(Class,Object) and setSerializationProperty(Object,Object).

 

Constructor Summary
ChildWriteContext(GraphMLWriteContext parentContext)
          Initializes a new instance of the ChildWriteContext class that delegates to the given parent context.
ChildWriteContext(GraphMLWriteContext parentContext, java.lang.Object currentObject)
          Initializes a new instance of the ChildWriteContext class that delegates to the provided context and has the getCurrentObject() set to the given value.
 
Method Summary
 java.lang.Object getCurrentObject()
          Returns the most current (i.e. the last element) within the container hierarchy as it is returned by GraphMLWriteContext.getObjectStack()
 Graph getGraph()
          Returns the currently active graph object
 java.util.Collection getObjectStack()
          Returns the current nesting of graphs and graph elements.
 GraphMLWriteContext getParentContext()
          Gets the parent context to which most calls are delegated.
 java.lang.Object getSerializationProperty(java.lang.Object key)
          Get a property value that specifies information about how to handle specific cases
 WriteEventHandler getWriteEvents()
          Returns an implementation of WriteEventHandler that allows to subscribe to various events in the write process.
 XmlWriter getWriter()
          Gets the core xml writer.
 java.lang.Object lookup(java.lang.Class type)
          Returns an instance that implements the given type or null.
 void removeLookup(java.lang.Class t)
          Removes a local lookup override that has been added.
 void removeSerializationProperty(java.lang.Object key)
          Removes a previously locally setSerializationProperty(Object,Object) serialization property.
 void serialize(GraphMLWriteContext context, java.lang.Object item, java.lang.Class serializationType)
          Serialize item to an XML representation.
 void serialize(java.lang.Object item)
          Serialize item to an XML representation.
 void setLookup(java.lang.Class t, java.lang.Object value)
          Adds another lookup result to the local lookup override.
 void setSerializationProperty(java.lang.Object key, java.lang.Object value)
          Sets the local serialization property for the given key to the value.
 void setWriter(XmlWriter value)
          Sets the core xml writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChildWriteContext

public ChildWriteContext(GraphMLWriteContext parentContext,
                         java.lang.Object currentObject)
Initializes a new instance of the ChildWriteContext class that delegates to the provided context and has the getCurrentObject() set to the given value.

Since this constructor updates the object stack, it should not be used outside the core GraphML element writing framework.

If currentObject is a Graph instance, the getGraph() property is also updated accordingly.

Parameters:
parentContext - The parent context to delegate calls to.
currentObject - The current Object to assign to getCurrentObject().
See Also:
getObjectStack(), getCurrentObject(), getGraph()

ChildWriteContext

public ChildWriteContext(GraphMLWriteContext parentContext)
Initializes a new instance of the ChildWriteContext class that delegates to the given parent context.

This constructor does not change the object stack.

Parameters:
parentContext - The parent context.
Method Detail

lookup

public java.lang.Object lookup(java.lang.Class type)
Description copied from interface: Lookup
Returns an instance that implements the given type or null.

Typically, this method will be called in order to obtain a different view or aspect of the current instance. This is quite similar to casting or compile time constraints. An instance implementing this method is not required to return non-null implementations for the types, nor does it have to return the same instance any time. Additionally, it depends on the type and context whether the instance returned stays up to date or needs to be retrieved again for subsequent use.

Specified by:
lookup in interface Lookup
Parameters:
type - the type for which an instance shall be returned
Returns:
an instance that is assignable to type or null

setLookup

public void setLookup(java.lang.Class t,
                      java.lang.Object value)
Adds another lookup result to the local lookup override.

Parameters:
value - The value to provide for queries to t.
See Also:
removeLookup(Class), lookup(Class)

removeLookup

public void removeLookup(java.lang.Class t)
Removes a local lookup override that has been added.

Parameters:
t - The type to remove from the local lookup.
See Also:
setLookup(Class,Object), lookup(Class)

getObjectStack

public java.util.Collection getObjectStack()
Description copied from interface: GraphMLWriteContext
Returns the current nesting of graphs and graph elements.

The list contains the user objects which correspond to the graphml elements.

Specified by:
getObjectStack in interface GraphMLWriteContext
Returns:
A read-only view on the current nesting.

getCurrentObject

public java.lang.Object getCurrentObject()
Description copied from interface: GraphMLWriteContext
Returns the most current (i.e. the last element) within the container hierarchy as it is returned by GraphMLWriteContext.getObjectStack()

Specified by:
getCurrentObject in interface GraphMLWriteContext
Returns:
The current (i.e. topmost) graph element that is written.

getWriteEvents

public WriteEventHandler getWriteEvents()
Description copied from interface: GraphMLWriteContext
Returns an implementation of WriteEventHandler that allows to subscribe to various events in the write process.

Specified by:
getWriteEvents in interface GraphMLWriteContext
Returns:
A WriteEventHandler instance.

getParentContext

public GraphMLWriteContext getParentContext()
Gets the parent context to which most calls are delegated.

Returns:
The parent context.

getWriter

public XmlWriter getWriter()
Gets the core xml writer.

Specified by:
getWriter in interface GraphMLWriteContext
Returns:
The XmlWriter instance used for actual XML generation.
See Also:
setWriter(XmlWriter)

setWriter

public void setWriter(XmlWriter value)
Sets the core xml writer.

If a null writer is set, this implementation will delegate to the getParentContext()'s GraphMLWriteContext.getWriter().

Parameters:
value - The XmlWriter instance used for actual XML generation.
See Also:
getWriter()

getGraph

public Graph getGraph()
Description copied from interface: GraphMLWriteContext
Returns the currently active graph object

Specified by:
getGraph in interface GraphMLWriteContext
Returns:
The currently active graph object

getSerializationProperty

public java.lang.Object getSerializationProperty(java.lang.Object key)
Description copied from interface: GraphMLWriteContext
Get a property value that specifies information about how to handle specific cases

Specified by:
getSerializationProperty in interface GraphMLWriteContext
Parameters:
key - The identifier for the property
Returns:
The property value, or null if no such property exists

serialize

public void serialize(java.lang.Object item)
               throws GraphMLWriteException
Description copied from interface: GraphMLWriteContext
Serialize item to an XML representation.

Specified by:
serialize in interface GraphMLWriteContext
Parameters:
item - The object that should be serialized.
Throws:
GraphMLWriteException

serialize

public void serialize(GraphMLWriteContext context,
                      java.lang.Object item,
                      java.lang.Class serializationType)
               throws GraphMLWriteException
Description copied from interface: GraphMLWriteContext
Serialize item to an XML representation.

This method is reserved for special use cases. Usually, you should just call GraphMLWriteContext.serialize(Object) instead.

Specified by:
serialize in interface GraphMLWriteContext
Parameters:
context - The current write context.
item - The object that should be serialized.
serializationType - The actual type of the serialization, in case it differs from the type of item.
Throws:
GraphMLWriteException

setSerializationProperty

public void setSerializationProperty(java.lang.Object key,
                                     java.lang.Object value)
Sets the local serialization property for the given key to the value.

Parameters:
key - The key to override.
value - The value.
See Also:
getSerializationProperty(Object)

removeSerializationProperty

public void removeSerializationProperty(java.lang.Object key)
Removes a previously locally setSerializationProperty(Object,Object) serialization property.

Parameters:
key - The key for which the local property override should be removed.
See Also:
setSerializationProperty(Object, Object)

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