org.springframework.binding.mapping
Class MappingBuilder

java.lang.Object
  extended by org.springframework.binding.mapping.MappingBuilder

public class MappingBuilder
extends java.lang.Object

A stateful builder that builds Mapping objects. Designed for convenience to build mappings in a clear, readable manner.

Example usage:

 MappingBuilder mapping = new MappingBuilder();
 Mapping result = mapping.source("foo").target("bar").from(String.class).to(Long.class).value();
 
Calling the value() result method clears out this builder's state so it can be reused to build another mapping.

Author:
Keith Donald, Erwin Vervaet

Constructor Summary
MappingBuilder(ExpressionParser expressionParser)
          Creates a mapping builder that uses the expression parser to parse attribute mapping expressions.
 
Method Summary
 MappingBuilder from(java.lang.Class sourceType)
          Sets the expected type of the object returned by evaluating the source expression.
 MappingBuilder required()
          Marks the mapping to be built a "required" mapping.
 void reset()
          Reset this mapping builder.
 void setConversionService(ConversionService conversionService)
          Sets the conversion service that will convert the object returned by evaluating the source expression to the to(Class) type if necessary.
 MappingBuilder source(java.lang.String expressionString)
          Sets the source expression of the mapping built by this builder.
 MappingBuilder target(java.lang.String expressionString)
          Sets the target property expression of the mapping built by this builder.
 MappingBuilder targetCollection(java.lang.String expressionString)
          Sets the target collection of the mapping built by this builder.
 MappingBuilder to(java.lang.Class targetType)
          Sets the target type of the property writeable by the target expression.
 Mapping value()
          The logical GoF builder getResult method, returning a fully constructed Mapping from the configured pieces.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MappingBuilder

public MappingBuilder(ExpressionParser expressionParser)
Creates a mapping builder that uses the expression parser to parse attribute mapping expressions.

Parameters:
expressionParser - the expression parser
Method Detail

setConversionService

public void setConversionService(ConversionService conversionService)
Sets the conversion service that will convert the object returned by evaluating the source expression to the to(Class) type if necessary.

Parameters:
conversionService - the conversion service

source

public MappingBuilder source(java.lang.String expressionString)
Sets the source expression of the mapping built by this builder.

Parameters:
expressionString - the expression string
Returns:
this, to support call-chaining

target

public MappingBuilder target(java.lang.String expressionString)
Sets the target property expression of the mapping built by this builder.

Parameters:
expressionString - the expression string
Returns:
this, to support call-chaining

targetCollection

public MappingBuilder targetCollection(java.lang.String expressionString)
Sets the target collection of the mapping built by this builder.

Parameters:
expressionString - the expression string, resolving a collection
Returns:
this, to support call-chaining

from

public MappingBuilder from(java.lang.Class sourceType)
Sets the expected type of the object returned by evaluating the source expression. Used in conjunction with to(Class) to perform a type conversion during the mapping process.

Parameters:
sourceType - the source type
Returns:
this, to support call-chaining

to

public MappingBuilder to(java.lang.Class targetType)
Sets the target type of the property writeable by the target expression.

Parameters:
targetType - the target type
Returns:
this, to support call-chaining

required

public MappingBuilder required()
Marks the mapping to be built a "required" mapping.

Returns:
this, to support call-chaining

value

public Mapping value()
The logical GoF builder getResult method, returning a fully constructed Mapping from the configured pieces. Once called, the state of this builder is nulled out to support building a new mapping object again.

Returns:
the mapping result

reset

public void reset()
Reset this mapping builder.



Copyright � 2004-2007. All Rights Reserved.