com.acsinet_solutions.cetia4.controller.map
Class SimpleRequestMapper

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

public class SimpleRequestMapper
extends java.lang.Object
implements RequestMapper

This class performs a single mapping for single-field mappings; these types of mappings are common in basic field mappings.

Author:
Santiago Arriaga

Constructor Summary
SimpleRequestMapper()
          Create a request mapper with no configured mapping.
SimpleRequestMapper(java.lang.String name, java.lang.Class mappingType)
          Create a mapper for a single mapping type.
 
Method Summary
 void addMapping(Mapping mapping)
          Add a mapping to the mapper.
 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.
 void performMapping(ParameterAccessor request, java.lang.Object bean)
          Perform the mapping from the HTTP request values to the provided bean using a generic parameter accesor API.
 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.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleRequestMapper

public SimpleRequestMapper()
Create a request mapper with no configured mapping.


SimpleRequestMapper

public SimpleRequestMapper(java.lang.String name,
                           java.lang.Class mappingType)
Create a mapper for a single mapping type.

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

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)

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

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.

Specified by:
performMapping in interface RequestMapper
Throws:
ValidationException
See Also:
RequestMapper.setValidator(Validator)

performMapping

public final void performMapping(ParameterAccessor request,
                                 java.lang.Object bean)
                          throws ValidationException
Description copied from interface: RequestMapper
Perform the mapping from the HTTP request values to the provided bean using a generic parameter accesor API. This allows to use the request mapping classes in a more wide variety of environments, not only web based.

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

Specified by:
performMapping in interface RequestMapper
Throws:
ValidationException
See Also:
RequestMapper.setValidator(Validator)