org.cruxframework.crux.core.client.bean
Interface BeanCopier<A,B>

Type Parameters:
A - The type of the origin bean of the copy.
B - The type of the target bean of the copy.

public interface BeanCopier<A,B>

An utility interface to allow copies between two objects.

You can define copiers by extending this interface.

Imagine you have the following java bean classes defined as:

 public class Person {
    private String name;
    private int age;
    
    public String getName(){return name;}
    public void setName(String name){this.name = name;}
    public int getAge(){return age;}
    public void setAge(int age){this.age = age;}
 }
 
 public class User {
    private String login;
    private String name;
    private int age;
    
    public String getLogin(){return login;}
    public void setLogin(String login){this.login = login;}
    public String getName(){return name;}
    public void setName(String name){this.name = name;}
    public int getAge(){return age;}
    public void setAge(int age){this.age = age;}
 }
 

You can define the following interface to make copies between objects of the type Person to/from objects of type User, considering its property values:

 public interface PersonCopier extends BeanCopier {}
 

To use the copier, just call GWT.create on the given interface, or inject it on your class.

 public class MyController {
    @Inject
    private PersonCopier copier;
    
    @Expose
    public void myMethod() {
       // read two objects...
       copier.copyTo(person, user);
       copier.copyFrom(user, person);
       }
    }
 }
 

Note, on the above example, that class User has a property login and Person class does not. No problem, that property will be ignored during copies.

Author:
Thiago da Rosa de Bustamante

Method Summary
 void copyFrom(B from, A to)
          Copy property values from one object to another
 void copyTo(A from, B to)
          Copy property values from one object to another
 

Method Detail

copyTo

void copyTo(A from,
            B to)
Copy property values from one object to another

Parameters:
from - the origin object
to - the target object

copyFrom

void copyFrom(B from,
              A to)
Copy property values from one object to another

Parameters:
from - the origin object
to - the target object


Copyright © 2014. All rights reserved.