Package org.int4.dirk.spi.instantiation
Interface Instance<T>
-
- Type Parameters:
T- the type of the instances
public interface Instance<T>Allows dynamic access to instances created by an injector. AnInstancecan be used to create instances of typeTwhich match all its criteria. SubInstances can be created which further narrow the set of possible matches.Instances are created for specific injection targets. This target may be marked optional. If the target is optional,nullis a valid result in case theInstancecan provide no matches.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voiddestroy(T instance)Destroys an instance created with thisInstanceor one of its children.voiddestroyAll(java.util.Collection<T> instances)Destroys a collection of instances created with thisInstanceor one of its children.Tget()Creates an instance of typeT.java.util.List<T>getAll()Creates all instances of typeT.Instance<T>select(java.lang.annotation.Annotation... qualifiers)Creates anInstancebased on this one which further narrows the potential matching instances by requiring additional qualifiers.<U extends T>
Instance<U>select(java.lang.Class<U> subtype, java.lang.annotation.Annotation... qualifiers)Creates anInstancebased on this one which further narrows the potential matching instances to a subtype ofTand the given additional qualifiers.<U extends T>
Instance<U>select(TypeLiteral<U> subtype, java.lang.annotation.Annotation... qualifiers)Creates anInstancebased on this one which further narrows the potential matching instances to a subtype ofTand the given additional qualifiers.
-
-
-
Method Detail
-
get
T get() throws CreationException, UnsatisfiedResolutionException, AmbiguousResolutionException, ScopeNotActiveException
Creates an instance of typeT. If there are multiple matching instances anAmbiguousResolutionExceptionexception is thrown. If the target for which thisInstancewas created is optional, thennullis returned when there are no matches, otherwise anUnsatisfiedResolutionExceptionis thrown.- 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
-
getAll
java.util.List<T> getAll() throws CreationException
Creates all instances of typeT. If the target for which thisInstancewas created is optional, thennullis returned when there are no matches, otherwise an empty list is returned.Scoped types which scope is currently inactive are ignored, and so this call never produces scope related exceptions.
- Returns:
- a list of instances, can be
nullor empty but never containsnull - Throws:
CreationException- when the creation of an instance failed
-
destroy
void destroy(T instance)
Destroys an instance created with thisInstanceor one of its children.- Parameters:
instance- an instance to destroy, cannot benull
-
destroyAll
void destroyAll(java.util.Collection<T> instances)
Destroys a collection of instances created with thisInstanceor one of its children.- Parameters:
instances- a collection of instances to destroy, cannot benull
-
select
Instance<T> select(java.lang.annotation.Annotation... qualifiers)
Creates anInstancebased on this one which further narrows the potential matching instances by requiring additional qualifiers.- Parameters:
qualifiers- an array of additional qualifierAnnotations, cannot benull- Returns:
- an
Instance, nevernull - Throws:
java.lang.IllegalArgumentException- if any of the given annotations is not a qualifier
-
select
<U extends T> Instance<U> select(java.lang.Class<U> subtype, java.lang.annotation.Annotation... qualifiers)
Creates anInstancebased on this one 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
Instance, nevernull - Throws:
java.lang.IllegalArgumentException- if any of the given annotations is not a qualifier
-
select
<U extends T> Instance<U> select(TypeLiteral<U> subtype, java.lang.annotation.Annotation... qualifiers)
Creates anInstancebased on this one which further narrows the potential matching instances to a subtype ofTand the given additional qualifiers.- Type Parameters:
U- a subtype of typeT- Parameters:
subtype- specifies a subtype of typeT, cannot benullqualifiers- an array of additional qualifierAnnotations, cannot benull- Returns:
- an
Instance, nevernull - Throws:
java.lang.IllegalArgumentException- if any of the given annotations is not a qualifier
-
-