Skip to content

Commit

Permalink
Added Binding an Interceptor to a Component
Browse files Browse the repository at this point in the history
Signed-off-by: thadumi <th.theodor.th@gmail.com>
  • Loading branch information
thadumi committed Mar 22, 2020
1 parent f32a261 commit b7c4603
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
Expand Up @@ -20,3 +20,5 @@ https://jakarta.ee/specifications/platform/9/.].
include::interceptor_binding_types/interceptor_binding_types.adoc[]

include::declaring_the_interceptor_bindings_of_an_interceptor.adoc[]

include::binding_an_interceptor_to_a_component.adoc[]
@@ -0,0 +1,78 @@
////
*******************************************************************
* Copyright (c) 2019 Eclipse Foundation
*
* This specification document is made available under the terms
* of the Eclipse Foundation Specification License v1.0, which is
* available at https://www.eclipse.org/legal/efsl.php.
*******************************************************************
////

[[binding_an_interceptor_to_a_component]]
== Binding an Interceptor to a Component

An interceptor may be bound to a component by
annotating the component class or a method or constructor of the
component class with the interceptor binding type.

In the following example, the
MonitoringInterceptor is applied to the target class. It will therefore
apply to all business methods of the class.

@Monitored

public class ShoppingCart \{ ... }



In this example, the MonitoringInterceptor is
applied to a single method:

public class ShoppingCart \{



@Monitored

public void placeOrder() \{ ... }



}

A component class or a method or constructor
of a component class may declare multiple interceptor bindings.

The set of interceptor bindings for a method
or constructor are those applied to the target class combined with those
applied at method level or constructor level. Note that the interceptor
bindings applied to the target class may include those inherited from
its superclasses. The CDI specification rules for the inheritance of
type-level metadata apply to the inheritance of interceptor bindings
from superclasses of the target class. See
link:intercept.html#a543[See
Jakarta Contexts and Dependency Injection (CDI specification), version 3.0.
https://jakarta.ee/specifications/cdi/3.0/.].

An interceptor binding declared on a method
or constructor replaces an interceptor binding of the same type declared
at class level or inherited from a superclasslink:#a572[7].

An extension specification may define
additional rules for combining interceptor bindings, such as
interceptors defined via a CDI stereotype.

If a component class declares or inherits a
class-level interceptor binding, it must not be declared final, or have
any non-static, non-private, final methods. If a component has a
class-level interceptor binding and is declared final or has a
non-static, non-private, final method, the container automatically
detects the problem and treats it as a definition error, and causes
deployment to fail.

If a non-static, non-private method of a
component class declares a method-level interceptor binding, neither the
method nor the component class may be declared final. If a non-static,
non-private, final method of a component has a method-level interceptor
binding, the container automatically detects the problem and treats it
as a definition error, and causes deployment to fail.

0 comments on commit b7c4603

Please sign in to comment.