public class ChildWriteContext extends Object implements IWriteContext
IWriteContext
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 lookup
and
serialization properties
.
Whenever it is necessary to locally modify some context properties, a new instance of this class should be created that wraps an existing one.
Constructor and Description |
---|
ChildWriteContext(IWriteContext parentContext)
Initializes a new instance of the
ChildWriteContext class that delegates to the given parent context. |
ChildWriteContext(IWriteContext parentContext,
Object currentObject)
Initializes a new instance of the
ChildWriteContext class that delegates to the provided context and returns the
given value in getCurrent() . |
Modifier and Type | Method and Description |
---|---|
Object |
getCurrent()
Returns the most current (the last element) within the container hierarchy as it is returned by
ObjectStack
or default(T) if the most current element is not of the desired target type. |
IGraph |
getGraph()
Returns the currently active graph object.
|
IListEnumerable<Object> |
getObjectStack()
Returns the current nesting of graphs and graph elements.
|
IWriteContext |
getParentContext()
Gets the parent context to which most calls are delegated.
|
<T> T |
getSerializationProperty(TypedKey<T> key)
Get a property value that specifies information about how to handle specific cases.
|
IWriteEvents |
getWriteEvents()
Returns an implementation of
IWriteEvents that allows to subscribe to various events in the write process. |
IXmlWriter |
getWriter()
Gets the writer.
|
<TLookup> TLookup |
lookup(Class<TLookup> type)
Returns an instance that implements the given type or
null . |
<T> void |
removeLookup(Class<T> tType)
Removes a local lookup override that has been added using
setLookup(Class, Object) . |
<T> void |
removeSerializationProperty(TypedKey<T> key)
Removes a previously locally
set serialization property. |
<T> void |
serialize(Type targetType,
IWriteContext context,
T item)
Serialize
item to an XML representation. |
<T> void |
setLookup(Class<T> tType,
T value)
Adds another lookup result to the local lookup override.
|
<T> void |
setSerializationProperty(TypedKey<T> key,
T value)
Sets the local serialization property for the given key to the value.
|
void |
setWriter(IXmlWriter value)
Sets the writer.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
serialize, serialize, serializeReplacement
createDictionaryLookup, createDynamic, createSingle, createSingle, createWrapped, lookup, lookup, safeLookup
public ChildWriteContext(IWriteContext parentContext)
ChildWriteContext
class that delegates to the given parent context.parentContext
- The parent context.public ChildWriteContext(IWriteContext parentContext, Object currentObject)
ChildWriteContext
class that delegates to the provided context and returns the
given value in getCurrent()
.parentContext
- The parent context to delegate calls to.currentObject
- The current object to return in getCurrent()
.public final Object getCurrent()
IWriteContext
ObjectStack
or default(T)
if the most current element is not of the desired target type.getCurrent
in interface IWriteContext
default(T)
.public final IGraph getGraph()
IWriteContext
getGraph
in interface IWriteContext
public final IListEnumerable<Object> getObjectStack()
IWriteContext
The list contains the user objects which correspond to the GraphML elements.
getObjectStack
in interface IWriteContext
public final IWriteContext getParentContext()
public <T> T getSerializationProperty(TypedKey<T> key)
IWriteContext
getSerializationProperty
in interface IWriteContext
key
- The identifier for the propertynull
if no such property existspublic IWriteEvents getWriteEvents()
IWriteContext
IWriteEvents
that allows to subscribe to various events in the write process.getWriteEvents
in interface IWriteContext
public final IXmlWriter getWriter()
If a null
writer is set, this implementation will delegate to the ParentContext
's
Writer
.
getWriter
in interface IWriteContext
setWriter(IXmlWriter)
public <TLookup> TLookup lookup(Class<TLookup> type)
ILookup
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 using
a super type or interface of this instance, but is not limited to inheritance 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. Also it depends on the
type and context whether the instance returned stays up to date or needs to
be reobtained for subsequent use.public <T> void removeLookup(Class<T> tType)
setLookup(Class, Object)
.T
- The type key to remove.tType
- The type key to remove.public <T> void removeSerializationProperty(TypedKey<T> key)
set
serialization property.key
- The key for which the local property override should be removed.public <T> void serialize(Type targetType, IWriteContext context, T item) throws SerializationNotSupportedException
IWriteContext
item
to an XML representation.
Client code should usually use the extension method IWriteContext.serialize(Type, Object)
instead to ensure the the correct
context
instance is used.
serialize
in interface IWriteContext
SerializationNotSupportedException
T
- The type of the object that is serialized.targetType
- The type of the object that is serialized.context
- The current write context.item
- The object that should be serialized.IWriteContext.serialize(Type, Object)
public <T> void setLookup(Class<T> tType, T value)
T
- The type to use as a key for the lookup.tType
- The type to use as a key for the lookup.value
- The value to provide for queries to T
.removeLookup(Class)
public <T> void setSerializationProperty(TypedKey<T> key, T value)
key
- The key to override.value
- The value.public final void setWriter(IXmlWriter value)
If a null
writer is set, this implementation will delegate to the ParentContext
's
Writer
.
value
- The Writer to set.getWriter()