com.marringtons.object
Class DTO

java.lang.Object
  extended bycom.marringtons.object.DTO

public class DTO
extends Object

This class provides facilities to deep copy data from one object to another. In the Adept library a DTO is any plain old Java object (pojo) used for transferring data from one class, package or module to another. The core requirement for a DTO is being able to load and extract data. To do this create a DTO object defining the objects to be played with and optionally a map of field names to copy.

 dto = new DTO( left, right, new Object[] {"p1", "param1", "p2", "param2"});
 dto = new DTO( left, right);
 dto.copy( right, left);
 dto.copy( left, right);
 right = (Right) dto.copy( left);
 left = (Left) dto.copy( right);
 

Author:
Paul Marrington

Constructor Summary
DTO(Object left, Object right)
          Create a DTO to transfer data to and from a DAO to any other sort of object.
DTO(Object left, Object right, Map fieldMap)
          Create a DTO to transfer data to and from a DAO to any other sort of object.
 
Method Summary
 Object copy(Object from)
          Copy data between one object and another where the field names match.
 Object copy(Object to, Object from)
          Copy data between one object and another where the field names match.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DTO

public DTO(Object left,
           Object right)
Create a DTO to transfer data to and from a DAO to any other sort of object. The objects passed are only used to get class details. Use an existing one if you have one. It will be unchanged. copy() will copy all public fields that have the same name.
 dto = new DTO( new LeftObject(), new RightObject());
 

Parameters:
left - DAO or general object.
right - DAO or general object.

DTO

public DTO(Object left,
           Object right,
           Map fieldMap)
Create a DTO to transfer data to and from a DAO to any other sort of object. The objects passed are only used to get class details. Use an existing one if you have one. It will be unchanged. Only the fields specified are copied.
 dto = new DTO( new LeftObject(), new RightObject(), Maps.load( new Object[]
   {
     "integer", "integer",
     "aLong", "anotherLong",
   }));
 

Parameters:
left - DAO or general object.
right - DAO or general object.
fieldMap - Map of fields to copy from source to target.
Method Detail

copy

public Object copy(Object to,
                   Object from)
Copy data between one object and another where the field names match. When they don't use a DTO that has a field map (@see DTO#DTO(Object, Object, Map)).
 dto = new DTO( left, right);
 dto.copy( right, left);
 dto.copy( left, right);
 

Parameters:
to - object to copy to or null to create a new one with a default constructor.
from - existing object to copy from.
Returns:
A pointer to the to object.

copy

public Object copy(Object from)
Copy data between one object and another where the field names match. When they don't use a DTO that has a field map (@see DTO#DTO(Object, Object, Map)).
 dto = new DTO( left, right);
 left = (LeftObject) dto.copy( right);
 right = (RightObject) dto.copy( left);
 

Parameters:
from - existing object to copy from.
Returns:
A pointer to the to object created and copied to.


Copyright © 2005 Paul Marrington http://library.marringtons.com