Java Reference
In-Depth Information
@Interceptors(PrimaryInterceptor.class)
public void updateInfo(String firstName, String lastName, Date date)
{ ... }
The parameters can be accessed and modified using the
InvocationCon-
text.getParameters
and
InvocationContext.setParameters
methods,
respectively.
Intercepting Lifecycle Callback Events
Interceptors for lifecycle callback events (post-create and pre-destroy) may be defined in
the target class or in interceptor classes. The
@PostCreate
annotation is used to desig-
nate a method as a post-create lifecycle event interceptor. The
@PreDestroy
annotation
is used to designate a method as a pre-destroy lifecycle event interceptor.
Lifecycle event interceptors defined within the target class have the following form:
void
method-name
() { ... }
For example:
@PostCreate
void initialize() { ... }
Lifecycle event interceptors defined in an interceptor class have the following form:
void <
method-name
>(InvocationContext) { ... }
For example:
@PreDestroy
void cleanup(InvocationContext ctx) { ... }
Lifecycle interceptor methods can have public, private, protected, or package-level access,
and must not be declared static or final.
Lifecycle interceptor methods are called in an unspecified security and transaction con-
text. That is, portable Java EE applications should not assume the lifecycle event inter-
ceptor method has access to a security or transaction context. Only one interceptor method
for each lifecycle event (post-create and pre-destroy) is allowed per class.