com.acsinet_solutions.cetia4.controller.map
Class MultipartBeanRequestMapper

java.lang.Object
  extended by com.acsinet_solutions.cetia4.controller.map.AbstractBeanRequestMapper
      extended by com.acsinet_solutions.cetia4.controller.map.MultipartBeanRequestMapper
All Implemented Interfaces:
RequestMapper

public class MultipartBeanRequestMapper
extends AbstractBeanRequestMapper

This class helps to perform mapping between form information and a DTO in a multipart environment. It is similar to BeanRequestMapper with the addition that FileItem properties are recognized and supported. FileItem properties are not mapped using SimpleMapping instances, so beware of this.

Author:
Santiago Arriaga

Nested Class Summary
 class MultipartBeanRequestMapper.MultipartDTOMapping
          mapping for multipart parameters.
 
Constructor Summary
MultipartBeanRequestMapper()
          Create a request mapper with no default mappings.
MultipartBeanRequestMapper(java.lang.Class targetClass)
          Create a request mapper for the given targetClass using reflection mappings over its simple properties using a nesting level of 3.
MultipartBeanRequestMapper(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 performMapping(java.util.List<org.apache.commons.fileupload.FileItem> items, java.lang.Object bean)
          Perform mapping from a list of file-items, to a bean.
 void performMapping(ParameterAccessor request, java.lang.Object bean)
          The parameter accessor must be a multipart context.
 void performMapping(javax.servlet.ServletRequest request, java.lang.Object bean)
          Perform the mapping from the HTTP request values to the provided bean in the case of the servlet API.
protected  Mapping tryCreateMapping(java.lang.String name, java.lang.Class type)
          Support for FileItem mappings is added.
 
Methods inherited from class com.acsinet_solutions.cetia4.controller.map.AbstractBeanRequestMapper
addMapping, getLogger, getMapping, getMappings, getSimpleMapping, getTargetClass, performMapping, removeMapping, setMapping, setValidator, validateAndCheck
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultipartBeanRequestMapper

public MultipartBeanRequestMapper()
Create a request mapper with no default mappings. mappings should be added to this class for it to be really useful ( unless a NOOP implementation is desired ).


MultipartBeanRequestMapper

public MultipartBeanRequestMapper(java.lang.Class targetClass)
Create a request mapper for the given targetClass using reflection mappings over its simple properties using a nesting level of 3. For arbitrary nesting level or no nesting use the more complete constructor.

See Also:
#BeanRequestMapper(Class,int)

MultipartBeanRequestMapper

public MultipartBeanRequestMapper(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 except for FileItem mappings where another class is used. For FileItem mapping, conversion to SimpleMapping in code is thus prohibited.

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

tryCreateMapping

protected Mapping tryCreateMapping(java.lang.String name,
                                   java.lang.Class type)
Support for FileItem mappings is added.

Overrides:
tryCreateMapping in class AbstractBeanRequestMapper

performMapping

public final void performMapping(javax.servlet.ServletRequest request,
                                 java.lang.Object bean)
                          throws ValidationException
Description copied from interface: RequestMapper
Perform the mapping from the HTTP request values to the provided bean in the case of the servlet API.

Validation is performed in addition to the mapping, if a validator was set for the current request mapper.

Throws:
ValidationException
See Also:
RequestMapper.setValidator(Validator)

performMapping

public final void performMapping(ParameterAccessor request,
                                 java.lang.Object bean)
                          throws ValidationException
The parameter accessor must be a multipart context. The mapping is performed in two parts; first mappings that are not related to FileItems are recognized and set in a wrapped ParameterAccessor instance so they can be mapped as typical; FileItem parameters will be mapped with an special ParameterAccessor class.

Throws:
ValidationException
See Also:
RequestMapper.setValidator(Validator)

performMapping

public final void performMapping(java.util.List<org.apache.commons.fileupload.FileItem> items,
                                 java.lang.Object bean)
                          throws ValidationException
Perform mapping from a list of file-items, to a bean. This method is useful when the file item list will be obtained first manually using manual configuration on the FileUpload API ( to set thresholds, strategies, etc. ) and finally the fileitem list will be mapped to a bean.

Throws:
ValidationException