Package org.exolab.castor.mapping.loader
Class FieldHandlerImpl
- java.lang.Object
-
- org.exolab.castor.mapping.loader.FieldHandlerFriend
-
- org.exolab.castor.mapping.ExtendedFieldHandler
-
- org.exolab.castor.mapping.AbstractFieldHandler
-
- org.exolab.castor.mapping.loader.FieldHandlerImpl
-
- All Implemented Interfaces:
ConfigurableFieldHandler,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 fromTypeInfo.getCollectionHandler()and the object to create (withnewInstance(Object)) is the former field type.- Version:
- $Revision: 7995 $ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
- Author:
- Assaf Arkin
-
-
Field Summary
-
Fields inherited from class org.exolab.castor.mapping.AbstractFieldHandler
_properties
-
-
Constructor Summary
Constructors Constructor Description 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).FieldHandlerImpl(FieldHandler handler, TypeInfo typeInfo)Construct a new field handler for the specified field.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TypeConvertorgetConvertFrom()TypeConvertorgetConvertTo()java.lang.ObjectgetValue(java.lang.Object object)Returns the value of the field from the object.booleanisCollection()Return true if the field is a collection.java.lang.ObjectnewInstance(java.lang.Object parent)Creates a new instance of the object described by this field.java.lang.ObjectnewInstance(java.lang.Object parent, java.lang.Object[] args)Creates a new instance of the object described by this field.voidresetValue(java.lang.Object object)Sets the value of the field to a default value.voidsetAddMethod(java.lang.reflect.Method method)Mutator method used byIntrospector.voidsetConvertFrom(TypeConvertor convertor)Sets the TypeConvertor used during calls to getValuevoidsetConvertTo(TypeConvertor convertor)Sets the TypeConvertor used during calls to setValuevoidsetCreateMethod(java.lang.reflect.Method method)Mutator method used byAbstractMappingLoaderandIntrospector.voidsetEnumMethod(java.lang.reflect.Method method)Sets the enumeration method.voidsetFieldDescriptor(FieldDescriptor fieldDesc)Sets the FieldDescriptor that this FieldHander is responsibile for.voidsetHasDeleteMethod(java.lang.reflect.Method hasMethod, java.lang.reflect.Method deleteMethod)Mutator method used byAbstractMappingLoaderandIntrospector.voidsetIterMethod(java.lang.reflect.Method method)Sets the iteration method.voidsetReadMethod(java.lang.reflect.Method method)Mutator method used byIntrospector.(package private) voidsetRequired(boolean required)Mutator method used byAbstractMappingLoader.voidsetValue(java.lang.Object object, java.lang.Object value)Sets the value of the field on the object.voidsetWriteMethod(java.lang.reflect.Method method)Mutator method used byIntrospector.java.lang.StringtoString()-
Methods inherited from class org.exolab.castor.mapping.AbstractFieldHandler
getFieldDescriptor, hasValue, setConfiguration
-
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
-
Methods inherited from interface org.exolab.castor.mapping.FieldHandler
checkValidity
-
-
-
-
Constructor Detail
-
FieldHandlerImpl
public FieldHandlerImpl(FieldHandler handler, TypeInfo typeInfo)
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
-
FieldHandlerImpl
public FieldHandlerImpl(java.lang.reflect.Field field, TypeInfo typeInfo) throws MappingExceptionConstruct 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 describedtypeInfo- 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 MappingExceptionConstruct 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 describedgetMethod- The method used to retrieve the field value, must accept no parameters and have a return type castable to the field typesetMethod- The method used to set the field value, must accept a single parameter that is castable to the field typetypeInfo- 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()
-
getValue
public java.lang.Object getValue(java.lang.Object object)
Returns the value of the field from the object.- Specified by:
getValuein interfaceFieldHandler- Specified by:
getValuein classFieldHandlerFriend- Parameters:
object- The object- Returns:
- The value of the field
- See Also:
FieldHandlerFriend.getValue(java.lang.Object)
-
setValue
public void setValue(java.lang.Object object, java.lang.Object value)Sets the value of the field on the object.- Specified by:
setValuein interfaceFieldHandler- Specified by:
setValuein classFieldHandlerFriend- Parameters:
object- The objectvalue- The new value- See Also:
FieldHandlerFriend.setValue(java.lang.Object, java.lang.Object)
-
resetValue
public void resetValue(java.lang.Object object)
Description copied from class:FieldHandlerFriendSets 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:
resetValuein interfaceFieldHandler- Specified by:
resetValuein classFieldHandlerFriend- Parameters:
object- The object
-
newInstance
public java.lang.Object newInstance(java.lang.Object parent) throws java.lang.IllegalStateExceptionCreates a new instance of the object described by this field.- Specified by:
newInstancein interfaceFieldHandler- Specified by:
newInstancein 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.IllegalStateExceptionCreates a new instance of the object described by this field.- Specified by:
newInstancein 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
-
setRequired
void setRequired(boolean required)
Mutator method used byAbstractMappingLoader.
-
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 MappingExceptionMutator method used byAbstractMappingLoaderandIntrospector. 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 MappingExceptionMutator method used byAbstractMappingLoaderandIntrospector. 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 MappingExceptionMutator method used byIntrospector. 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 MappingExceptionMutator method used byIntrospector. 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 MappingExceptionMutator method used byIntrospector. Please understand how this method is used before you start playing with it! :-)- Throws:
MappingException
-
setEnumMethod
public void setEnumMethod(java.lang.reflect.Method method) throws MappingExceptionSets the enumeration method.- Throws:
MappingException
-
setIterMethod
public void setIterMethod(java.lang.reflect.Method method) throws MappingExceptionSets the iteration method.- Throws:
MappingException
-
isCollection
public boolean isCollection()
Return true if the field is a collection.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
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.- Overrides:
setFieldDescriptorin classAbstractFieldHandler- Parameters:
fieldDesc- the FieldDescriptor to set
-
-