Skip to main content


Showing posts from December, 2009

Adapter pattern revised

In my article about adapter pattern I have written an adapter that allows to access Ehcache cache instances through a simple Map interface. The basic idea was to write a Map implementation that actually, behind the scenes, was wrapping and hitting Ehcache. Everything looked great but Zach Bailey found a bug in my implementation – or more precisely – lack of functionality. He even provided a test case proving he is right. And sadly, he was ;-). Thank you Zach! The problem was with three map methods: keySet() , entrySet() and values() . If you read carefully their API you’ll find out that all these methods should return an "interactive" view backed by the underlying map so that changing the view is automatically reflected in the map that returned that view and vice-versa. For example, if you remove an item from the set returned by keySet() , corresponding map entry with this key value should be also removed. Unfortunately, in my implementation these methods simply retur

Chain of responsibility pattern meets Spring, JPA, Wicket and Apache CXF part 2/2

In the first part of this article I have shown a semi-real life example of the Chain of responsibility pattern (also mentioning about Iterator, Adapter and DTO). This behavioral design pattern has been used to control the process of registering a car, consisting of several steps. Everything worked es expected but modifying the chain configuration required application restart. Also not everyone might enjoy editing Spring context XML files. We will address this issues and make our application more dynamic. If not storing the chain configuration in Spring file directly, then where? Of course in the database, preferably using JPA. This is the JPA entity that will serve as a single handler configuration: public class RegistrationChainHandlerConfig implements Serializable { private int id; private String handlerName; private int priority; private boolean enabled; /* getters/setters */ } Each handler configured as a Spring bean is going to have a corresponding Registr