Cheers,
Hanson
Demo
=====
iimport java.lang.reflect.Method;
import net.sf.beanlib.hibernate3.Hibernate3BeanReplicator;
import net.sf.beanlib.provider.collector.PrivateSetterMethodCollector;
import net.sf.beanlib.spi.PropertyFilter;
import org.apache.commons.lang.builder.ToStringBuilder;
public class TestMain {
public static class Iap {
private String summary;
private String detail;
public String getSummary() { return summary; }
void setSummary(String summary) { this.summary = summary; }
public String getDetail() { return detail; }
void setDetail(String detail) { this.detail = detail; }
}
public static void main(String[]args) {
Hibernate3BeanReplicator replicator = new Hibernate3BeanReplicator();
replicator.initPropertyFilter(new PropertyFilter() {
public boolean propagate(String propertyName, Method readerMethod) {
System.out.printf("propertyName=%s,
readerMethod=%s\n", propertyName, readerMethod);
return "summary".equals(propertyName);
}
});
replicator.initSetterMethodCollector(new
PrivateSetterMethodCollector());
Iap from = new Iap();
from.setSummary("foo");
from.setDetail("bar");
System.out.println("from: " + ToStringBuilder.reflectionToString(from));
Iap newIap = replicator.copy(from);
System.out.println("to: " + ToStringBuilder.reflectionToString(newIap));
}
}
Sample Output
===========
from: TestMain$Iap@7f2ad19e[summary=foo,detail=bar]
propertyName=detail, readerMethod=public java.lang.String
TestMain$Iap.getDetail()
propertyName=summary, readerMethod=public java.lang.String
TestMain$Iap.getSummary()
to: TestMain$Iap@583e0ebb[summary=foo,detail=<null>]