Class FieldHandlerImpl<T>
java.lang.Object
org.exolab.castor.mapping.loader.FieldHandlerFriend<T>
org.exolab.castor.mapping.ExtendedFieldHandler<T>
org.exolab.castor.mapping.AbstractFieldHandler<T>
org.exolab.castor.mapping.loader.FieldHandlerImpl<T>
- All Implemented Interfaces:
ConfigurableFieldHandler<T>,FieldHandler<T>
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: 9062 $ $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
ConstructorsConstructorDescriptionFieldHandlerImpl(Field field, TypeInfo typeInfo) Construct a new field handler for the specified field.FieldHandlerImpl(String fieldName, Method[] getSequence, Method[] setSequence, Method getMethod, Method setMethod, TypeInfo typeInfo) Construct a new field handler for the specified field that is accessed through the accessor methods (get/set).FieldHandlerImpl(FieldHandler<T> handler, TypeInfo typeInfo) Construct a new field handler for the specified field. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of the field from the object.booleanReturn true if the field is a collection.newInstance(Object parent) Creates a new instance of the object described by this field.newInstance(Object parent, Object[] args) Creates a new instance of the object described by this field.voidresetValue(Object object) Sets the value of the field to a default value.voidsetAddMethod(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(Method method) Mutator method used byAbstractMappingLoaderandIntrospector.voidsetEnumMethod(Method method) Sets the enumeration method.voidsetFieldDescriptor(FieldDescriptor fieldDesc) Sets the FieldDescriptor that this FieldHander is responsibile for.voidsetHasDeleteMethod(Method hasMethod, Method deleteMethod) Mutator method used byAbstractMappingLoaderandIntrospector.voidsetIterMethod(Method method) Sets the iteration method.voidsetReadMethod(Method method) Mutator method used byIntrospector.voidSets the value of the field on the object.voidsetWriteMethod(Method method) Mutator method used byIntrospector.toString()Methods inherited from class org.exolab.castor.mapping.AbstractFieldHandler
getFieldDescriptor, hasValue, setConfigurationMethods inherited from class org.exolab.castor.mapping.ExtendedFieldHandler
checkValidityMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.exolab.castor.mapping.FieldHandler
checkValidity
-
Constructor Details
-
FieldHandlerImpl
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
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 describedtypeInfo- Type information- Throws:
MappingException- If the field is not public, is static or transient
-
FieldHandlerImpl
public FieldHandlerImpl(String fieldName, Method[] getSequence, Method[] setSequence, Method getMethod, 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 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 Details
-
getConvertFrom
-
getConvertTo
-
getValue
-
setValue
-
resetValue
Description copied from interface:FieldHandlerSets 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.
- Parameters:
object- The object.
-
newInstance
Creates a new instance of the object described by this field.- Parameters:
parent- The object for which the field is created- Returns:
- A new instance of the field's value
- Throws:
IllegalStateException- This field is a simple type and cannot be instantiated
-
newInstance
Creates a new instance of the object described by this field.- Specified by:
newInstancein classExtendedFieldHandler<T>- 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:
IllegalStateException- This field is a simple type and cannot be instantiated
-
setConvertFrom
Sets the TypeConvertor used during calls to getValue- Parameters:
convertor- the TypeConvertor to use during calls to getValue
-
setConvertTo
Sets the TypeConvertor used during calls to setValue- Parameters:
convertor- the TypeConvertor to use during calls to setValue
-
setCreateMethod
Mutator method used byAbstractMappingLoaderandIntrospector. Please understand how this method is used before you start playing with it! :-)- Throws:
MappingException
-
setHasDeleteMethod
Mutator method used byAbstractMappingLoaderandIntrospector. Please understand how this method is used before you start playing with it! :-)- Throws:
MappingException
-
setReadMethod
Mutator method used byIntrospector. Please understand how this method is used before you start playing with it! :-)- Throws:
MappingException
-
setWriteMethod
Mutator method used byIntrospector. Please understand how this method is used before you start playing with it! :-)- Throws:
MappingException
-
setAddMethod
Mutator method used byIntrospector. Please understand how this method is used before you start playing with it! :-)- Throws:
MappingException
-
setEnumMethod
Sets the enumeration method.- Throws:
MappingException
-
setIterMethod
Sets the iteration method.- Throws:
MappingException
-
isCollection
public boolean isCollection()Return true if the field is a collection. -
toString
-
setFieldDescriptor
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<T>- Parameters:
fieldDesc- the FieldDescriptor to set
-