Search this API

y.view
Class SimpleUserDataHandler

java.lang.Object
  extended by y.view.SimpleUserDataHandler
All Implemented Interfaces:
GenericEdgeRealizer.UserDataHandler, GenericNodeRealizer.UserDataHandler, NodePort.UserDataHandler, YLabel.UserDataHandler

public class SimpleUserDataHandler
extends java.lang.Object
implements GenericNodeRealizer.UserDataHandler, GenericEdgeRealizer.UserDataHandler, YLabel.UserDataHandler, NodePort.UserDataHandler

Simple implementation of the GenericNodeRealizer.UserDataHandler, GenericEdgeRealizer.UserDataHandler, and YLabel.UserDataHandler interfaces. that can be used by GenericNodeRealizer, GenericEdgeRealizer, and YLabel instances respectively. This implementation tries to either clone the user data and if that fails either copies the value by reference, returns null or throws a RuntimeException

 

Field Summary
static byte EXCEPTION_ON_FAILURE
          Policy constant.
static byte NULL_ON_FAILURE
          Policy constant.
static byte REFERENCE_ON_FAILURE
          Policy constant.
 
Constructor Summary
SimpleUserDataHandler(byte mode)
          Creates a new instance of SimpleUserDataHandler using the given mode
 
Method Summary
 java.lang.Object copyUserData(EdgeRealizer srcContext, java.lang.Object srcData, EdgeRealizer targetContext)
          Copies the user-defined data appropriately.
 java.lang.Object copyUserData(NodePort srcPort, java.lang.Object srcData, NodePort tgtPort)
          Creates a copy of the specified user data that is suitable for the specified target port instance.
 java.lang.Object copyUserData(NodeRealizer srcContext, java.lang.Object srcData, NodeRealizer targetContext)
          Copies the user data using its clone method and if that fails either returns the reference, null, or throws a RuntimeException, depending on the mode of this instance.
protected  java.lang.Object copyUserData(java.lang.Object srcData)
          Callback method that performs the actual copy.
 java.lang.Object copyUserData(YLabel srcContext, java.lang.Object srcData, YLabel targetContext)
          Copies the user-defined data appropriately.
 java.lang.Object readUserData(EdgeRealizer context, java.io.ObjectInputStream ois)
          Retrieves the user-defined data object from the ObjectInputStream.
 java.lang.Object readUserData(NodeRealizer context, java.io.ObjectInputStream ois)
          Read the user data using the default serialization method.
protected  java.lang.Object readUserData(java.io.ObjectInputStream ois)
           
 java.lang.Object readUserData(YLabel context, java.io.ObjectInputStream ois)
          Retrieves the user-defined data object from the ObjectInputStream.
 void storeUserData(EdgeRealizer context, java.lang.Object userData, java.io.ObjectOutputStream oos)
          Stores the user-defined data object to the ObjectOutputStream.
 void storeUserData(NodeRealizer context, java.lang.Object userData, java.io.ObjectOutputStream oos)
          Writes the user data using the default serialization method.
protected  void storeUserData(java.lang.Object userData, java.io.ObjectOutputStream oos)
           
 void storeUserData(YLabel context, java.lang.Object userData, java.io.ObjectOutputStream oos)
          Stores the user-defined data object to the ObjectOutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REFERENCE_ON_FAILURE

public static final byte REFERENCE_ON_FAILURE
Policy constant. This mode will copy the user data by reference if cloning fails.

See Also:
Constant Field Values

NULL_ON_FAILURE

public static final byte NULL_ON_FAILURE
Policy constant. This mode will return a null if cloning fails and serialize a null if serialization fails.

See Also:
Constant Field Values

EXCEPTION_ON_FAILURE

public static final byte EXCEPTION_ON_FAILURE
Policy constant. This mode will throw a RuntimeException if cloning fails or serialization fails.

See Also:
Constant Field Values
Constructor Detail

SimpleUserDataHandler

public SimpleUserDataHandler(byte mode)
Creates a new instance of SimpleUserDataHandler using the given mode

Method Detail

copyUserData

public java.lang.Object copyUserData(NodeRealizer srcContext,
                                     java.lang.Object srcData,
                                     NodeRealizer targetContext)
Copies the user data using its clone method and if that fails either returns the reference, null, or throws a RuntimeException, depending on the mode of this instance.

Specified by:
copyUserData in interface GenericNodeRealizer.UserDataHandler

copyUserData

protected java.lang.Object copyUserData(java.lang.Object srcData)
Callback method that performs the actual copy. This implementation tries to invoke the clone method.

Parameters:
srcData - the object to copy/clone
Returns:
the clone, if successful

readUserData

public java.lang.Object readUserData(NodeRealizer context,
                                     java.io.ObjectInputStream ois)
                              throws java.io.IOException
Read the user data using the default serialization method. If that fails either returns null or throws an IOException, depending on the mode of this instance.

Specified by:
readUserData in interface GenericNodeRealizer.UserDataHandler
Throws:
java.io.IOException

readUserData

protected java.lang.Object readUserData(java.io.ObjectInputStream ois)
                                 throws java.io.IOException
Throws:
java.io.IOException

storeUserData

public void storeUserData(NodeRealizer context,
                          java.lang.Object userData,
                          java.io.ObjectOutputStream oos)
                   throws java.io.IOException
Writes the user data using the default serialization method. If that fails either writes null or throws an IOException, depending on the mode of this instance.

Specified by:
storeUserData in interface GenericNodeRealizer.UserDataHandler
Throws:
java.io.IOException

storeUserData

protected void storeUserData(java.lang.Object userData,
                             java.io.ObjectOutputStream oos)
                      throws java.io.IOException
Throws:
java.io.IOException

storeUserData

public void storeUserData(EdgeRealizer context,
                          java.lang.Object userData,
                          java.io.ObjectOutputStream oos)
                   throws java.io.IOException
Description copied from interface: GenericEdgeRealizer.UserDataHandler
Stores the user-defined data object to the ObjectOutputStream. Used for YGF serialization.

Specified by:
storeUserData in interface GenericEdgeRealizer.UserDataHandler
Parameters:
context - the edge to store the user-defined data
userData - the user-defined data object
oos - the stream to store the user-defined data object to
Throws:
java.io.IOException - if an exception occurs

readUserData

public java.lang.Object readUserData(EdgeRealizer context,
                                     java.io.ObjectInputStream ois)
                              throws java.io.IOException
Description copied from interface: GenericEdgeRealizer.UserDataHandler
Retrieves the user-defined data object from the ObjectInputStream. Used for YGF deserialization.

Specified by:
readUserData in interface GenericEdgeRealizer.UserDataHandler
Parameters:
context - the edge to read the user-defined data for
ois - the stream to read the user-defined data object from
Returns:
the user-defined data object as read in from the stream
Throws:
java.io.IOException - if an exception occurs

copyUserData

public java.lang.Object copyUserData(EdgeRealizer srcContext,
                                     java.lang.Object srcData,
                                     EdgeRealizer targetContext)
Description copied from interface: GenericEdgeRealizer.UserDataHandler
Copies the user-defined data appropriately.

Specified by:
copyUserData in interface GenericEdgeRealizer.UserDataHandler
Parameters:
srcContext - the edge that will be copied
srcData - the data associated with the srcContext
targetContext - the edge the copy will be associated with
Returns:
the copy that will be stored with the targetContext

storeUserData

public void storeUserData(YLabel context,
                          java.lang.Object userData,
                          java.io.ObjectOutputStream oos)
                   throws java.io.IOException
Description copied from interface: YLabel.UserDataHandler
Stores the user-defined data object to the ObjectOutputStream. Used for YGF serialization.

Specified by:
storeUserData in interface YLabel.UserDataHandler
Parameters:
context - the label to store the user-defined data for
userData - the user-defined data object
oos - the stream to store the user-defined data object to
Throws:
java.io.IOException - if an exception occurs

readUserData

public java.lang.Object readUserData(YLabel context,
                                     java.io.ObjectInputStream ois)
                              throws java.io.IOException
Description copied from interface: YLabel.UserDataHandler
Retrieves the user-defined data object from the ObjectInputStream. Used for YGF deserialization.

Specified by:
readUserData in interface YLabel.UserDataHandler
Parameters:
context - the label to read the user-defined data for
ois - the stream to read the user-defined data object from
Returns:
the user-defined data object as read in from the stream
Throws:
java.io.IOException - if an exception occurs

copyUserData

public java.lang.Object copyUserData(YLabel srcContext,
                                     java.lang.Object srcData,
                                     YLabel targetContext)
Description copied from interface: YLabel.UserDataHandler
Copies the user-defined data appropriately.

Specified by:
copyUserData in interface YLabel.UserDataHandler
Parameters:
srcContext - the label that will be copied
srcData - the data associated with the srcContext
targetContext - the label the copy will be associated with
Returns:
the copy that will be stored with the targetContext

copyUserData

public java.lang.Object copyUserData(NodePort srcPort,
                                     java.lang.Object srcData,
                                     NodePort tgtPort)
Description copied from interface: NodePort.UserDataHandler
Creates a copy of the specified user data that is suitable for the specified target port instance.

Specified by:
copyUserData in interface NodePort.UserDataHandler
Parameters:
srcPort - the port instance whose user data is copied.
srcData - the user data that has to be copied.
tgtPort - the port instance for which the copy is created.
Returns:
a copy of the specified user data.

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