com.acsinet_solutions.cetia4.controller.map
Class AbstractBeanRequestMapper

java.lang.Object
  extended by com.acsinet_solutions.cetia4.controller.map.AbstractBeanRequestMapper
All Implemented Interfaces:
RequestMapper
Direct Known Subclasses:
BeanRequestMapper, MultipartBeanRequestMapper

public abstract class AbstractBeanRequestMapper
extends java.lang.Object
implements RequestMapper

This is the basic abstract convenience class for performing mapping between form information and a DTO. If provides basic support for subclasses that perform mapping on simple and multipart requests.

Author:
Santiago Arriaga

Constructor Summary
AbstractBeanRequestMapper()
          Create a request mapper with no default mappings.
AbstractBeanRequestMapper(java.lang.Class targetClass, int nestingLevel)
          Create a request mapper for the given targetClass using reflection mappings over its simple properties at an arbitrary nesting level for nesting properties.
 
Method Summary
 void addMapping(Mapping mapping)
          Add a mapping to the mapper.
protected  org.apache.commons.logging.Log getLogger()
          Get the logger for this instance.
 Mapping getMapping(java.lang.String propertyName)
          Gets the mapping for a given property.
 java.util.Collection<Mapping> getMappings()
          Get a reference to a read-only collection with all the mappings.
 SimpleMapping getSimpleMapping(java.lang.String propertyName)
          Gets the simple mapping for a given property.
 java.lang.Class getTargetClass()
          Get the class that was mapped with this instance; this method may return null if the mapper was not created with a target class.
protected  void performMapping(ParameterAccessor request, java.lang.Object bean, ValidationIssueBuilder builder, Mapping mapping)
          Perform a mapping, and check for issues.
 void removeMapping(java.lang.String propertyName)
          Removes the mapping for a given property.
 void setMapping(Mapping mapping)
          Sets the mapping for a given property.
 void setValidator(Validator validator)
          Set an optional validation reference.
protected  Mapping tryCreateMapping(java.lang.String name, java.lang.Class type)
          This method tries to create a default mapping for a given class type.
protected  void validateAndCheck(ValidationIssueBuilder builder, java.lang.Object bean)
          Perform custom validations, and throw an exception if errors were found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.acsinet_solutions.cetia4.controller.map.RequestMapper
performMapping, performMapping
 

Constructor Detail

AbstractBeanRequestMapper

public AbstractBeanRequestMapper()
Create a request mapper with no default mappings.


AbstractBeanRequestMapper

public AbstractBeanRequestMapper(java.lang.Class targetClass,
                                 int nestingLevel)
Create a request mapper for the given targetClass using reflection mappings over its simple properties at an arbitrary nesting level for nesting properties. For no nesting properties, use 1 as value of nesting level ( 0 will result in an empty RequestMapper ).

Additional mappings may be added later, or undesired mappings may be removed if desired.

Default mappings are created using SimpleMapping.getDefaultMapping() method. All these are instances of SimpleMapping.

The name of the mapping will always correspond to the name of the mapped field. For example "text" property will correspond to "text" HTTP field. "note.id" nested property will correspond to "note.id" HTTP field.

Parameters:
targetClass - A not-null Class instance of the JavaBean type that will be mapped
See Also:
SimpleMapping.getDefaultMapping(String,Class)
Method Detail

addMapping

public final void addMapping(Mapping mapping)
Description copied from interface: RequestMapper
Add a mapping to the mapper. Does not check if a mapping for the given property exist.

Specified by:
addMapping in interface RequestMapper

setMapping

public final void setMapping(Mapping mapping)
Description copied from interface: RequestMapper
Sets the mapping for a given property. If a mapping with property name equal to the one returned by the getPropertyName() of the given mapping exists.

Specified by:
setMapping in interface RequestMapper
See Also:
Mapping.getPropertyName()

removeMapping

public final void removeMapping(java.lang.String propertyName)
Description copied from interface: RequestMapper
Removes the mapping for a given property. Mappings for the given property name are searched and deleted. If a mapping does not return a valid or not-null property name in getPropertyName() this method may not be able to delete the given mapping.

Specified by:
removeMapping in interface RequestMapper
See Also:
Mapping.getPropertyName()

getMapping

public final Mapping getMapping(java.lang.String propertyName)
Description copied from interface: RequestMapper
Gets the mapping for a given property. This is useful for changing default mappings. All default mappings are subclasses of SimpleMapping so a cast can be safely performed in this cases, or getSimpleMapping() convenience method can be used.

Specified by:
getMapping in interface RequestMapper
See Also:
Mapping.getPropertyName()

getSimpleMapping

public final SimpleMapping getSimpleMapping(java.lang.String propertyName)
Description copied from interface: RequestMapper
Gets the simple mapping for a given property. This method is useful when reading default mappings, for example, to change them their associated message. All default mappings created by a RequestMapper such as BeanRequestMapper will always extend SimpleMapping. Custom mappings may not extend this class, so this method should only be used when dealing with default mappings.

Specified by:
getSimpleMapping in interface RequestMapper

getMappings

public final java.util.Collection<Mapping> getMappings()
Description copied from interface: RequestMapper
Get a reference to a read-only collection with all the mappings. This may be useful to access mappings that are not accesible using it's property name.

Specified by:
getMappings in interface RequestMapper

setValidator

public final void setValidator(Validator validator)
Description copied from interface: RequestMapper
Set an optional validation reference. Validation may be performed as part of the mapping, and validating here has the advantage that all validation errors are reported simultaneously. The validation method that is called in this validator when mapping is the generic validate() method, not the specific insert or update validate() methods, so beware of this.

Specified by:
setValidator in interface RequestMapper
See Also:
Validator.validate(ValidationIssueBuilder,Object)

getTargetClass

public final java.lang.Class getTargetClass()
Get the class that was mapped with this instance; this method may return null if the mapper was not created with a target class.


tryCreateMapping

protected Mapping tryCreateMapping(java.lang.String name,
                                   java.lang.Class type)
This method tries to create a default mapping for a given class type. If the mapping could not be obtained, the method returns null.


performMapping

protected void performMapping(ParameterAccessor request,
                              java.lang.Object bean,
                              ValidationIssueBuilder builder,
                              Mapping mapping)
Perform a mapping, and check for issues.


validateAndCheck

protected final void validateAndCheck(ValidationIssueBuilder builder,
                                      java.lang.Object bean)
                               throws ValidationException
Perform custom validations, and throw an exception if errors were found. The validation issue builder may have previously loaded errors that make this method throw an exception, even if custom validations are passed or do not exist.

Throws:
ValidationException

getLogger

protected final org.apache.commons.logging.Log getLogger()
Get the logger for this instance.