On Advised POJOs with JGoodies Binding

While playing around with the idea of introducing the JGoodies Model into my existing POJOs, I ran into a few problems. I decided that a good place to start would be by leveraging the GOFObservable aspect found on the JBoss Wiki. Unfortunately this aspect won’t do what I need out of the box since it doesn’t use JavaBean conventions. So I extended the Model class to create a suitable Mixin that I was able to introduce to all of my POJOs, and it worked just fine.

However, making these advised POJOs work with the rest of the binding framework is a bit more challenging. Working with classes that are advised by introductions is odd. Suppose you have an Address class with the usual street, city, state, and zip code fields, and you have the appropriate getters and setters on the bean. If this class extended Model directly, you could add a PropertyChangeListener like this:


Address address = new Address();
address.addPropertyChangeListener(new StreetChangeListener());

When the same POJO gains PropertyChangeSupport though an introduction, you end up having to cast the Address class to an instance of the Mixin:


Address address = new Address();
ModelMixin mixin = (ModelMixin) address;
mixin.addPropertyChangeListener(new StreetChangeListener());

So with an introduction, the new behavior doesn’t have direct access to the properties of the original object and vice versa. JGoodies wasn’t designed to handle this scenario so my plan isn’t going to work out of the box.

Advertisement