Package org.int4.dirk.spi.instantiation
Interface InstantiationContext<T>
-
- Type Parameters:
T- the type of the instances
public interface InstantiationContext<T>A context which can be used to create instances of typeTwhich match all its criteria. Sub contexts can be created which further narrow the set of possible matches.Contexts are often created for a specific injection target. This target may allow optional injection. If optional injection is allowed,
nullis a valid result in case there are no matches.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Tcreate()Creates an instance of typeT.java.util.List<T>createAll()Creates all instances of typeTthis context can provide.InstantiationContext<T>select(java.lang.annotation.Annotation... qualifiers)Creates anInstantiationContextbased on this context which further narrows the potential matching instances by requiring additional qualifiers.<U extends T>
InstantiationContext<U>select(java.lang.Class<U> subtype, java.lang.annotation.Annotation... qualifiers)Creates anInstantiationContextbased on this context which further narrows the potential matching instances to a subtype ofTand the given additional qualifiers.<U extends T>
InstantiationContext<U>select(java.lang.reflect.Type subtype, java.lang.annotation.Annotation... qualifiers)Creates anInstantiationContextbased on this context which further narrows the potential matching instances to a subtype ofTand the given additional qualifiers.
-
-
-
Method Detail
-
create
T create() throws CreationException, UnsatisfiedResolutionException, AmbiguousResolutionException, ScopeNotActiveException
Creates an instance of typeT. If there are multiple matching instances key given anAmbiguousResolutionExceptionexception is thrown. Returnsnullif there are no matches andnullis a considered valid result for this context.- Returns:
- an instance or
nullif there were no matches - Throws:
CreationException- when the creation of the instance failedUnsatisfiedResolutionException- when nothing matched andnullis not validAmbiguousResolutionException- when their are multiple potential instancesScopeNotActiveException- when the scope for the given type is not active
-
createAll
java.util.List<T> createAll() throws CreationException
Creates all instances of typeTthis context can provide. If there were no matchesnullis returned if valid for this context, otherwise returns an empty list. Scoped types which scope is currently inactive are excluded.- Returns:
- a list of instances, can be
nullor empty but never containsnull - Throws:
CreationException- when the creation of an instance failed
-
select
InstantiationContext<T> select(java.lang.annotation.Annotation... qualifiers)
Creates anInstantiationContextbased on this context which further narrows the potential matching instances by requiring additional qualifiers.- Parameters:
qualifiers- an array of additional qualifierAnnotations, cannot benull- Returns:
- an
InstantiationContext, nevernull - Throws:
java.lang.IllegalArgumentException- if any of the given annotation is not a qualifier
-
select
<U extends T> InstantiationContext<U> select(java.lang.Class<U> subtype, java.lang.annotation.Annotation... qualifiers)
Creates anInstantiationContextbased on this context which further narrows the potential matching instances to a subtype ofTand the given additional qualifiers.- Type Parameters:
U- a subtype of typeT- Parameters:
subtype- a subtype of typeT, cannot benullqualifiers- an array of additional qualifierAnnotations, cannot benull- Returns:
- an
InstantiationContext, nevernull - Throws:
java.lang.IllegalArgumentException- if any of the given annotation is not a qualifier
-
select
<U extends T> InstantiationContext<U> select(java.lang.reflect.Type subtype, java.lang.annotation.Annotation... qualifiers)
Creates anInstantiationContextbased on this context which further narrows the potential matching instances to a subtype ofTand the given additional qualifiers.- Type Parameters:
U- a subtype of typeT- Parameters:
subtype- a subtype of typeT, cannot benullqualifiers- an array of additional qualifierAnnotations, cannot benull- Returns:
- an
InstantiationContext, nevernull - Throws:
java.lang.IllegalArgumentException- if any of the given annotation is not a qualifierjava.lang.IllegalArgumentException- if the given type is not a subtype ofT
-
-