Java Reference
In-Depth Information
Once again, decorators are disabled by default. To enable the preceding decorator, you'll
need to add the following snippet to the beans.xml file:
<decorators>
<class>com.actionbazaar.buslogic.BidManagerFraudDetector</class>
</decorators>
Just as with interceptors, you can have multiple decorators on a given class. The order of
the decorators in the beans.xml file determines the order in which they'll be invoked. Now
that you have a handle on interceptors and decorators, let's see how you can reduce the
number of annotations convoluting your code.
12.5. Component stereotypes
As you've progressed through the features of CDI, you've been amassing an incredible
number of annotations. On some methods the annotations are longer than the method pro-
totype. If you look at many of these methods, you'll notice that in many cases you're re-
peating the same annotations over and over. This is quite a bit of redundant code to support.
Luckily, the developers behind CDI foresaw this problem and added something called a
stereotype to CDI.
It shouldn't be surprising that a stereotype is another annotation. But unlike the annotations
you've seen so far, it consolidates a set of annotations into one annotation. You create a new
annotation and add the annotations you want to consolidate into one to it. Let's start by con-
sidering the annotations on the getCurrentUser() method in the CurrentUser-
Bean class. The method prototype in this case is shorter than the annotations applied to it:
@Named @SessionScoped
public class CurrentUserBean implements Serializable {
@Produces @SessionScoped @AuthenticatedUser @Named
public User getCurrentUser() {
...
}
}
You can dramatically reduce the number of annotations on the method with a stereotype.
It's defined as follows:
@SessionScoped
@AuthenticatedUser
Search WWH ::




Custom Search