org.exolab.castor.mapping
Class AbstractFieldHandler

java.lang.Object
  extended by org.exolab.castor.mapping.loader.FieldHandlerFriend
      extended by org.exolab.castor.mapping.ExtendedFieldHandler
          extended by org.exolab.castor.mapping.AbstractFieldHandler
All Implemented Interfaces:
ConfigurableFieldHandler, FieldHandler
Direct Known Subclasses:
FieldHandlerImpl, GeneralizedFieldHandler, TransientFieldHandler, XMLFieldHandler

public abstract class AbstractFieldHandler
extends ExtendedFieldHandler
implements ConfigurableFieldHandler

An extended version of the FieldHandler interface which is used for adding additional functionality while preserving backward compatability.

Version:
$Revision: 8145 $ $Date: 2005-08-03 15:11:51 -0600 (Wed, 03 Aug 2005) $
Author:
Keith Visco
See Also:
FieldDescriptor, FieldHandler

Field Summary
protected  java.util.Properties _properties
          Configuration that can be used by subclasses when needed.
 
Constructor Summary
protected AbstractFieldHandler()
          Creates a new default AbstractFieldHandler.
 
Method Summary
protected  FieldDescriptor getFieldDescriptor()
          Returns the FieldDescriptor for the field that this handler is reponsibile for, or null if no FieldDescriptor has been set.
abstract  java.lang.Object getValue(java.lang.Object object)
          Returns the value of the field from the object.
 boolean hasValue(java.lang.Object object)
          Returns true if the "handled" field has a value within the given object.
abstract  java.lang.Object newInstance(java.lang.Object parent)
          Creates a new instance of the object described by this field.
abstract  java.lang.Object newInstance(java.lang.Object parent, java.lang.Object[] args)
          Creates a new instance of the object described by this field.
abstract  void resetValue(java.lang.Object object)
          Sets the value of the field to a default value.
 void setConfiguration(java.util.Properties config)
          Empty implementation of the ConfigurableFieldHandler interface, for convenience purpose.
 void setFieldDescriptor(FieldDescriptor fieldDesc)
          Sets the FieldDescriptor that this FieldHander is responsibile for.
abstract  void setValue(java.lang.Object object, java.lang.Object value)
          Sets the value of the field on the object.
 
Methods inherited from class org.exolab.castor.mapping.ExtendedFieldHandler
checkValidity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.exolab.castor.mapping.FieldHandler
checkValidity
 

Field Detail

_properties

protected java.util.Properties _properties
Configuration that can be used by subclasses when needed.

Constructor Detail

AbstractFieldHandler

protected AbstractFieldHandler()
Creates a new default AbstractFieldHandler. This method should be called by all extending classes so that any important initialization code will be executed.

Method Detail

getFieldDescriptor

protected final FieldDescriptor getFieldDescriptor()
Returns the FieldDescriptor for the field that this handler is reponsibile for, or null if no FieldDescriptor has been set. This method is useful for implementations of the FieldHandler interface that wish to obtain information about the field in order to make the FieldHandler more generic and reusable, or simply for validation purposes.

Specified by:
getFieldDescriptor in class ExtendedFieldHandler
Returns:
the FieldDescriptor, or null if none exists.

setFieldDescriptor

public void setFieldDescriptor(FieldDescriptor fieldDesc)
Sets the FieldDescriptor that this FieldHander is responsibile for. By setting the FieldDescriptor, it allows the implementation of the FieldHandler methods to obtain information about the field itself. This allows a particular implementation to become more generic and reusable.

Specified by:
setFieldDescriptor in class ExtendedFieldHandler
Parameters:
fieldDesc - the FieldDescriptor to set

hasValue

public boolean hasValue(java.lang.Object object)
Returns true if the "handled" field has a value within the given object.

By default this just checks for null. Normally this method is needed for checking if a value has been set via a call to the setValue method, or if the primitive value has been initialized by the JVM.

This method should be overloaded for improved value checking.

Returns:
true if the given object has a value for the handled field

getValue

public abstract java.lang.Object getValue(java.lang.Object object)
                                   throws java.lang.IllegalStateException
Returns the value of the field from the object.

Specified by:
getValue in interface FieldHandler
Specified by:
getValue in class ExtendedFieldHandler
Parameters:
object - The object
Returns:
The value of the field
Throws:
java.lang.IllegalStateException - The Java object has changed and is no longer supported by this handler, or the handler is not compatiable with the Java object

newInstance

public abstract java.lang.Object newInstance(java.lang.Object parent)
                                      throws java.lang.IllegalStateException
Creates a new instance of the object described by this field.

Specified by:
newInstance in interface FieldHandler
Specified by:
newInstance in class ExtendedFieldHandler
Parameters:
parent - The object for which the field is created
Returns:
A new instance of the field's value
Throws:
java.lang.IllegalStateException - This field is a simple type and cannot be instantiated

newInstance

public abstract java.lang.Object newInstance(java.lang.Object parent,
                                             java.lang.Object[] args)
                                      throws java.lang.IllegalStateException
Creates a new instance of the object described by this field.

Specified by:
newInstance in class ExtendedFieldHandler
Parameters:
parent - The object for which the field is created
args - the set of constructor arguments
Returns:
A new instance of the field's value
Throws:
java.lang.IllegalStateException - This field is a simple type and cannot be instantiated

resetValue

public abstract void resetValue(java.lang.Object object)
                         throws java.lang.IllegalStateException,
                                java.lang.IllegalArgumentException
Sets the value of the field to a default value.

Reference fields are set to null, primitive fields are set to their default value, collection fields are emptied of all elements.

Specified by:
resetValue in interface FieldHandler
Specified by:
resetValue in class ExtendedFieldHandler
Parameters:
object - The object
Throws:
java.lang.IllegalStateException - The Java object has changed and is no longer supported by this handler, or the handler is not compatiable with the Java object
java.lang.IllegalArgumentException

setValue

public abstract void setValue(java.lang.Object object,
                              java.lang.Object value)
                       throws java.lang.IllegalStateException,
                              java.lang.IllegalArgumentException
Sets the value of the field on the object.

Specified by:
setValue in interface FieldHandler
Specified by:
setValue in class ExtendedFieldHandler
Parameters:
object - The object.
value - The new value.
Throws:
java.lang.IllegalStateException - The Java object has changed and is no longer supported by this handler, or the handler is not compatiable with the Java object.
java.lang.IllegalArgumentException - The value passed is not of a supported type.

setConfiguration

public void setConfiguration(java.util.Properties config)
                      throws ValidityException
Empty implementation of the ConfigurableFieldHandler interface, for convenience purpose. Subclasses that want to use any configuration should override this method.

Specified by:
setConfiguration in interface ConfigurableFieldHandler
Parameters:
config - the configuration data.
Throws:
ValidityException - if config is invalid for this FieldHandler.


Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com