T - type for which the proxy is createdpublic interface InterceptionFactory<T>
An InterceptionFactory adds the services available for instances created by the container to any instance.
It makes each method invocation in the instance a business method invocation as defined in section 7.2 of the specification document
It will bind business methods only to @AroundInvoke interceptor methods.
An implementation of InterceptionFactory may be obtain 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 also provides a built-in bean for InterceptionFactory that can be injected in a producer method parameters to apply
interceptors on the produced instance.
@Produces @RequestScoped public MyClass produceMyClass(InterceptionFactoryInterceptionFactory is not reusablefactory) { factory.configure().add(new AnnotationLiteral () {}); return factory.createInterceptedInstance(new MyClass()); }
| Modifier and Type | Method and Description |
|---|---|
AnnotatedTypeConfigurator<T> |
configure()
Returns an
AnnotatedTypeConfigurator to allow addition of interceptor binding on the instance's methods. |
T |
createInterceptedInstance(T instance)
Returns an enhanced version of the instance for which each method invocations will be a business method invocation.
|
InterceptionFactory<T> |
ignoreFinalMethods()
Instructs the container to ignore all non-static, final methods with public, protected or default visibility declared on
any bean type of the specific bean during validation of injection points that require proxyable bean type.
|
InterceptionFactory<T> ignoreFinalMethods()
Instructs the container to ignore all non-static, final methods with public, protected or default visibility declared on any bean type of the specific bean during validation of injection points that require proxyable bean type.
These method should never be invoked upon bean instances. Otherwise, unpredictable behavior results.
AnnotatedTypeConfigurator<T> configure()
AnnotatedTypeConfigurator to allow addition of interceptor binding on the instance's methods.
The matching annotatedType will be used to apply the interceptors when calling createInterceptedInstance method.
Annotations that are not interceptor binding will be ignored.
Each call returns the same AnnotatedTypeConfigurator.AnnotatedTypeConfigurator to configure interceptors bindingsT createInterceptedInstance(T instance)
AnnotatedTypeConfigurator
defined with the configure method.
This method should ony be called once, subsequent calls will throw an IllegalStateException
If T is not proxyable as defined in section 3.11 of the spec an UnproxyableResolutionException exception is thrown.
Calling ignoreFinalMethods before this method can loosen this restriction.
If the instance was created by the container, this method does nothing and returns the provided instance.instance - on which container should add its servicesCopyright © 2008–2017 JBoss by Red Hat, Inc.. All rights reserved.