TKey
- The type of the keys.TData
- The type of the data.public abstract class AbstractOutputHandler<TKey,TData> extends Object implements IOutputHandler
IOutputHandler
interface.Modifier | Constructor and Description |
---|---|
protected |
AbstractOutputHandler(Class<TKey> keyType,
KeyScope scope,
String name,
KeyType type)
Initializes a new instance of the
AbstractOutputHandler class using the provided scope, name, and type for the
key definition. |
protected |
AbstractOutputHandler(Class<TKey> keyType,
String name)
Initializes a new instance of the
AbstractOutputHandler class. |
Modifier and Type | Method and Description |
---|---|
IEnumerable<GraphMLXmlAttribute> |
getDataTagAttributes()
Gets the XML attributes that should be added to the data element.
|
TData |
getDefaultValue()
Gets the default value.
|
IEnumerable<GraphMLXmlAttribute> |
getKeyDefinitionAttributes()
Gets the XML attributes that should be added to the key definition in the GraphML key element.
|
WritePrecedence |
getPrecedence()
Gets the write precedence for the handler.
|
protected abstract TData |
getValue(IWriteContext context,
TKey key)
Callback method that obtains the data for the given key.
|
boolean |
isDefaultExisting()
Gets a value indicating whether a default value has been assigned.
|
boolean |
isDefaultValue(IWriteContext context)
Determines whether in the current context, the value is the default value and therefore no data element needs to be
written.
|
boolean |
isKeyDefaultWritingEnabled()
Gets a value indicating whether to write the key default.
|
protected void |
setDefaultExisting(boolean value)
Sets a value indicating whether a default value has been assigned.
|
void |
setDefaultValue(TData value)
Sets the default value.
|
void |
setKeyDefaultWritingEnabled(boolean value)
Sets a value indicating whether to write the key default.
|
void |
setKeyDefinitionName(String name)
Sets the name for the key definition.
|
void |
setKeyDefinitionScope(KeyScope scope)
Sets the scope for the key definition.
|
void |
setKeyDefinitionType(KeyType type)
Sets the key type for the key definition.
|
void |
setKeyDefinitionUri(String uri)
Sets an optional URI for the key definition.
|
void |
setPrecedence(WritePrecedence value)
Sets the write precedence for the handler.
|
void |
writeKeyDefinitionContent(IWriteContext context)
Writes the contents of the key definition.
|
void |
writeValue(IWriteContext context)
Actually writes the value for the current context.
|
protected abstract void |
writeValueCore(IWriteContext context,
TData data)
Callback method that performs the actual writing of the data.
|
protected AbstractOutputHandler(Class<TKey> keyType, KeyScope scope, String name, KeyType type)
AbstractOutputHandler
class using the provided scope, name, and type for the
key definition.keyType
- The type of the keys.scope
- The scope.name
- The name to use for the key definition.type
- The type to use for the key definition.setKeyDefinitionUri(String)
protected AbstractOutputHandler(Class<TKey> keyType, String name)
AbstractOutputHandler
class.
The GraphML key scope and type are determined automatically.
keyType
- The type of the keys.public IEnumerable<GraphMLXmlAttribute> getDataTagAttributes()
IOutputHandler
getDataTagAttributes
in interface IOutputHandler
public final TData getDefaultValue()
Setting this value also sets the DefaultExisting
property.
setDefaultValue(Object)
public IEnumerable<GraphMLXmlAttribute> getKeyDefinitionAttributes()
IOutputHandler
getKeyDefinitionAttributes
in interface IOutputHandler
public final WritePrecedence getPrecedence()
getPrecedence
in interface IOutputHandler
setPrecedence(WritePrecedence)
protected abstract TData getValue(IWriteContext context, TKey key)
context
- The context.key
- The key.public final boolean isDefaultExisting()
true
if a default value has been assigned, false
otherwise.setDefaultExisting(boolean)
public boolean isDefaultValue(IWriteContext context)
This implementation will return false
if no default has been set
. Otherwise it will
use getValue(IWriteContext, Object)
and compare the result with the DefaultValue
to
determine whether they are equal and therefore no data needs to be written.
isDefaultValue
in interface IOutputHandler
context
- The context.true
if for the current context the default value applies and therefore no data element needs to be written.public final boolean isKeyDefaultWritingEnabled()
true
if the key default should be written; false
otherwise.setKeyDefaultWritingEnabled(boolean)
protected final void setDefaultExisting(boolean value)
value
- true
if a default value has been assigned, false
otherwise.isDefaultExisting()
public final void setDefaultValue(TData value)
Setting this value also sets the DefaultExisting
property.
value
- The default value.getDefaultValue()
public final void setKeyDefaultWritingEnabled(boolean value)
value
- true
if the key default should be written; false
otherwise.isKeyDefaultWritingEnabled()
public final void setKeyDefinitionName(String name)
name
- The name of the key element.public final void setKeyDefinitionScope(KeyScope scope)
Note that the official GraphML schema does not support the KeyScope.GRAPHML
so this implementation will silently
ignore this which will result in KeyScope.ALL
implicitly being defined.
scope
- The scope of the key element.public final void setKeyDefinitionType(KeyType type)
type
- The type of the key element.public final void setKeyDefinitionUri(String uri)
By default, no URI is set.
uri
- The URI of the key element.public final void setPrecedence(WritePrecedence value)
value
- The write precedence.getPrecedence()
public void writeKeyDefinitionContent(IWriteContext context) throws IOException
Depending on whether KeyDefaultWritingEnabled
is enabled and DefaultExisting
is true
, this method will write the GraphML 'default' element and use writeValueCore(IWriteContext, Object)
to serialize the DefaultValue
.
writeKeyDefinitionContent
in interface IOutputHandler
IOException
- If the key definition cannot be written.context
- The context.public final void writeValue(IWriteContext context) throws IOException
This method will use getValue(IWriteContext, Object)
to obtain the data and delegate to writeValueCore(IWriteContext, Object)
to perform the actual serialization.
writeValue
in interface IOutputHandler
IOException
- If the value cannot be written.context
- The context.protected abstract void writeValueCore(IWriteContext context, TData data) throws IOException
IOException
- If the data cannot be written.context
- The context.data
- The data.