Package org.exolab.castor.mapping
Class GeneralizedFieldHandler
- java.lang.Object
-
- org.exolab.castor.mapping.loader.FieldHandlerFriend
-
- org.exolab.castor.mapping.ExtendedFieldHandler
-
- org.exolab.castor.mapping.AbstractFieldHandler
-
- org.exolab.castor.mapping.GeneralizedFieldHandler
-
- All Implemented Interfaces:
ConfigurableFieldHandler
,FieldHandler
- Direct Known Subclasses:
EnumFieldHandler
,SQLTimeFieldHandler
,SQLTimestampFieldHandler
,ToStringFieldHandler
,ValueOfFieldHandler
public abstract class GeneralizedFieldHandler extends AbstractFieldHandler
An extended version of the FieldHandler interface which is used for making generic libraries of FieldHandlers which can be used for more than one field or class, but have similar conversion algorithms.- Version:
- $Revision: 6216 $ $Date: 2005-01-18 17:29:45 -0700 (Tue, 18 Jan 2005) $
- Author:
- Keith Visco
- See Also:
FieldDescriptor
,FieldHandler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
GeneralizedFieldHandler.GFHConverterEnumeration
-
Field Summary
-
Fields inherited from class org.exolab.castor.mapping.AbstractFieldHandler
_properties
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
GeneralizedFieldHandler()
Creates a new default GeneralizedFieldHandler.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract java.lang.Object
convertUponGet(java.lang.Object value)
This method is used to convert the value when the getValue method is called.abstract java.lang.Object
convertUponSet(java.lang.Object value)
This method is used to convert the value when the setValue method is called.abstract java.lang.Class
getFieldType()
Returns the class type for the field that this GeneralizedFieldHandler converts to and from.java.lang.Object
getValue(java.lang.Object object)
Returns the value of the field from the object.java.lang.Object
newInstance(java.lang.Object parent)
Creates a new instance of the object described by this field.java.lang.Object
newInstance(java.lang.Object parent, java.lang.Object[] args)
Creates a new instance of the object described by this field.void
resetValue(java.lang.Object object)
Sets the value of the field to a default value.void
setCollectionIteration(boolean autoCollectionIteration)
Sets whether or not this GeneralizedFieldHandler should automatically iterate over the collection returned by the target object and pass only the items (one by one) to the convertUponGet method.void
setFieldHandler(FieldHandler handler)
Sets the FieldHandler that this FieldHander delegates to.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.AbstractFieldHandler
getFieldDescriptor, hasValue, setConfiguration, setFieldDescriptor
-
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
-
-
-
-
Method Detail
-
convertUponGet
public abstract java.lang.Object convertUponGet(java.lang.Object value)
This method is used to convert the value when the getValue method is called. The getValue method will obtain the actual field value from given 'parent' object. This convert method is then invoked with the field's value. The value returned from this method will be the actual value returned by getValue method.- Parameters:
value
- the object value to convert after performing a get operation- Returns:
- the converted value.
-
convertUponSet
public abstract java.lang.Object convertUponSet(java.lang.Object value)
This method is used to convert the value when the setValue method is called. The setValue method will call this method to obtain the converted value. The converted value will then be used as the value to set for the field.- Parameters:
value
- the object value to convert before performing a set operation- Returns:
- the converted value.
-
getFieldType
public abstract java.lang.Class getFieldType()
Returns the class type for the field that this GeneralizedFieldHandler converts to and from. This should be the type that is used in the object model.- Returns:
- the class type of of the field
-
setFieldHandler
public final void setFieldHandler(FieldHandler handler)
Sets the FieldHandler that this FieldHander delegates to. A call to this method must be made with a non-null FieldHandler before this GeneralizedFieldHandler can be used.- Parameters:
handler
- the FieldHandler to delegate to
-
setCollectionIteration
public void setCollectionIteration(boolean autoCollectionIteration)
Sets whether or not this GeneralizedFieldHandler should automatically iterate over the collection returned by the target object and pass only the items (one by one) to the convertUponGet method. As of Castor 0.9.6 this is true by default.- Parameters:
autoCollectionIteration
- a boolean that when true indicates that this GeneralizedFieldHandler should automatically iterate over a collection and pass only collection items to the convertUponGet method.
-
getValue
public final 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 interfaceFieldHandler
- Specified by:
getValue
in classFieldHandlerFriend
- 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 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 interfaceFieldHandler
- Specified by:
newInstance
in classFieldHandlerFriend
- 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 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 classExtendedFieldHandler
- Parameters:
parent
- The object for which the field is createdargs
- 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 final 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 interfaceFieldHandler
- Specified by:
resetValue
in classFieldHandlerFriend
- 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 objectjava.lang.IllegalArgumentException
-
setValue
public final 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 interfaceFieldHandler
- Specified by:
setValue
in classFieldHandlerFriend
- 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.
-
-