Top Description Methods
javax.enterprise.inject.spi

public Interface InterceptionFactory<T>

Type Parameters
<T>
type for which the wrapper is created
Imports
javax.enterprise.context.Dependent, javax.enterprise.context.spi.CreationalContext, javax.enterprise.inject.Default, javax.enterprise.inject.spi.configurator.AnnotatedTypeConfigurator

InterceptionFactory allows to create a wrapper instance whose method invocations are intercepted by method interceptors and forwarded to a provided instance.

An implementation of InterceptionFactory may be obtained by calling BeanManager#createInterceptionFactory(CreationalContext, Class) to be used in the create method of a custom bean for example.

public class MyCustomBean implements Bean<MyClass> {

    BeanManager bm;

    public MyBean(BeanManager bm) {
       this.bm = bm;
    }

    public MyClass create(CreationalContext<MyClass> creationalContext) {

        InterceptionFactory factory = bm.createInterceptionFactory(creationalContext, MyClass.class);

        factory.configure().filterMethods(m -> m.getJavaMember().getName().equals("shouldBeTransactional")).findFirst()
                .ifPresent(m -> m.add(new AnnotationLiteral<Transactional>() {
                }));

        return factory.createInterceptedInstance(new MyClass());
    }
}

The container must also provide a built-in bean with scope Dependent, bean type InterceptionFactory and qualifier Default that can be injected in a producer method parameter.

@Produces
@RequestScoped
public MyClass produceMyClass(InterceptionFactory factory) {
    factory.configure().add(new AnnotationLiteral() {
    });
    return factory.createInterceptedInstance(new MyClass());
}

Instances of this class are neither reusable nor suitable for sharing between threads.

Author
Antoine Sabot-Durand
Since
2.0

Method Summary

Modifier and TypeMethod and Description
public AnnotatedTypeConfigurator<T>

Returns:

an AnnotatedTypeConfigurator to configure interceptors bindings
configure
()

Returns an AnnotatedTypeConfigurator initialized with the AnnotatedType created either for the class passed to BeanManager#createInterceptionFactory(CreationalContext, Class) or derived from the InterceptionFactory parameter injection point.

public T

Returns:

a wrapper instance
createInterceptedInstance
(T
The provided instance
instance
)

Returns a wrapper instance whose method invocations are intercepted by method interceptors and forwarded to a provided instance.

public InterceptionFactory<T>

Returns:

self
ignoreFinalMethods
()

Instructs the container to ignore all non-static, final methods with public, protected or default visibility declared by any class in the type hierarchy of the intercepted instance during invocation of createInterceptedInstance(Object).

Method Detail

configureback to summary
public AnnotatedTypeConfigurator<T> configure()

Returns an AnnotatedTypeConfigurator initialized with the AnnotatedType created either for the class passed to BeanManager#createInterceptionFactory(CreationalContext, Class) or derived from the InterceptionFactory parameter injection point.

The configurator allows to add or remove interceptor bindings used to associate interceptors with the wrapper instance returned by createInterceptedInstance(Object).

Each call returns the same AnnotatedTypeConfigurator.

Returns:AnnotatedTypeConfigurator<T>

an AnnotatedTypeConfigurator to configure interceptors bindings

createInterceptedInstanceback to summary
public T createInterceptedInstance(T instance)

Returns a wrapper instance whose method invocations are intercepted by method interceptors and forwarded to a provided instance.

This method should only be called once, subsequent calls will throw an IllegalStateException.

If T is not proxyable as defined in section 3.11 of the spec an javax.enterprise.inject.UnproxyableResolutionException exception is thrown. Calling ignoreFinalMethods() before this method can loosen these restrictions.

If the provided instance is an internal container construct (such as client proxy), non-portable behavior results.

Parameters
instance:T

The provided instance

Returns:T

a wrapper instance

ignoreFinalMethodsback to summary
public InterceptionFactory<T> ignoreFinalMethods()

Instructs the container to ignore all non-static, final methods with public, protected or default visibility declared by any class in the type hierarchy of the intercepted instance during invocation of createInterceptedInstance(Object).

Ignored methods should never be invoked upon the wrapper instance created by createInterceptedInstance(Object). Otherwise, unpredictable behavior results.

Returns:InterceptionFactory<T>

self