Package org.exolab.castor.xml.handlers
Class ContainerFieldHandler
java.lang.Object
org.exolab.castor.xml.handlers.ContainerFieldHandler
- All Implemented Interfaces:
FieldHandler
The FieldHandler for ContainerElement.
- Version:
- $Revision: 6784 $ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
- Author:
- Keith Visco
- See Also:
-
org.exolab.castor.mapping.FieldDescriptor
org.exolab.castor.mapping.FieldHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Automatically choose the mode to use.static final int
The mode for a ContainerElement.static final int
When the field is not a ContainerElement, this mode is used. -
Constructor Summary
ConstructorsConstructorDescriptionContainerFieldHandler
(FieldHandler handler) Creates a new ContainerFieldHandler with the given FieldHandler. -
Method Summary
Modifier and TypeMethodDescriptionvoid
checkValidity
(Object object) Checks the field validity.Returns the value of the field from the object.newInstance
(Object parent) Creates a new instance of the object described by this field.void
resetValue
(Object object) Sets the value of the field to a default value.void
Sets the value of the field on the object.
-
Field Details
-
MODE_AUTO
public static final int MODE_AUTOAutomatically choose the mode to use.- See Also:
-
MODE_PARENT_LINK
public static final int MODE_PARENT_LINKWhen the field is not a ContainerElement, this mode is used.- See Also:
-
MODE_CHILD_LINK
public static final int MODE_CHILD_LINKThe mode for a ContainerElement. getValue and setValue operate on the parent.- See Also:
-
-
Constructor Details
-
ContainerFieldHandler
Creates a new ContainerFieldHandler with the given FieldHandler.- Parameters:
handler
- The field handler to delegate to.
-
-
Method Details
-
getValue
Returns the value of the field from the object. If mode is MODE_CHILD_LINK or mode is MODE_AUTO and the object is a ContainerElement, then the value of the parent is returned. Otherwise, a new ContainerElement is returned. The value of this new ContainerElement is the value of the provided object and the parent of the new ContainerElement is the provided object.- Specified by:
getValue
in interfaceFieldHandler
- Parameters:
object
- The object to get the value of- Returns:
- The value of the field
- Throws:
IllegalStateException
- The Java object has changed and is no longer supported by this handler, or the handler is not compatible with the Java object
-
newInstance
Creates a new instance of the object described by this field. Of the object provided is a ContainerElement, then a new isntance of the parent object is returned. Otherwise a new ContainerElement is created and returned, with the parent set to the provided object.- Specified by:
newInstance
in interfaceFieldHandler
- 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
-
resetValue
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
- Parameters:
object
- The object- Throws:
IllegalStateException
- The Java object has changed and is no longer supported by this handler, or the handler is not compatiable with the Java object
-
setValue
public void setValue(Object object, Object value) throws IllegalStateException, IllegalArgumentException Sets the value of the field on the object. That is, sets the value of the container parent to the provided value.- Specified by:
setValue
in interfaceFieldHandler
- Parameters:
object
- The object whose value to set.value
- The new value- Throws:
IllegalStateException
- The Java object has changed and is no longer supported by this handler, or the handler is not compatiable with the Java objectIllegalArgumentException
- The value passed is not of a supported type
-
checkValidity
Checks the field validity. Returns successfully if the field can be stored, is valid, etc, throws an exception otherwise.- Specified by:
checkValidity
in interfaceFieldHandler
- Parameters:
object
- The object- Throws:
ValidityException
- The field is invalid, is required and null, or any other validity violationIllegalStateException
- The Java object has changed and is no longer supported by this handler, or the handler is not compatiable with the Java object
-