Package org.int4.dirk.spi.scope
Class AbstractScopeResolver<S>
- java.lang.Object
-
- org.int4.dirk.spi.scope.AbstractScopeResolver<S>
-
- Type Parameters:
S- the type of the scope discriminator object
- All Implemented Interfaces:
ScopeResolver
- Direct Known Subclasses:
SingletonScopeResolver
public abstract class AbstractScopeResolver<S> extends java.lang.Object implements ScopeResolver
Abstract base implementation of aScopeResolverwhich manages a map of instances per scope.
-
-
Constructor Summary
Constructors Constructor Description AbstractScopeResolver()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voiddestroyScope(S scope)Destroys the given scope.<T> Tget(java.lang.Object key, CreationalContext<T> creationalContext)Returns an existing instance associated with the given key, or uses the given context to create one.protected abstract SgetCurrentScope()Returns the current scope, ornullif there is no current scope.booleanisActive()Returnstruewhen this scope is currently active, otherwisefalse.voidremove(java.lang.Object key)Removes the given key from this scope resolver.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.int4.dirk.spi.scope.ScopeResolver
getAnnotation
-
-
-
-
Method Detail
-
isActive
public final boolean isActive()
Description copied from interface:ScopeResolverReturnstruewhen this scope is currently active, otherwisefalse.- Specified by:
isActivein interfaceScopeResolver- Returns:
truewhen this scope is currently active, otherwisefalse
-
get
public final <T> T get(java.lang.Object key, CreationalContext<T> creationalContext) throws java.lang.ExceptionDescription copied from interface:ScopeResolverReturns an existing instance associated with the given key, or uses the given context to create one.- Specified by:
getin interfaceScopeResolver- Type Parameters:
T- the type of the instances provided by theCreationalContext- Parameters:
key- an object suitable as a key for use in a map, cannot benullcreationalContext- anCreationalContext, cannot benull- Returns:
- an instance of the given type, never
null - Throws:
ScopeNotActiveException- when there is no scope activejava.lang.Exception- when the object factory throws an exception
-
remove
public final void remove(java.lang.Object key)
Description copied from interface:ScopeResolverRemoves the given key from this scope resolver.- Specified by:
removein interfaceScopeResolver- Parameters:
key- an object suitable as a key for use in a map, cannot benull
-
getCurrentScope
protected abstract S getCurrentScope()
Returns the current scope, ornullif there is no current scope.- Returns:
- the current scope, or
nullif there is no current scope
-
destroyScope
protected final void destroyScope(S scope)
Destroys the given scope. Removes all references to instance from the given scope and releases their associatedCreationalContexts. Does nothing if the scope does not exist.- Parameters:
scope- a scope, cannot benull
-
-