it.avutils.jmapper
Class JMapper<D,S>

java.lang.Object
  extended by it.avutils.jmapper.JMapper<D,S>
Type Parameters:
D - Type of the Destination Class
S - Type of Source Class
All Implemented Interfaces:
IJMapper<D,S>

public final class JMapper<D,S>
extends Object
implements IJMapper<D,S>

JMapper takes as input two classes, Destination and Source.
For Destination, we mean the instance that will be created or enhanced.
For Source, we mean the instance containing the data.
To execute the mapping, we must before configure one class between Destination and Source.

for example:


 class Destination {
 
  @JMap
  String id;
 
  @JMap("sourceField")
  String destinationField;
  
  String other;
  
  // getter and setter
 }
 
 class Source {
 
  String id;
 
  String sourceField;
  
  String other;
  
  // getter and setter
 }
 
then invoke the method GetDestination.

For example:
    
 Source source = new Source("id", "sourceField", "other");
 JMapper jmapper = new JMapper(Destination.class, Source.class);
 // new instance
 Destination destination = jmapper.getDestination(source); 
 // enrichment
 jmapper.getDestination(destination, source);

Author:
Alessandro Vurro

Constructor Summary
JMapper(Class<D> destination, Class<S> source)
          Constructs a JMapper that handles two classes: the class of destination and the class of source.
JMapper(Class<D> destination, Class<S> source, ChooseConfig chooseConfig)
          Constructs a JMapper that handles two classes: the class of destination and the class of source.
JMapper(Class<D> destination, Class<S> source, ChooseConfig config, String xmlPath)
          Constructs a JMapper that handles two classes: the class of destination and the class of source.
JMapper(Class<D> destination, Class<S> source, String xmlPath)
          Constructs a JMapper that handles two classes: the class of destination and the class of source.
 
Method Summary
 IMapper<D,S> createMapper(MapperBuilder mapper)
           
 D getDestination(D destination, S source)
          This Method returns the destination given in input enriched with data contained in source given in input
with this setting: NullPointerControlALL MappingType of DestinationALL_FIELDS MappingType of SourceALL_FIELDS
 D getDestination(D destination, S source, MappingType mtDestination, MappingType mtSource)
          This Method returns the destination given in input enriched with data contained in source given in input
with this setting: NullPointerControlALL MappingType of DestinationmtDestination MappingType of SourcemtSource
 D getDestination(D destination, S source, NullPointerControl nullPointerControl, MappingType mtDestination, MappingType mtSource)
          This Method returns the destination given in input enriched with data contained in source given in input
with this setting: NullPointerControlnullPointerControl MappingType of DestinationmtDestination MappingType of SourcemtSource
 D getDestination(S source)
          This method returns a new instance of Destination Class with this setting: NullPointerControlSOURCE MappingType of DestinationALL_FIELDS MappingType of SourceALL_FIELDS
 D getDestination(S source, MappingType mtSource)
          This method returns a new instance of Destination Class with this setting: NullPointerControlSOURCE MappingType of DestinationALL_FIELDS MappingType of SourcemtSource
 D getDestination(S source, NullPointerControl nullPointerControl, MappingType mtSource)
          This method returns a new instance of Destination Class with this setting: NullPointerControlnullPointerControl MappingType of DestinationALL_FIELDS MappingType of SourcemtSource
 D getDestinationWithoutControl(D destination, S source)
          This Method returns the destination given in input enriched with data contained in source given in input
with this setting: NullPointerControlNOT_ANY MappingType of DestinationALL_FIELDS MappingType of SourceALL_FIELDS
 D getDestinationWithoutControl(S source)
          This method returns a new instance of Destination Class with this setting: NullPointerControlNOT_ANY MappingType of DestinationALL_FIELDS MappingType of SourceALL_FIELDS
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JMapper

public JMapper(Class<D> destination,
               Class<S> source)
Constructs a JMapper that handles two classes: the class of destination and the class of source.
Configuration will be searched automatically.

Parameters:
destination - the Destination Class
source - the Source Class

JMapper

public JMapper(Class<D> destination,
               Class<S> source,
               ChooseConfig chooseConfig)
Constructs a JMapper that handles two classes: the class of destination and the class of source.
The configuration evaluated is the one received in input.

Parameters:
destination - the Destination Class
source - the Source Class
chooseConfig - the configuration to load
See Also:
ChooseConfig

JMapper

public JMapper(Class<D> destination,
               Class<S> source,
               String xmlPath)
Constructs a JMapper that handles two classes: the class of destination and the class of source.
Taking as input the path to the xml file.

Parameters:
destination - the Destination Class
source - the Source Class
xmlPath - xml configuration path
See Also:
ChooseConfig

JMapper

public JMapper(Class<D> destination,
               Class<S> source,
               ChooseConfig config,
               String xmlPath)
Constructs a JMapper that handles two classes: the class of destination and the class of source.
The configuration evaluated is the one received in input present in the xml configuration file.

Parameters:
destination - the Destination Class
source - the Source Class
config - the configuration to load
xmlPath - xml configuration path
See Also:
ChooseConfig
Method Detail

getDestination

public D getDestination(S source)
This method returns a new instance of Destination Class with this setting:
NullPointerControlSOURCE
MappingType of DestinationALL_FIELDS
MappingType of SourceALL_FIELDS

Specified by:
getDestination in interface IJMapper<D,S>
Parameters:
source - instance that contains the data
Returns:
new instance of destination
See Also:
NullPointerControl, MappingType

getDestinationWithoutControl

public D getDestinationWithoutControl(S source)
This method returns a new instance of Destination Class with this setting:
NullPointerControlNOT_ANY
MappingType of DestinationALL_FIELDS
MappingType of SourceALL_FIELDS

Specified by:
getDestinationWithoutControl in interface IJMapper<D,S>
Parameters:
source - instance that contains the data
Returns:
new instance of destination
See Also:
NullPointerControl, MappingType

getDestination

public D getDestination(D destination,
                        S source)
This Method returns the destination given in input enriched with data contained in source given in input
with this setting:
NullPointerControlALL
MappingType of DestinationALL_FIELDS
MappingType of SourceALL_FIELDS

Specified by:
getDestination in interface IJMapper<D,S>
Parameters:
destination - instance to enrich
source - instance that contains the data
Returns:
destination enriched
See Also:
NullPointerControl, MappingType

getDestinationWithoutControl

public D getDestinationWithoutControl(D destination,
                                      S source)
This Method returns the destination given in input enriched with data contained in source given in input
with this setting:
NullPointerControlNOT_ANY
MappingType of DestinationALL_FIELDS
MappingType of SourceALL_FIELDS

Specified by:
getDestinationWithoutControl in interface IJMapper<D,S>
Parameters:
destination - instance to enrich
source - instance that contains the data
Returns:
destination enriched
See Also:
NullPointerControl, MappingType

getDestination

public D getDestination(S source,
                        MappingType mtSource)
This method returns a new instance of Destination Class with this setting:
NullPointerControlSOURCE
MappingType of DestinationALL_FIELDS
MappingType of SourcemtSource

Specified by:
getDestination in interface IJMapper<D,S>
Parameters:
source - instance that contains the data
mtSource - type of mapping
Returns:
new instance of destination
See Also:
NullPointerControl, MappingType

getDestination

public D getDestination(S source,
                        NullPointerControl nullPointerControl,
                        MappingType mtSource)
This method returns a new instance of Destination Class with this setting:
NullPointerControlnullPointerControl
MappingType of DestinationALL_FIELDS
MappingType of SourcemtSource

Specified by:
getDestination in interface IJMapper<D,S>
Parameters:
source - instance that contains the data
nullPointerControl - type of control
mtSource - type of mapping
Returns:
new instance of destination
See Also:
NullPointerControl, MappingType

getDestination

public D getDestination(D destination,
                        S source,
                        MappingType mtDestination,
                        MappingType mtSource)
This Method returns the destination given in input enriched with data contained in source given in input
with this setting:
NullPointerControlALL
MappingType of DestinationmtDestination
MappingType of SourcemtSource

Specified by:
getDestination in interface IJMapper<D,S>
Parameters:
destination - instance to enrich
source - instance that contains the data
mtDestination - type of mapping of destination instance
mtSource - type of mapping of source instance
Returns:
destination enriched
See Also:
NullPointerControl, MappingType

getDestination

public D getDestination(D destination,
                        S source,
                        NullPointerControl nullPointerControl,
                        MappingType mtDestination,
                        MappingType mtSource)
This Method returns the destination given in input enriched with data contained in source given in input
with this setting:
NullPointerControlnullPointerControl
MappingType of DestinationmtDestination
MappingType of SourcemtSource

Specified by:
getDestination in interface IJMapper<D,S>
Parameters:
destination - instance to enrich
source - instance that contains the data
nullPointerControl - type of control
mtDestination - type of mapping of destination instance
mtSource - type of mapping of source instance
Returns:
destination enriched
See Also:
NullPointerControl, MappingType

createMapper

public IMapper<D,S> createMapper(MapperBuilder mapper)
                          throws javassist.NotFoundException,
                                 Exception
Throws:
javassist.NotFoundException
Exception


Copyright © 2013. All Rights Reserved.