public class Dependency
extends java.lang.Object
Dependency
implements a manager that is used to manage DependencyScope
instances. It provides a static API with methods for activating and deactivating
DependencyScope
instances.Constructor and Description |
---|
Dependency() |
Modifier and Type | Method and Description |
---|---|
static void |
activateScope(DependencyScopeOwner owner)
Activates a
DependencyScope for the given DependencyScopeOwner . |
static void |
activateScope(DependencyScopeOwner owner,
DependencyScope scope)
Activates the given
DependencyScope for the given DependencyScopeOwner . |
static void |
addDependant(java.lang.Object dependant)
Adds the given
Object as an dependant to currently active scope - if one exists. |
static DependencyScope |
addScope(DependencyScopeOwner owner)
Adds the
DependencyScope owner by the given DependencyScopeOwner to
the HashMap of the current DependencyScope s. |
static void |
deactivateScope(DependencyScopeOwner owner)
Deactivates a
DependencyScope managed by the given DependencyScopeOwner . |
static void |
disposeScope(DependencyScopeOwner owner)
Disposes the
DependencyScope of the given DependencyScopeOwner . |
static void |
disposeScopes()
Invoked to dispose all the registered
DependencyScope s. |
static <T> T |
get(java.lang.Class<? extends DependencyScope> scopeClass,
java.lang.Class<T> dependencyType)
Gets a dependency of the specified type.
|
static <T> T |
get(java.lang.Class<? extends DependencyScope> scopeClass,
java.lang.Class<T> dependencyType,
java.lang.Object dependant)
Gets a dependency of the specified type.
|
static <T> T |
get(java.lang.Class<T> dependencyType)
Gets a dependency of the specified type.
|
static <T> T |
get(java.lang.Class<T> dependencyType,
java.lang.Object dependant)
Gets a dependency of the specified type.
|
static <T> T |
get(DependencyScope scope,
java.lang.Class<T> dependencyType)
Gets a dependency of the specified type.
|
static <T> T |
get(DependencyScope scope,
java.lang.Class<T> dependencyType,
java.lang.Object dependant)
Gets a dependency of the specified type.
|
static DependencyScope |
getActiveScope()
Gets the
DependencyScope that is set to be currently the active one. |
static <T> java.util.Collection<T> |
getAll(java.lang.Class<? extends DependencyScope> scopeType,
java.lang.Class<T> dependencyType)
Gets all dependency of the specified type.
|
static <T> java.util.Collection<T> |
getAll(java.lang.Class<? extends DependencyScope> scopeClass,
java.lang.Class<T> dependencyType,
java.lang.Object dependant)
Gets all dependencies of the specified type.
|
static <T> java.util.Collection<T> |
getAll(java.lang.Class<T> dependencyType)
Gets all dependencies of the specified type.
|
static <T> java.util.Collection<T> |
getAll(java.lang.Class<T> dependencyType,
java.lang.Object dependant)
Gets all dependencies of the specified type.
|
static <T> java.util.Collection<T> |
getAll(DependencyScope scope,
java.lang.Class<T> dependencyType)
Gets all dependencies of the specified type.
|
static <T> java.util.Collection<T> |
getAll(DependencyScope scope,
java.lang.Class<T> dependencyType,
java.lang.Object dependant)
Gets all dependencies of the specified type.
|
static DependencyScope |
getAppScope()
Gets the application level
DependencyScope . |
static <T extends DependencyScope> |
getScope(java.lang.Class<? extends DependencyScope> scopeClass)
Gets a specified
DependencyScope . |
static <T extends DependencyScope> |
getScope(java.lang.Class<? extends DependencyScope> scopeClass,
boolean createInstance)
Gets a specified
DependencyScope . |
static <T extends DependencyScope> |
getScope(DependencyScopeOwner owner,
boolean createInstance)
Gets a
DependencyScope managed by the given DependencyScopeOwner . |
static <T extends DependencyScope> |
getScope(java.lang.String scopeClassName,
boolean createInstance)
Gets a
DependencyScope specified by the given canonical class name. |
static void |
removeDependant(java.lang.Object dependant)
Removes the given
Object as an dependant from currently active scope - if one exists. |
static void |
resetActiveScope()
This method resets the currently active
DependencyScope to null . |
protected static void |
resetAppScope()
This method resets the application level
DependencyScope to null . |
static void |
setAppScope(DependencyScope appScope)
Sets the application level
DependencyScope . |
public static DependencyScope addScope(DependencyScopeOwner owner)
DependencyScope
owner by the given DependencyScopeOwner
to
the HashMap
of the current DependencyScope
s.owner
- A DependencyScopeOwner
DependencyScope
.public static <T extends DependencyScope> T getScope(DependencyScopeOwner owner, boolean createInstance)
DependencyScope
managed by the given DependencyScopeOwner
.T
- A type parameter for casting the requested dependency to expected type.owner
- A DependencyScopeOwner
.createInstance
- A boolean
flag specifying if the requested DependencyScope
is
attempted to be created via reflection in case the requested DependencyScope
is not registered yet.DependencyScope
. May return null
.public static <T extends DependencyScope> T getScope(java.lang.String scopeClassName, boolean createInstance)
DependencyScope
specified by the given canonical class name.T
- A type parameter for casting the requested dependency to expected type.scopeClassName
- The canonical name of the DependencyScope
.createInstance
- A boolean
flag specifying if the requested DependencyScope
is
attempted to be created via reflection in case the requested DependencyScope
is not registered yet.DependencyScope
. May return null
.public static <T extends DependencyScope> T getScope(java.lang.Class<? extends DependencyScope> scopeClass)
DependencyScope
.scopeClass
- A Class
specifying DependencyScope
.DependencyScope
. If null
is returned, it indicates an
error in an DependencyScope
implementation.public static <T extends DependencyScope> T getScope(java.lang.Class<? extends DependencyScope> scopeClass, boolean createInstance)
DependencyScope
.scopeClass
- A Class
specifying DependencyScope
.createInstance
- A boolean
flag specifying if the requested DependencyScope
is
attempted to be created via reflection in case the requested DependencyScope
is not registered yet.DependencyScope
. If null
is returned, it indicates an
error in an DependencyScope
implementation.public static DependencyScope getAppScope()
DependencyScope
.DependencyScope
.public static DependencyScope getActiveScope()
DependencyScope
that is set to be currently the active one. Note that only
one DependencyScope
can be active at any given. If no DependencyScope
is
set to be active, the application level DependencyScope
is returned.DependencyScope
. May not return null
.public static void setAppScope(DependencyScope appScope)
DependencyScope
.appScope
- A DependencyScope
.public static void activateScope(DependencyScopeOwner owner)
DependencyScope
for the given DependencyScopeOwner
.
The active DependencyScope
is used for resolving dependencies. Setting the currently
active DependencyScope
is not thread safe. Therefore this method can be invoked
only from the Main UI thread.owner
- A DependencyScopeOwner
.public static void activateScope(DependencyScopeOwner owner, DependencyScope scope)
DependencyScope
for the given DependencyScopeOwner
.
The active DependencyScope
is used for resolving dependencies. Setting the currently
active DependencyScope
is not thread safe. Therefore this method can be invoked
only from the Main UI thread. This method is suitable to be used when the actual instanceowner
- A DependencyScopeOwner
.scope
- A DependencyScope
.public static void deactivateScope(DependencyScopeOwner owner)
DependencyScope
managed by the given DependencyScopeOwner
.
When a DependencyScope
is deactivated it is also disposed if disposing is allowed
for the deactivated DependencyScope
.owner
- A DependencyScopeOwner
.public static void disposeScope(DependencyScopeOwner owner)
DependencyScope
of the given DependencyScopeOwner
.owner
- A DependencyScopeOwner
.public static void disposeScopes()
DependencyScope
s.public static <T> T get(java.lang.Class<T> dependencyType)
DependencyScope
.T
- A type parameter for casting the requested dependency to expected type.dependencyType
- A Class
specifying the type of the requested dependency.null
is returned, it indicates an error in
an DependencyScope
implementation.public static <T> T get(java.lang.Class<? extends DependencyScope> scopeClass, java.lang.Class<T> dependencyType)
DependencyScope
.T
- A type parameter for casting the requested dependency to expected type.scopeClass
- A Class
specifying DependencyScope
.dependencyType
- A Class
specifying the type of the requested dependency.null
is returned, it indicates an error in
an DependencyScope
implementation.public static <T> T get(java.lang.Class<? extends DependencyScope> scopeClass, java.lang.Class<T> dependencyType, java.lang.Object dependant)
DependencyScope
.T
- A type parameter for casting the requested dependency to expected type.scopeClass
- A Class
specifying DependencyScope
.dependencyType
- A Class
specifying the type of the requested dependency.dependant
- The object requesting the requested. This parameter is required when the requesting object
is also a requested within the object graph represented by the active Dependency
.null
is returned, it indicates an error in
an DependencyScope
implementation.public static <T> T get(DependencyScope scope, java.lang.Class<T> dependencyType)
DependencyScope
.T
- A type parameter for casting the requested dependency to expected type.scope
- A DependencyScope
.dependencyType
- A Class
specifying the type of the requested dependency.null
is returned, it indicates an error in
an DependencyScope
implementation.public static <T> T get(java.lang.Class<T> dependencyType, java.lang.Object dependant)
DependencyScope
.T
- A type parameter for casting the requested dependency to expected type.dependencyType
- A Class
specifying the type of the requested dependency.dependant
- The object requesting the requested. This parameter is required when the requesting object
is also a requested within the object graph represented by the active Dependency
.null
is returned, it indicates an error in
an DependencyScope
implementation.public static <T> T get(DependencyScope scope, java.lang.Class<T> dependencyType, java.lang.Object dependant)
DependencyScope
.T
- A type parameter for casting the requested dependency to expected type.scope
- A DependencyScope
.dependencyType
- A Class
specifying the type of the requested dependency.dependant
- The object requesting the requested. This parameter is required when the requesting object
is also a requested within the object graph represented by the active Dependency
.null
is returned, it indicates an error in
an DependencyScope
implementation.public static <T> java.util.Collection<T> getAll(java.lang.Class<T> dependencyType)
DependencyScope
.T
- A type parameter for casting the requested dependency to expected type.dependencyType
- A Class
specifying the type of the requested dependency.Collection
containing the found dependencies. If an empty Collection
is returned,
it indicates an error in an DependencyScope
implementation or configuration.public static <T> java.util.Collection<T> getAll(java.lang.Class<? extends DependencyScope> scopeType, java.lang.Class<T> dependencyType)
DependencyScope
.T
- A type parameter for casting the requested dependency to expected type.scopeType
- A Class
specifying DependencyScope
.dependencyType
- A Class
specifying the type of the requested dependency.Collection
containing the found dependencies. If an empty Collection
is returned,
it indicates an error in an DependencyScope
implementation or configuration.public static <T> java.util.Collection<T> getAll(java.lang.Class<? extends DependencyScope> scopeClass, java.lang.Class<T> dependencyType, java.lang.Object dependant)
DependencyScope
.T
- A type parameter for casting the requested dependency to expected type.scopeClass
- A Class
specifying DependencyScope
.dependencyType
- A Class
specifying the type of the requested dependency.dependant
- The object requesting the requested. This parameter is required when the requesting object
is also a requested within the object graph represented by the active Dependency
.Collection
containing the found dependencies. If an empty Collection
is returned,
it indicates an error in an DependencyScope
implementation or configuration.public static <T> java.util.Collection<T> getAll(DependencyScope scope, java.lang.Class<T> dependencyType)
DependencyScope
.T
- A type parameter for casting the requested dependency to expected type.scope
- A DependencyScope
.dependencyType
- A Class
specifying the type of the requested dependency.Collection
containing the found dependencies. If an empty Collection
is returned,
it indicates an error in an DependencyScope
implementation or configuration.public static <T> java.util.Collection<T> getAll(java.lang.Class<T> dependencyType, java.lang.Object dependant)
DependencyScope
.T
- A type parameter for casting the requested dependency to expected type.dependencyType
- A Class
specifying the type of the requested dependency.dependant
- The object requesting the requested. This parameter is required when the requesting object
is also a requested within the object graph represented by the active Dependency
.Collection
containing the found dependencies. If an empty Collection
is returned,
it indicates an error in an DependencyScope
implementation or configuration.public static <T> java.util.Collection<T> getAll(DependencyScope scope, java.lang.Class<T> dependencyType, java.lang.Object dependant)
DependencyScope
.T
- A type parameter for casting the requested dependency to expected type.scope
- A DependencyScope
.dependencyType
- A Class
specifying the type of the requested dependency.dependant
- The object requesting the requested. This parameter is required when the requesting object
is also a requested within the object graph represented by the active Dependency
.Collection
containing the found dependencies. If an empty Collection
is returned,
it indicates an error in an DependencyScope
implementation or configuration.protected static void resetAppScope()
DependencyScope
to null
.
This method is added only for testing purposes.public static void resetActiveScope()
DependencyScope
to null
.
This method is added only for testing purposes.public static void addDependant(java.lang.Object dependant)
Object
as an dependant to currently active scope - if one exists.dependant
- An Object
to be added as dependant.public static void removeDependant(java.lang.Object dependant)
Object
as an dependant from currently active scope - if one exists.dependant
- An Object
to be removed as dependant.