java.lang.Object
org.refcodes.decoupling.Dependency<T>
- Type Parameters:
T
- the generic type of theDependency
.
- All Implemented Interfaces:
Comparable<Dependency<T>>
,ClaimsAccessor
,InstanceMetricsAccessor
,ProfilesAccessor
,TagsAccessor
,org.refcodes.mixin.AliasAccessor
,org.refcodes.mixin.TypeAccessor<T>
,org.refcodes.schema.Schemable
- Direct Known Subclasses:
DependencyBuilder
public class Dependency<T>
extends Object
implements org.refcodes.schema.Schemable, org.refcodes.mixin.AliasAccessor, org.refcodes.mixin.TypeAccessor<T>, ProfilesAccessor, TagsAccessor, InstanceMetricsAccessor, ClaimsAccessor, Comparable<Dependency<T>>
A
Dependency
describes a component wired together by the
Reactor
with other components also defined by Dependency
instances.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.refcodes.mixin.AliasAccessor
org.refcodes.mixin.AliasAccessor.AliasBuilder<B extends org.refcodes.mixin.AliasAccessor.AliasBuilder<B>>, org.refcodes.mixin.AliasAccessor.AliasMutator, org.refcodes.mixin.AliasAccessor.AliasProperty
Nested classes/interfaces inherited from interface org.refcodes.decoupling.ClaimsAccessor
ClaimsAccessor.ClaimsBuilder<B extends ClaimsAccessor.ClaimsBuilder<B>>, ClaimsAccessor.ClaimsMutator, ClaimsAccessor.ClaimsProperty
Nested classes/interfaces inherited from interface org.refcodes.decoupling.InstanceMetricsAccessor
InstanceMetricsAccessor.InstanceMetricsBuilder<B extends InstanceMetricsAccessor.InstanceMetricsBuilder<B>>, InstanceMetricsAccessor.InstanceMetricsMutator, InstanceMetricsAccessor.InstanceMetricsProperty
Nested classes/interfaces inherited from interface org.refcodes.decoupling.ProfilesAccessor
ProfilesAccessor.ProfilesBuilder<B extends ProfilesAccessor.ProfilesBuilder<B>>, ProfilesAccessor.ProfilesMutator, ProfilesAccessor.ProfilesProperty
Nested classes/interfaces inherited from interface org.refcodes.decoupling.TagsAccessor
TagsAccessor.TagsBuilder<B extends TagsAccessor.TagsBuilder<B>>, TagsAccessor.TagsMutator, TagsAccessor.TagsProperty
Nested classes/interfaces inherited from interface org.refcodes.mixin.TypeAccessor
org.refcodes.mixin.TypeAccessor.TypeBuilder<T extends Object,
B extends org.refcodes.mixin.TypeAccessor.TypeBuilder<T, B>>, org.refcodes.mixin.TypeAccessor.TypeMutator<T extends Object>, org.refcodes.mixin.TypeAccessor.TypeProperty<T extends Object> -
Field Summary
Modifier and TypeFieldDescriptionprotected String
protected Dependency<?>[]
protected FactoryClaim<?,
T> protected InitializerClaim<?,
T> protected InstanceMetrics
protected Reactor
protected T
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(Dependency<T> aDependency) boolean
getAlias()
Claim[]
FactoryClaim<?,
T> Retrieves theFactoryClaim
, being aClaim
dedicated to fabricate (create) the dependency.Retrieves theInstanceMetrics
which describes how an instance for aDependency
is managed.T[]
Retrieves the instances produced by thisDependency
(as of theDependency
'sInstanceMetrics
configuration).Object[]
Retrieves the profiles assigned to theDependency
declaration.getSetup()
Retrieves theInitializerClaim
, being aClaim
dedicated to initialize the dependency after instantiation.Object[]
getTags()
Retrieves the tags assigned to theDependency
declaration.getType()
int
hashCode()
boolean
hasInstance
(Object aInstance) Determines whether thisDependency
element contains the provided instance.boolean
Determines weather thisDependency
element has at least one instance of its typegetType()
being created.boolean
hasProfile
(Object... aProfiles) Tests whether thisDependency
matches any of the provided profiles.protected T
Hook method to be overwritten by sub-classes in order to decorate new aspects to the produced instance.protected void
setInstance
(T aInstance) Sets the instance for theDependency
(the type is derived from the instance if not already set, the alias is derived from type if not already set).Creates theDependency
's instance using the preparedDependency
declarations (theDependency
declarations are prepared by theReactor
'sReactor.createContext()
and the like methods and in turn by the underlyingtoInstance()
methods).protected T
toInstance
(Dependency<?>[] aDependencies, Object... aProfiles) Creates theDependency
's instance as of its type using the providedDependency
declarations.protected T
toInstance
(Dependency<?>[] aDependencies, Set<Dependency<?>> aVistedDependencies, Object... aProfiles) Creates theDependency
's instance as of its type using the providedDependency
declarations.toSchema()
toString()
-
Field Details
-
_singleton
-
_alias
-
_claims
-
_dependencies
-
_instanceMetrics
-
_instances
-
_profiles
-
_tags
-
_type
-
_initializer
-
_factory
-
_reactor
-
-
Constructor Details
-
Dependency
protected Dependency()Instantiates a newDependency
.
-
-
Method Details
-
equals
-
getAlias
- Specified by:
getAlias
in interfaceorg.refcodes.mixin.AliasAccessor
-
getClaims
- Specified by:
getClaims
in interfaceClaimsAccessor
- Returns:
- The
Claim
instances stored by theClaim
instances property.
-
getSetup
Retrieves theInitializerClaim
, being aClaim
dedicated to initialize the dependency after instantiation.- Returns:
- The
InitializerClaim
being set for thisDependency
.
-
getFactory
Retrieves theFactoryClaim
, being aClaim
dedicated to fabricate (create) the dependency.- Returns:
- The
FactoryClaim
being set for thisDependency
.
-
getInstanceMetrics
Retrieves theInstanceMetrics
which describes how an instance for aDependency
is managed.- Specified by:
getInstanceMetrics
in interfaceInstanceMetricsAccessor
- Returns:
- The according
InstanceMetrics
.
-
getInstances
Retrieves the instances produced by thisDependency
(as of theDependency
'sInstanceMetrics
configuration).- Returns:
- The instances fabricated by this
Dependency
declaration.
-
getProfiles
Retrieves the profiles assigned to theDependency
declaration.- Specified by:
getProfiles
in interfaceProfilesAccessor
- Returns:
- The assigned profiles.
-
getTags
Retrieves the tags assigned to theDependency
declaration.- Specified by:
getTags
in interfaceTagsAccessor
- Returns:
- The assigned tags.
-
getType
- Specified by:
getType
in interfaceorg.refcodes.mixin.TypeAccessor<T>
-
hashCode
public int hashCode() -
hasInstances
public boolean hasInstances()Determines weather thisDependency
element has at least one instance of its typegetType()
being created.- Returns:
- True in case instances for this
Dependency
have already been created.
-
hasInstance
Determines whether thisDependency
element contains the provided instance.- Parameters:
aInstance
- The instance which is to be tested.- Returns:
- True in case this
Dependency
element contains the given instance, else false.
-
hasProfile
Tests whether thisDependency
matches any of the provided profiles.- Parameters:
aProfiles
- The profiles (as provided by theReactor
) to match against.- Returns:
- True in case this
Dependency
matches at least one of the provided profiles.
-
toInstance
Creates theDependency
's instance using the preparedDependency
declarations (theDependency
declarations are prepared by theReactor
'sReactor.createContext()
and the like methods and in turn by the underlyingtoInstance()
methods).- Returns:
- The instance retrieved from the
Dependency
. - Throws:
DependencyInstanciationException
- the dependency instantiation exception
-
toSchema
- Specified by:
toSchema
in interfaceorg.refcodes.schema.Schemable
-
compareTo
- Specified by:
compareTo
in interfaceComparable<T>
-
toString
-
setInstance
Sets the instance for theDependency
(the type is derived from the instance if not already set, the alias is derived from type if not already set).- Parameters:
aInstance
- The instance of the dependency;
-
toInstance
protected T toInstance(Dependency<?>[] aDependencies, Object... aProfiles) throws CircularDependencyException, AmbigousDependencyException, UnsatisfiedDependencyException, AmbigousClaimException, AmbigousInitializerException, AmbigousFactoryException, InstallDependencyException Creates theDependency
's instance as of its type using the providedDependency
declarations.- Parameters:
aDependencies
- theDependency
declarations to use.aProfiles
- The profiles as provided by theReactor
to take into account.- Returns:
- The instance retrieved from the
Dependency
. - Throws:
CircularDependencyException
- thrown in case there is some (transitive) circular dependency between twoDependency
instances.AmbigousDependencyException
- thrown in case for a requiredDependency
there are more than one matchingDependency
candidates in theReactor
.UnsatisfiedDependencyException
- thrown in case for a requiredDependency
none matchingDependency
candidates in theReactor
have been found (taking the profiles applied into account) for the constructors of the givenDependency
.AmbigousClaimException
- is thrown in case oneClaim
can be matched by multiple dependencies.AmbigousInitializerException
- is thrown in case oneInitializerClaim
instance can be matched by multiple dependencies.AmbigousFactoryException
- is thrown in case oneFactoryClaim
instance can be matched by multiple dependencies.InstallDependencyException
- is thrown when trying to install aDependency
into theContext
, though installing failed die to the dependency throwing an exception during the process of installing (e.g. instantiation).
-
toInstance
protected T toInstance(Dependency<?>[] aDependencies, Set<Dependency<?>> aVistedDependencies, Object... aProfiles) throws CircularDependencyException, AmbigousDependencyException, UnsatisfiedDependencyException, AmbigousClaimException, AmbigousInitializerException, AmbigousFactoryException, InstallDependencyException Creates theDependency
's instance as of its type using the providedDependency
declarations.- Parameters:
aDependencies
- theDependency
declarations to use.aVistedDependencies
- TheDependency
declarations already visited in order to detect a circular dependency situation.aProfiles
- The profiles as provided by theReactor
to take into account.- Returns:
- The instance retrieved from the
Dependency
. - Throws:
CircularDependencyException
- thrown in case there is some (transitive) circular dependency between twoDependency
instances.AmbigousDependencyException
- thrown in case for a requiredDependency
there are more than one matchingDependency
candidates in theReactor
.UnsatisfiedDependencyException
- thrown in case for a requiredDependency
none matchingDependency
candidates in theReactor
have been found (taking the profiles applied into account) for the constructors of the givenDependency
.AmbigousClaimException
- is thrown in case oneClaim
can be matched by multiple dependencies.AmbigousInitializerException
- is thrown in case oneInitializerClaim
instance can be matched by multiple dependencies.AmbigousFactoryException
- is thrown in case oneFactoryClaim
instance can be matched by multiple dependencies.InstallDependencyException
- is thrown when trying to install aDependency
into theContext
, though installing failed die to the dependency throwing an exception during the process of installing (e.g. instantiation).
-
intercept
Hook method to be overwritten by sub-classes in order to decorate new aspects to the produced instance.- Parameters:
aInstance
- The instance to be post processed.- Returns:
- The (new) post processed instance.
-