Java Reference
In-Depth Information
uses this decorator.
This simple decorator returns more detailed output than the encoded string returned by
the
CoderImpl.codeString
method. A more complex decorator could store inform-
ation in a database or perform some other business logic.
A decorator can be declared as an abstract class, so that it does not have to implement all
the business methods of the interface.
In order for a decorator to be invoked in a CDI application, it must, like an interceptor or
an alternative, be specified in the
beans.xml
file. For example, the
CoderDecorat-
or
class is specified as follows:
<decorators>
<class>decorators.CoderDecorator</class>
</decorators>
If an application uses more than one decorator, the decorators are invoked in the order in
which they are specified in the
beans.xml
file.
If an application has both interceptors and decorators, the interceptors are invoked first.
This means, in effect, that you cannot intercept a decorator.
Using Stereotypes in CDI Applications
A
stereotype
is a kind of annotation, applied to a bean, that incorporates other annotations.
Stereotypes can be particularly useful in large applications where you have a number of
beans that perform similar functions. A stereotype is a kind of annotation that specifies
the following:
• A default scope
• Zero or more interceptor bindings
• Optionally, a
@Named
annotation, guaranteeing default EL naming
• Optionally, an
@Alternative
annotation, specifying that all beans with this ste-
reotype are alternatives
A bean annotated with a particular stereotype will always use the specified annotations,
so you do not have to apply the same annotations to many beans.
For
example,
you
might
create
a
stereotype
named
Action
,
using
the
javax.enterprise.inject.Stereotype
annotation: