Search this API

y.io.graphml.output
Class AbstractOutputHandler

java.lang.Object
  extended by y.io.graphml.output.AbstractOutputHandler
All Implemented Interfaces:
java.util.EventListener, OutputHandler, OutputHandlerProvider
Direct Known Subclasses:
AbstractDataProviderOutputHandler, AbstractWriteNodePortHandler, EdgeLayoutOutputHandler, NodeLayoutOutputHandler, PostprocessorOutputHandler, WriteEdgeRealizerHandler, WriteNodeRealizerHandler

public abstract class AbstractOutputHandler
extends java.lang.Object
implements OutputHandler, OutputHandlerProvider

Convenience abstract base implementation of the OutputHandler interface.

Since this class also implements the OutputHandlerProvider interface, it can be registered directly with GraphMLHandler.addOutputHandlerProvider(y.io.graphml.output.OutputHandlerProvider)

 

Constructor Summary
protected AbstractOutputHandler()
          Initializes a new instance of the AbstractOutputHandler class.
protected AbstractOutputHandler(java.lang.String name, KeyScope scope, KeyType type)
          Initializes a new instance of the AbstractOutputHandler class
 
Method Summary
 void addNameToKeyDefinition(java.lang.String name)
          Adds the name to the key definition.
 void addScopeToKeyDefinition(KeyScope scope)
          Adds the scope to the key definition.
 void addTypeToKeyDefinition(KeyType type)
          Adds the key type to the key definition.
 void addUriToKeyDefinition(java.lang.String uri)
          Adds an optional uri to the key definition.
 java.util.Collection getDataTagAttributes()
          Returns XML all attributes of the data element.
 java.lang.Object getDefaultValue()
          Gets the default value.
 java.util.Collection getKeyDefinitionAttributes()
          Returns all XML attributes of the key element.
 WritePrecedence getPrecedence()
          Gets the write precedence for the handler.
 KeyScope getScope()
          Gets the KeyScope where this handler should register itself.
 java.util.Set getValidScopes()
          Allows to restrict the scopes where the handler is used, if the handler is registered to KeyScope.ALL.
protected abstract  java.lang.Object getValue(GraphMLWriteContext context, java.lang.Object key)
          Callback method that obtains the data for the given key.
 boolean hasDefaultValueAssigned()
          Gets a value indicating whether a default value has been assigned.
 boolean isDefaultValue(GraphMLWriteContext ctx)
          Determines whether in the current context, the value is the default value and therefore no data element needs to be written.
protected  boolean isValidScope(GraphMLWriteContext ctx)
          Checks whether the current handler is called in a scope that is valid. wrt getValidScopes()
 boolean isWriteKeyDefault()
          Gets a value indicating whether to write the key default.
 void onQueryOutputHandler(QueryOutputHandlersEvent event)
          Allows this instance to register itself as an OutputHandler.
 void setDefaultValue(java.lang.Object value)
          Sets the default value.
protected  void setDefaultValueAssigned(boolean value)
          Sets a value indicating whether a default value has been assigned.
 void setPrecedence(WritePrecedence value)
          Sets the write precedence for the handler.
 void setScope(KeyScope scope)
          Sets the KeyScope where this handler should register itself.
 void setValidScopes(java.util.Set value)
          Allows to restrict the scopes where the handler is used, if the handler is registered to KeyScope.ALL.
 void setWriteKeyDefault(boolean value)
          Sets a value indicating whether to write the key default.
 void writeKeyDefinitionContent(GraphMLWriteContext ctx)
          Writes the contents of the key definition.
 void writeValue(GraphMLWriteContext ctx)
          Actually writes the value for the current context.
protected abstract  void writeValueCore(GraphMLWriteContext context, java.lang.Object data)
          Core write that performs the actual writing of the data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractOutputHandler

protected AbstractOutputHandler()
Initializes a new instance of the AbstractOutputHandler class.


AbstractOutputHandler

protected AbstractOutputHandler(java.lang.String name,
                                KeyScope scope,
                                KeyType type)
Initializes a new instance of the AbstractOutputHandler class

Parameters:
name - The name to use for the key definition.
scope - The scope, if this is KeyScope.GRAPHML, the getValidScopes() property is initialized to contain exactly that scope.
type - The type to use for the key definition.
Method Detail

getScope

public KeyScope getScope()
Gets the KeyScope where this handler should register itself.

Returns:
the KeyScope where this handler should register itself.
See Also:
onQueryOutputHandler(QueryOutputHandlersEvent), setScope(y.io.graphml.KeyScope)

setScope

public void setScope(KeyScope scope)
Sets the KeyScope where this handler should register itself.

Parameters:
scope - the KeyScope where this handler should register itself.
See Also:
onQueryOutputHandler(QueryOutputHandlersEvent), getScope()

onQueryOutputHandler

public void onQueryOutputHandler(QueryOutputHandlersEvent event)
                          throws GraphMLWriteException
Allows this instance to register itself as an OutputHandler.

This implementation registers the current instance on event if a KeyScope has been specified either with AbstractOutputHandler(String, y.io.graphml.KeyScope, y.io.graphml.KeyType) or setScope(y.io.graphml.KeyScope)

Specified by:
onQueryOutputHandler in interface OutputHandlerProvider
Parameters:
event - Event that contains all data relevant for handler setup.
Throws:
GraphMLWriteException - if a problem occurs during serialization.

addNameToKeyDefinition

public void addNameToKeyDefinition(java.lang.String name)
Adds the name to the key definition.

Parameters:
name - The name of the key element.

addUriToKeyDefinition

public void addUriToKeyDefinition(java.lang.String uri)
Adds an optional uri to the key definition.

By default, no URI is set.

Parameters:
uri - The uri of the key element.

addTypeToKeyDefinition

public void addTypeToKeyDefinition(KeyType type)
Adds the key type to the key definition.

Parameters:
type - The type of the key element.

addScopeToKeyDefinition

public void addScopeToKeyDefinition(KeyScope scope)
Adds the scope to the key definition.

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.

Parameters:
scope - The scope of the key element.

getDefaultValue

public java.lang.Object getDefaultValue()
Gets the default value.

Returns:
The default value of the attribute.
See Also:
setDefaultValue(Object)

setDefaultValue

public void setDefaultValue(java.lang.Object value)
Sets the default value.

Setting this value also sets the hasDefaultValueAssigned() property.

Parameters:
value - The default value of the attribute.
See Also:
getDefaultValue()

hasDefaultValueAssigned

public boolean hasDefaultValueAssigned()
Gets a value indicating whether a default value has been assigned.

Returns:
true if a default value has been assigned; false otherwise.
See Also:
setDefaultValueAssigned(boolean)

setDefaultValueAssigned

protected void setDefaultValueAssigned(boolean value)
Sets a value indicating whether a default value has been assigned.

Parameters:
value - true if a default value has been assigned; false otherwise.
See Also:
setDefaultValueAssigned(boolean)

getPrecedence

public WritePrecedence getPrecedence()
Gets the write precedence for the handler.

Specified by:
getPrecedence in interface OutputHandler
Returns:
The write precedence.
See Also:
setPrecedence(WritePrecedence)

setPrecedence

public void setPrecedence(WritePrecedence value)
Sets the write precedence for the handler.

Parameters:
value - The write precedence.
See Also:
getPrecedence()

getKeyDefinitionAttributes

public java.util.Collection getKeyDefinitionAttributes()
Returns all XML attributes of the key element.

Specified by:
getKeyDefinitionAttributes in interface OutputHandler
Returns:
All attributes of the key element.
See Also:
addNameToKeyDefinition(String), addScopeToKeyDefinition(y.io.graphml.KeyScope), addTypeToKeyDefinition(y.io.graphml.KeyType), addUriToKeyDefinition(String)

getDataTagAttributes

public java.util.Collection getDataTagAttributes()
Returns XML all attributes of the data element.

By default, this collection is empty.

Specified by:
getDataTagAttributes in interface OutputHandler
Returns:
All attributes of the data element.

isDefaultValue

public boolean isDefaultValue(GraphMLWriteContext ctx)
                       throws GraphMLWriteException
Determines whether in the current context, the value is the default value and therefore no data element needs to be written.

This implementation will return false if no hasDefaultValueAssigned(). Otherwise it will use getValue(y.io.graphml.output.GraphMLWriteContext,Object) and compare the result with the getDefaultValue() to determine whether they are equal and therefore no data needs to be written.

Specified by:
isDefaultValue in interface OutputHandler
Parameters:
ctx - The context.
Returns:
true if for the current context the default value applies and therefore no data element needs to be written.
Throws:
GraphMLWriteException
See Also:
hasDefaultValueAssigned(), getDefaultValue()

isValidScope

protected boolean isValidScope(GraphMLWriteContext ctx)
Checks whether the current handler is called in a scope that is valid. wrt getValidScopes()

Parameters:
ctx - The current write context.
Returns:
true iff the current scope in which the handler is called is valid wrt getValidScopes().
See Also:
getValidScopes(), SerializationProperties.CURRENT_KEY_SCOPE

getValidScopes

public java.util.Set getValidScopes()
Allows to restrict the scopes where the handler is used, if the handler is registered to KeyScope.ALL.

By default the collection contains KeyScope.ALL, which means the set of valid scopes is not restricted further.

Returns:
A set of actually valid scopes for KeyScope.ALL
See Also:
isValidScope(GraphMLWriteContext), setValidScopes(java.util.Set)

setValidScopes

public void setValidScopes(java.util.Set value)
Allows to restrict the scopes where the handler is used, if the handler is registered to KeyScope.ALL.

By default the collection contains the KeyScope.ALL, which means the set of valid scopes is not restricted further.

Parameters:
value - A set of actually valid scopes for KeyScope.ALL
See Also:
isValidScope(GraphMLWriteContext), getValidScopes()

writeValue

public void writeValue(GraphMLWriteContext ctx)
                throws GraphMLWriteException
Actually writes the value for the current context.

This method will use getValue(y.io.graphml.output.GraphMLWriteContext,Object) to obtain the data and delegate to writeValueCore(y.io.graphml.output.GraphMLWriteContext,Object) to perform the actual serialization.

Specified by:
writeValue in interface OutputHandler
Parameters:
ctx - The context.
Throws:
GraphMLWriteException

writeKeyDefinitionContent

public void writeKeyDefinitionContent(GraphMLWriteContext ctx)
                               throws GraphMLWriteException
Writes the contents of the key definition.

Depending on whether setWriteKeyDefault(boolean) is enabled and hasDefaultValueAssigned() is true, this method will write the GraphML 'default' element and use writeValueCore(y.io.graphml.output.GraphMLWriteContext,Object) to serialize the getDefaultValue().

Specified by:
writeKeyDefinitionContent in interface OutputHandler
Parameters:
ctx - The context.
Throws:
GraphMLWriteException

setWriteKeyDefault

public void setWriteKeyDefault(boolean value)
Sets a value indicating whether to write the key default.

Parameters:
value - true if the key default should be written at all.
See Also:
isWriteKeyDefault(), writeKeyDefinitionContent(GraphMLWriteContext)

isWriteKeyDefault

public boolean isWriteKeyDefault()
Gets a value indicating whether to write the key default.

Returns:
true if the key default should be written; false otherwise.
See Also:
setWriteKeyDefault(boolean), writeKeyDefinitionContent(GraphMLWriteContext)

writeValueCore

protected abstract void writeValueCore(GraphMLWriteContext context,
                                       java.lang.Object data)
                                throws GraphMLWriteException
Core write that performs the actual writing of the data.

Parameters:
context - The context.
data - The data.
Throws:
GraphMLWriteException

getValue

protected abstract java.lang.Object getValue(GraphMLWriteContext context,
                                             java.lang.Object key)
                                      throws GraphMLWriteException
Callback method that obtains the data for the given key.

Parameters:
context - The context.
key - The key.
Returns:
The data that is associated with the key.
Throws:
GraphMLWriteException

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