org.jbeanmapper
Class BeanMapper

java.lang.Object
  extended byorg.jbeanmapper.BeanMapper

public class BeanMapper
extends java.lang.Object

Maps a JavaBean to another JavaBean. Mapping is not thread safe unless an "unmodifiable" view of the mapper is used (see BeanMappers.unmodifiableBeanMapper).

Author:
Brian Pugh

Constructor Summary
BeanMapper()
           
 
Method Summary
 void addBeanMapping(BeanMapping mapping)
          Add a new BeanMapping rule.
 java.util.Map getBeanMappings()
          Get all the registered bean mappings.
 Configurator getConfigurator()
          Get the configurator for this mapper.
 java.lang.Object map(java.lang.Object sourceBean)
          Map the sourceBean to a destination bean.
 java.lang.Object map(java.lang.Object sourceBean, java.lang.Class targetClass)
          Register that the sourceBean class should be mapped to targetClass, then map the source bean.
 void registerBeanMapping(java.lang.Class srcClass, java.lang.Class targetClass)
          Register that srcClass should be mapped to targetClass.
 void registerBeanMappings(org.xml.sax.InputSource inputSource)
          Register the bean mappings specified in the mapping domcument in the InputSource.
 void setConfigurator(Configurator configurator)
          Set the configurator for this mapper.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanMapper

public BeanMapper()
Method Detail

registerBeanMapping

public void registerBeanMapping(java.lang.Class srcClass,
                                java.lang.Class targetClass)
                         throws BeanMappingException
Register that srcClass should be mapped to targetClass. If srcClass has already been registered to a target class, previous rule will be overwritten.

Parameters:
srcClass - the class to be mapped.
targetClass - the class to be mapped to.
Throws:
BeanMappingException - if registration of the mapping fails.

registerBeanMappings

public void registerBeanMappings(org.xml.sax.InputSource inputSource)
                          throws BeanMappingException
Register the bean mappings specified in the mapping domcument in the InputSource.

Parameters:
inputSource - the source of the mapping document. Not null.
Throws:
BeanMappingException - if registration fails.

map

public java.lang.Object map(java.lang.Object sourceBean)
                     throws BeanMappingException
Map the sourceBean to a destination bean.

Parameters:
sourceBean - the bean to be mapped.
Returns:
a mapped bean.
Throws:
BeanMappingException - if mapping fails.

map

public java.lang.Object map(java.lang.Object sourceBean,
                            java.lang.Class targetClass)
                     throws BeanMappingException
Register that the sourceBean class should be mapped to targetClass, then map the source bean.

Parameters:
sourceBean - bean to be mapped.
targetClass - bean to be mapped to.
Returns:
a mapped bean of type targetClass.
Throws:
BeanMappingException - if the mapping fails.

getBeanMappings

public java.util.Map getBeanMappings()
Get all the registered bean mappings.

Returns:

addBeanMapping

public void addBeanMapping(BeanMapping mapping)
Add a new BeanMapping rule. If an existing rule exists for the srcClass, it will be overwritten.

Parameters:
mapping - the BeanMapping to be added.

getConfigurator

public Configurator getConfigurator()
Get the configurator for this mapper.

Returns:
The configurator for this mapper.

setConfigurator

public void setConfigurator(Configurator configurator)
Set the configurator for this mapper.

Parameters:
configurator - The configurator for this mapper.