Javabeans, BeanInfo and cglib
March 2, 2007 | In Java | No CommentsHave: Pretty big Javabean object model with BeanInfo classes. No support for event listeners or firePropertyChange() in setters.
Want: Same, but with support for adding PropertyChangeListeners. Preferably without changing the object model code.
The object model is now supposed to be used in a Swing application based on Netbeans Platform. The platform has these nice wrappers from Javabeans with BeanInfo classes, showing the icons and configuring the Property Sheet for us. Nice.
When we add support for PropertyChangeListeners we also get instant update between the Explorer view, the editor window and the Property Sheet in Netbeans. Really needed to give a good UI.
I got inspired by Xavier Hanin to use cglib to generate support for firePropertyChange from my Javabeans, by letting cglib implement an Observable interface like this: Observable.java. It inserts all the code needed to register listeners on the properties of every Javabean.
It works really well, except that it breaks my use of BeanInfo classes. I guess this is because cglib decorate the Javabean by extending it. The new class is called something like MyBean$$EnhancerByCGLIBf989dfbb, and then the resolving of MyBeanBeanInfo fails.
But wait, if cglib implements Observable on the fly, why can’t it also implement the BeanInfo interface? It’s an undocumented feature that the Interceptor first checks if the class itself implements BeanInfo, before it looks for a MyBeanBeanInfo class (and if that doesn’t exist it fall back to Reflection).
So I let cglib add another interface to my proxy Javabean. Since I have access to the “real” bean in the proxy I just get the BeanInfo with the Introspector and delegate all BeanInfo methods to it.
It worked fine when I tested it:
BeanInfo proxyBean = (BeanInfo) BeanEnhancer.enhance(myBean);
proxyBean.getBeanDescriptor().getShortDescription()
It returned the description set in the BeanInfo class. Sweet.
But it fails when I use Introspector.getBeanInfo(proxyBean.getClass()). It fails somewhere inside Introspector.java. It’s something with proxyBean.getClass().newInstance().
java.lang.NoSuchMethodError: MyBean.getAdditionalBeanInfo()[Ljava/beans/BeanInfo;
at MyBean$$EnhancerByCGLIB$$dd36606c.getAdditionalBeanInfo()
at java.beans.Introspector.(Introspector.java:371);
I really liked the idea though…
In bed with spammers?
March 1, 2007 | In Uncategorized | 1 CommentMy hosting provider, LayeredTech, has been OK so far, compared to my previous experiences. But today I got a “Undelivered Mail Returned to Sender” message from O’Reilly:
host smtp2.oreilly.com[209.58.173.22]
said: 550-Host 72.232.198.90 is blocked: 550 Mail refused from spam source
550 (layeredtech.com) by local blocking list (in reply to RCPT TO command)
O’Reilly is probably not the only organization blocking email from all of LayeredTech’s networks. After some searching it seems that LayeredTech has a slow abuse department. They don’t act against spammer quickly enough. Some even say that they host spammers willingly. I don’t know.
I don’t want to move my stuff again. It’s working fine now. Please, LayeredTech - deal with the situation and kick out any spammers left. Then make a public statement so that O’Reilly and others will remove the block.