Class AbstractCDI<T>
- java.lang.Object
-
- javax.enterprise.inject.spi.CDI<T>
-
- org.jboss.weld.AbstractCDI<T>
-
- Type Parameters:
T
-
- All Implemented Interfaces:
Iterable<T>
,Instance<T>
,Provider<T>
,WeldInstance<T>
- Direct Known Subclasses:
SimpleCDI
public abstract class AbstractCDI<T> extends CDI<T> implements WeldInstance<T>
Abstract implementation of CDI which forwards all Instance methods to a delegate. Furthermore, it allows the calling class to be identified using thegetCallingClassName()
method.- Author:
- Jozef Hartinger
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.weld.inject.WeldInstance
WeldInstance.Handler<T>
-
-
Field Summary
Fields Modifier and Type Field Description protected Set<String>
knownClassNames
-
Fields inherited from class javax.enterprise.inject.spi.CDI
configuredProvider, discoveredProviders
-
-
Constructor Summary
Constructors Constructor Description AbstractCDI()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkState()
Check whether the container is in a "valid" state, no-op by default.void
destroy(T instance)
When called, the container destroys the instance if the active context object for the scope type of the bean supports destroying bean instances.T
get()
Provides a fully-constructed and injected instance ofT
.protected String
getCallingClassName()
ExaminesStackTraceElement
s to figure out which class invoked a method onCDI
.WeldInstance.Handler<T>
getHandler()
Obtains an initialized contextual reference handler for the bean that has the required type and required qualifiers and is eligible for injection.protected WeldInstance<T>
getInstance()
Subclasses are allowed to override the default behavior, i.e.Comparator<WeldInstance.Handler<?>>
getPriorityComparator()
The returned comparator sorts handlers by priority in descending order.Iterable<WeldInstance.Handler<T>>
handlers()
Allows to iterate over contextual reference handlers for all the beans that have the required type and required qualifiers and are eligible for injection.boolean
isAmbiguous()
Determines if there is more than one bean that matches the required type and qualifiers and is eligible for injection into the class into which the parent Instance was injected.boolean
isResolvable()
Determines if there is exactly one bean that matches the required type and qualifiers and is eligible for injection into the class into which the parent Instance was injected.boolean
isUnsatisfied()
Determines if there is no bean that matches the required type and qualifiers and is eligible for injection into the class into which the parent Instance was injected.Iterator<T>
iterator()
WeldInstance<T>
select(Annotation... qualifiers)
Obtains a child Instance for the given additional required qualifiers.<U extends T>
WeldInstance<U>select(Class<U> subtype, Annotation... qualifiers)
Obtains a child Instance for the given required type and additional required qualifiers.<X> WeldInstance<X>
select(Type subtype, Annotation... qualifiers)
Obtains a childInstance
for the given required type and additional required qualifiers.<U extends T>
WeldInstance<U>select(TypeLiteral<U> subtype, Annotation... qualifiers)
Obtains a child Instance for the given required type and additional required qualifiers.-
Methods inherited from class javax.enterprise.inject.spi.CDI
current, getBeanManager, setCDIProvider
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface org.jboss.weld.inject.WeldInstance
handlersStream
-
-
-
-
Method Detail
-
get
public T get()
Description copied from interface:Provider
Provides a fully-constructed and injected instance ofT
.
-
select
public WeldInstance<T> select(Annotation... qualifiers)
Description copied from interface:Instance
Obtains a child Instance for the given additional required qualifiers.
-
select
public <U extends T> WeldInstance<U> select(Class<U> subtype, Annotation... qualifiers)
Description copied from interface:Instance
Obtains a child Instance for the given required type and additional required qualifiers.
-
select
public <U extends T> WeldInstance<U> select(TypeLiteral<U> subtype, Annotation... qualifiers)
Description copied from interface:Instance
Obtains a child Instance for the given required type and additional required qualifiers.
- Specified by:
select
in interfaceInstance<T>
- Specified by:
select
in interfaceWeldInstance<T>
- Type Parameters:
U
- the required type- Parameters:
subtype
- aTypeLiteral
representing the required typequalifiers
- the additional required qualifiers- Returns:
- the child Instance
-
select
public <X> WeldInstance<X> select(Type subtype, Annotation... qualifiers)
Description copied from interface:WeldInstance
Obtains a child
Instance
for the given required type and additional required qualifiers. Must be invoked onInstance<T>
where T isObject
.- Specified by:
select
in interfaceWeldInstance<T>
- Type Parameters:
X
- the required type- Parameters:
subtype
- aType
representing the required typequalifiers
- the additional required qualifiers- Returns:
- the child
Instance
-
isUnsatisfied
public boolean isUnsatisfied()
Description copied from interface:Instance
Determines if there is no bean that matches the required type and qualifiers and is eligible for injection into the class into which the parent Instance was injected.
- Specified by:
isUnsatisfied
in interfaceInstance<T>
- Returns:
- true if there is no bean that matches the required type and qualifiers and is eligible for injection into the class into which the parent Instance was injected, or false otherwise.
-
isAmbiguous
public boolean isAmbiguous()
Description copied from interface:Instance
Determines if there is more than one bean that matches the required type and qualifiers and is eligible for injection into the class into which the parent Instance was injected.
- Specified by:
isAmbiguous
in interfaceInstance<T>
- Returns:
- true if there is more than one bean that matches the required type and qualifiers and is eligible for injection into the class into which the parent Instance was injected, or false otherwise.
-
destroy
public void destroy(T instance)
Description copied from interface:Instance
When called, the container destroys the instance if the active context object for the scope type of the bean supports destroying bean instances. All normal scoped built-in contexts support destroying bean instances.
The instance passed should either be a dependent scoped bean instance obtained from the same
Instance
object, or the client proxy for a normal scoped bean instance.
-
getHandler
public WeldInstance.Handler<T> getHandler()
Description copied from interface:WeldInstance
Obtains an initialized contextual reference handler for the bean that has the required type and required qualifiers and is eligible for injection.The contextual reference is obtained lazily, i.e. when first needed.
- Specified by:
getHandler
in interfaceWeldInstance<T>
- Returns:
- a new handler
-
isResolvable
public boolean isResolvable()
Description copied from interface:Instance
Determines if there is exactly one bean that matches the required type and qualifiers and is eligible for injection into the class into which the parent Instance was injected.
- Specified by:
isResolvable
in interfaceInstance<T>
- Returns:
- true if there is exactly one bean that matches the required type and qualifiers and is eligible for injection into the class into which the parent Instance was injected, or false otherwise.
-
handlers
public Iterable<WeldInstance.Handler<T>> handlers()
Description copied from interface:WeldInstance
Allows to iterate over contextual reference handlers for all the beans that have the required type and required qualifiers and are eligible for injection.Note that the returned
Iterable
is stateless and so eachIterable.iterator()
produces a new set of handlers.- Specified by:
handlers
in interfaceWeldInstance<T>
- Returns:
- a new iterable
-
getPriorityComparator
public Comparator<WeldInstance.Handler<?>> getPriorityComparator()
Description copied from interface:WeldInstance
The returned comparator sorts handlers by priority in descending order.- A class-based bean whose annotated type has
javax.annotation.Priority
has the priority of valuejavax.annotation.Priority#value()
- A custom bean which implements
Prioritized
has the priority of valuePrioritized.getPriority()
- Any other bean has the priority of value 0
- Specified by:
getPriorityComparator
in interfaceWeldInstance<T>
- Returns:
- a comparator instance
- A class-based bean whose annotated type has
-
getCallingClassName
protected String getCallingClassName()
ExaminesStackTraceElement
s to figure out which class invoked a method onCDI
.
-
getInstance
protected WeldInstance<T> getInstance()
Subclasses are allowed to override the default behavior, i.e. to cache an instance per BeanManager.- Returns:
- the
Instance
the relevant calls are delegated to
-
checkState
protected void checkState()
Check whether the container is in a "valid" state, no-op by default.Subclasses are allowed to override the default behavior, i.e. to check whether a container is running.
-
-