After my first article about Java EE6 decorators, it got some attention on dzone. I got some comments telling me the example isn’t exposing the true power of the decorator feature.
The first thing I did not mention in my previous post is that we can combine a number of decorators and choose the order we want them executed.
If you have a use case for it, you can easily define 2 decorators, by just defining them in the beans.xml file like this.
<decorators> <class>be.styledideas.blog.decorator.HighDecorator</class> <class>be.styledideas.blog.decorator.LowDecorator</class> </decorators>
So when we call our decorated class, we get the highdecorator entry, low decorator entry, actual decorated class, low decorator exit, highdecorator exit. So the decorator sequence in the file does matter.
The true power of the Decorator feature in java EE6 is the ability to combine it with CDI annotations. As example I’ll use an Social media feed processor.
So I have created an interface