Class InstanceImpl<T>
- java.lang.Object
-
- org.jboss.weld.bean.builtin.AbstractFacade<T,Instance<T>>
-
- org.jboss.weld.bean.builtin.InstanceImpl<T>
-
- Type Parameters:
T
-
- All Implemented Interfaces:
Instance<T>
,Provider<T>
,Serializable
,Iterable<T>
,WeldInstance<T>
public class InstanceImpl<T> extends AbstractFacade<T,Instance<T>> implements WeldInstance<T>, Serializable
Helper implementation for Instance for getting instances- Author:
- Gavin King
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.jboss.weld.bean.builtin.AbstractFacade
AbstractFacade.AbstractFacadeSerializationProxy<T,X>
-
Nested classes/interfaces inherited from interface jakarta.enterprise.inject.Instance
Instance.Handle<T>
-
Nested classes/interfaces inherited from interface org.jboss.weld.inject.WeldInstance
WeldInstance.Handler<T>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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
.Instance.Handle<T>
getHandle()
Obtains an initialized contextual reference handle for a bean that has the required type and qualifiers and is eligible for injection.Comparator<Instance.Handle<?>>
getHandlePriorityComparator()
The returned comparator sorts handles by priority in descending order.WeldInstance.Handler<T>
getHandler()
This method is deprecated as a similar functioning method exists in CDI 4.0 and newer.Comparator<WeldInstance.Handler<?>>
getPriorityComparator()
This method is deprecated in favor ofWeldInstance.getHandlePriorityComparator()
which operates on a non-deprecatedInstance.Handle
interface.Iterable<WeldInstance.Handler<T>>
handlers()
This method is deprecated as a similar functioning method exists in CDI 4.0 and newer.Iterable<Instance.Handle<T>>
handles()
Allows iterating over contextual reference handles for all 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 parentInstance
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 parentInstance
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 parentInstance
was injected.Iterator<T>
iterator()
static <I> Instance<I>
of(InjectionPoint injectionPoint, CreationalContext<I> creationalContext, BeanManagerImpl beanManager)
<U extends T>
WeldInstance<U>select(TypeLiteral<U> subtype, Annotation... qualifiers)
Obtains a childInstance
for the given required type and additional required qualifiers.WeldInstance<T>
select(Annotation... qualifiers)
Obtains a childInstance
for the given additional required qualifiers.<U extends T>
WeldInstance<U>select(Class<U> subtype, Annotation... qualifiers)
Obtains a childInstance
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.String
toString()
Gets a string representation-
Methods inherited from class org.jboss.weld.bean.builtin.AbstractFacade
equals, getBeanManager, getCreationalContext, getFacadeType, getInjectionPoint, getQualifiers, getType, hashCode
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jakarta.enterprise.inject.Instance
handlesStream, stream
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface org.jboss.weld.inject.WeldInstance
handlersStream
-
-
-
-
Method Detail
-
of
public static <I> Instance<I> of(InjectionPoint injectionPoint, CreationalContext<I> creationalContext, BeanManagerImpl beanManager)
-
get
public T get()
Description copied from interface:Provider
Provides a fully-constructed and injected instance ofT
.
-
toString
public String toString()
Gets a string representation
-
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 parentInstance
was injected, orfalse
otherwise.
-
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 parentInstance
was injected, orfalse
otherwise.
-
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
-
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.
-
getHandle
public Instance.Handle<T> getHandle()
Description copied from interface:Instance
Obtains an initialized contextual reference handle for a bean that has the required type and qualifiers and is eligible for injection. Throws exceptions if there is no such bean or more than one.The contextual reference is obtained lazily, i.e. when first needed.
- Specified by:
getHandle
in interfaceInstance<T>
- Returns:
- a new
Instance.Handle
instnace
-
getHandler
public WeldInstance.Handler<T> getHandler()
Description copied from interface:WeldInstance
This method is deprecated as a similar functioning method exists in CDI 4.0 and newer. Users should instead useInstance.getHandle()
. 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 parentInstance
was injected, orfalse
otherwise.
-
handles
public Iterable<Instance.Handle<T>> handles()
Description copied from interface:Instance
Allows iterating over contextual reference handles for all beans that have the required type and required qualifiers and are eligible for injection.Note that the returned
Iterable
is stateless. Therefore, eachIterable.iterator()
produces a new set of handles.
-
handlers
public Iterable<WeldInstance.Handler<T>> handlers()
Description copied from interface:WeldInstance
This method is deprecated as a similar functioning method exists in CDI 4.0 and newer. Users should instead useInstance.handles()
. 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
This method is deprecated in favor ofWeldInstance.getHandlePriorityComparator()
which operates on a non-deprecatedInstance.Handle
interface. The returned comparator sorts handlers by priority in descending order.- A class-based bean whose annotated type has
jakarta.annotation.Priority
has the priority of valuejakarta.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
-
getHandlePriorityComparator
public Comparator<Instance.Handle<?>> getHandlePriorityComparator()
Description copied from interface:WeldInstance
The returned comparator sorts handles by priority in descending order.- A class-based bean whose annotated type has
jakarta.annotation.Priority
has the priority of valuejakarta.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:
getHandlePriorityComparator
in interfaceWeldInstance<T>
- Returns:
- a comparator instance
- A class-based bean whose annotated type has
-
-