Package org.eclipse.jetty.cdi
Class CdiSpiDecorator
- java.lang.Object
-
- org.eclipse.jetty.cdi.CdiSpiDecorator
-
- All Implemented Interfaces:
Decorator
public class CdiSpiDecorator extends java.lang.Object implements Decorator
A Decorator that invokes the CDI provider within a webapp to decorate objects created by the contextsDecoratedObjectFactory
(typically Listeners, Filters and Servlets). The CDI provider is invoked usingMethodHandle
s to avoid any CDI instance or dependencies within the server scope. The code invoked is equivalent to:public <T> T decorate(T o) { BeanManager manager = CDI.current().getBeanManager(); manager.createInjectionTarget(manager.createAnnotatedType((Class<T>)o.getClass())) .inject(o,manager.createCreationalContext(null)); return o; }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
CdiSpiDecorator.Decorated
-
Field Summary
Fields Modifier and Type Field Description private ServletContextHandler
_context
private java.lang.invoke.MethodHandle
_createAnnotatedType
private java.lang.invoke.MethodHandle
_createCreationalContext
private java.lang.invoke.MethodHandle
_createInjectionTarget
private java.lang.invoke.MethodHandle
_current
private java.util.Map<java.lang.Object,CdiSpiDecorator.Decorated>
_decorated
private java.lang.invoke.MethodHandle
_dispose
private java.lang.invoke.MethodHandle
_getBeanManager
private java.lang.invoke.MethodHandle
_inject
private java.lang.invoke.MethodHandle
_release
private java.util.Set<java.lang.String>
_undecorated
private static Logger
LOG
static java.lang.String
MODE
-
Constructor Summary
Constructors Constructor Description CdiSpiDecorator(ServletContextHandler context)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addUndecoratable(java.lang.String... classname)
<T> T
decorate(T o)
Decorate an object.void
destroy(java.lang.Object o)
Destroy a decorated object.java.util.Set<java.lang.String>
getUndecoratable()
Get the set of classes that will not be decorated.protected boolean
isDecoratable(java.lang.Class<?> clazz)
Test if a class can be decorated.void
setUndecoratable(java.util.Set<java.lang.String> classnames)
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
MODE
public static final java.lang.String MODE
- See Also:
- Constant Field Values
-
_context
private final ServletContextHandler _context
-
_decorated
private final java.util.Map<java.lang.Object,CdiSpiDecorator.Decorated> _decorated
-
_current
private final java.lang.invoke.MethodHandle _current
-
_getBeanManager
private final java.lang.invoke.MethodHandle _getBeanManager
-
_createAnnotatedType
private final java.lang.invoke.MethodHandle _createAnnotatedType
-
_createInjectionTarget
private final java.lang.invoke.MethodHandle _createInjectionTarget
-
_createCreationalContext
private final java.lang.invoke.MethodHandle _createCreationalContext
-
_inject
private final java.lang.invoke.MethodHandle _inject
-
_dispose
private final java.lang.invoke.MethodHandle _dispose
-
_release
private final java.lang.invoke.MethodHandle _release
-
_undecorated
private final java.util.Set<java.lang.String> _undecorated
-
-
Constructor Detail
-
CdiSpiDecorator
public CdiSpiDecorator(ServletContextHandler context) throws java.lang.UnsupportedOperationException
- Throws:
java.lang.UnsupportedOperationException
-
-
Method Detail
-
isDecoratable
protected boolean isDecoratable(java.lang.Class<?> clazz)
Test if a class can be decorated. The default implementation checks the set fromgetUndecoratable()
on the class and all it's super classes.- Parameters:
clazz
- The class to check- Returns:
- True if the class and all it's super classes can be decorated
-
getUndecoratable
public java.util.Set<java.lang.String> getUndecoratable()
Get the set of classes that will not be decorated. The default set includes the listener from Weld that will itself setup decoration.- Returns:
- The modifiable set of class names that will not be decorated (ie
isDecoratable(Class)
will return false. - See Also:
isDecoratable(Class)
-
setUndecoratable
public void setUndecoratable(java.util.Set<java.lang.String> classnames)
- Parameters:
classnames
- The set of class names that will not be decorated.- See Also:
isDecoratable(Class)
-
addUndecoratable
public void addUndecoratable(java.lang.String... classname)
- Parameters:
classname
- A class name that will be added to the undecoratable classes set.- See Also:
getUndecoratable()
,isDecoratable(Class)
-
decorate
public <T> T decorate(T o)
Decorate an object.The signature of this method must match what is introspected for by the Jetty DecoratingListener class. It is invoked dynamically.
-
-