org.exolab.castor.mapping.loader
Class FieldHandlerImpl

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
              extended by org.exolab.castor.mapping.loader.FieldHandlerImpl
All Implemented Interfaces:
FieldHandler

public final class FieldHandlerImpl
extends AbstractFieldHandler

A field handler that knows how to get/set the values of a field directly or through the get/set methods. Uses reflection.

Note: the field Java type is obtained from TypeInfo.getFieldType(), but if the field is a collection, the actual field/accessor type is obtained from TypeInfo.getCollectionHandler() and the object to create (with newInstance(Object)) is the former field type.

Version:
$Revision: 1.7 $ $Date: 2005/05/22 14:22:58 $
Author:
Assaf Arkin

Constructor Summary
FieldHandlerImpl(FieldHandler handler, TypeInfo typeInfo)
          Construct a new field handler for the specified field.
FieldHandlerImpl(java.lang.reflect.Field field, TypeInfo typeInfo)
          Construct a new field handler for the specified field.
FieldHandlerImpl(java.lang.String fieldName, java.lang.reflect.Method[] getSequence, java.lang.reflect.Method[] setSequence, java.lang.reflect.Method getMethod, java.lang.reflect.Method setMethod, TypeInfo typeInfo)
          Construct a new field handler for the specified field that is accessed through the accessor methods (get/set).
 
Method Summary
 TypeConvertor getConvertFrom()
           
 java.lang.String getConvertParam()
           
 TypeConvertor getConvertTo()
           
 java.lang.Object getValue(java.lang.Object object)
          Returns the value of the field from the object.
 boolean isCollection()
          Return true if the field is a collection.
 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 setAddMethod(java.lang.reflect.Method method)
          Mutator method used by Introspector.
 void setConvertFrom(TypeConvertor convertor)
          Sets the TypeConvertor used during calls to getValue
 void setConvertTo(TypeConvertor convertor)
          Sets the TypeConvertor used during calls to setValue
 void setCreateMethod(java.lang.reflect.Method method)
          Mutator method used by MappingLoader and Introspector.
 void setHasDeleteMethod(java.lang.reflect.Method hasMethod, java.lang.reflect.Method deleteMethod)
          Mutator method used by MappingLoader and Introspector.
 void setReadMethod(java.lang.reflect.Method method)
          Mutator method used by Introspector.
(package private)  void setRequired(boolean required)
          Mutator method used by MappingLoader.
 void setValue(java.lang.Object object, java.lang.Object value)
          Sets the value of the field on the object.
 void setWriteMethod(java.lang.reflect.Method method)
          Mutator method used by Introspector.
 java.lang.String toString()
           
 
Methods inherited from class org.exolab.castor.mapping.AbstractFieldHandler
getFieldDescriptor, hasValue, 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, wait, wait, wait
 

Constructor Detail

FieldHandlerImpl

public FieldHandlerImpl(FieldHandler handler,
                        TypeInfo typeInfo)
                 throws MappingException
Construct a new field handler for the specified field. The field must be public, and may not be static or transient. The field name is determined from the Java field, the type from the type information.

Parameters:
handler -
typeInfo - Type information
Throws:
MappingException - If the field is not public, is static or transient

FieldHandlerImpl

public FieldHandlerImpl(java.lang.reflect.Field field,
                        TypeInfo typeInfo)
                 throws MappingException
Construct a new field handler for the specified field. The field must be public, and may not be static or transient. The field name is determined from the Java field, the type from the type information.

Parameters:
field - The field being described
typeInfo - Type information
Throws:
MappingException - If the field is not public, is static or transient

FieldHandlerImpl

public FieldHandlerImpl(java.lang.String fieldName,
                        java.lang.reflect.Method[] getSequence,
                        java.lang.reflect.Method[] setSequence,
                        java.lang.reflect.Method getMethod,
                        java.lang.reflect.Method setMethod,
                        TypeInfo typeInfo)
                 throws MappingException
Construct a new field handler for the specified field that is accessed through the accessor methods (get/set). The accessor methods must be public and not static. The field name is required for descriptive purposes. The field type must match the return value of the get method and the single parameter of the set method. Either get or set methods are optional.

Parameters:
fieldName - The field being described
getMethod - The method used to retrieve the field value, must accept no parameters and have a return type castable to the field type
setMethod - The method used to set the field value, must accept a single parameter that is castable to the field type
typeInfo - Type information
Throws:
MappingException - If the get or set method are not public, are static, or do not specify the proper types
Method Detail

getConvertFrom

public TypeConvertor getConvertFrom()

getConvertTo

public TypeConvertor getConvertTo()

getConvertParam

public java.lang.String getConvertParam()

getValue

public java.lang.Object getValue(java.lang.Object object)
Description copied from class: AbstractFieldHandler
Returns the value of the field from the object.

Specified by:
getValue in interface FieldHandler
Specified by:
getValue in class AbstractFieldHandler
Parameters:
object - The object
Returns:
The value of the field

setValue

public void setValue(java.lang.Object object,
                     java.lang.Object value)
Description copied from class: AbstractFieldHandler
Sets the value of the field on the object.

Specified by:
setValue in interface FieldHandler
Specified by:
setValue in class AbstractFieldHandler
Parameters:
object - The object
value - The new value

resetValue

public void resetValue(java.lang.Object object)
Description copied from class: AbstractFieldHandler
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 AbstractFieldHandler
Parameters:
object - The 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 interface FieldHandler
Specified by:
newInstance in class AbstractFieldHandler
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 class AbstractFieldHandler
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

setRequired

void setRequired(boolean required)
Mutator method used by MappingLoader.


setConvertFrom

public void setConvertFrom(TypeConvertor convertor)
Sets the TypeConvertor used during calls to getValue

Parameters:
convertor - the TypeConvertor to use during calls to getValue

setConvertTo

public void setConvertTo(TypeConvertor convertor)
Sets the TypeConvertor used during calls to setValue

Parameters:
convertor - the TypeConvertor to use during calls to setValue

setCreateMethod

public void setCreateMethod(java.lang.reflect.Method method)
                     throws MappingException
Mutator method used by MappingLoader and Introspector. Please understand how this method is used before you start playing with it! :-)

Throws:
MappingException

setHasDeleteMethod

public void setHasDeleteMethod(java.lang.reflect.Method hasMethod,
                               java.lang.reflect.Method deleteMethod)
                        throws MappingException
Mutator method used by MappingLoader and Introspector. Please understand how this method is used before you start playing with it! :-)

Throws:
MappingException

setReadMethod

public void setReadMethod(java.lang.reflect.Method method)
                   throws MappingException
Mutator method used by Introspector. Please understand how this method is used before you start playing with it! :-)

Throws:
MappingException

setWriteMethod

public void setWriteMethod(java.lang.reflect.Method method)
                    throws MappingException
Mutator method used by Introspector. Please understand how this method is used before you start playing with it! :-)

Throws:
MappingException

setAddMethod

public void setAddMethod(java.lang.reflect.Method method)
                  throws MappingException
Mutator method used by Introspector. Please understand how this method is used before you start playing with it! :-)

Throws:
MappingException

isCollection

public boolean isCollection()
Return true if the field is a collection.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


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