PropertyFilter not being called

33 views
Skip to first unread message

Joseph

unread,
Dec 9, 2010, 2:37:15 PM12/9/10
to beanlib
I am trying to filter out a specific property, so I implemented a
standard PropertyFilter. I included a println in the propagate method
to see the results of the filter and noticed that the filter is never
called. Is there something wrong with the way I am using the filter:

Hibernate3BeanReplicator replicator = new Hibernate3BeanReplicator();

replicator.initPropertyFilter(idVetoer);
replicator.initSetterMethodCollector(new
PrivateSetterMethodCollector());

Iap newIap = replicator.copy(iap);

I am using beanlib 5.0.3 beta and Hibernate 3.6.

Any suggestions?

Hanson Char

unread,
Dec 9, 2010, 8:09:45 PM12/9/10
to bea...@googlegroups.com
It should work.  The demo code below should be pretty self-explanatory.

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>]

Joseph

unread,
Dec 9, 2010, 10:14:02 PM12/9/10
to beanlib
Thanks for the prompt response. It turns out the PropertyFilter
variable was being set to null and that's why nothing was happening.
I was tipped off by implementing an anonymous class like your
example. Dumb mistake on my part, but you helped me figure it out, so
thanks again.
Reply all
Reply to author
Forward
0 new messages