public class ClassLoaderScope extends Object implements ContextScope
ContextScope
for ClassLoader
-scoped singleton context resources.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_ORDER
Default scope order
|
Constructor and Description |
---|
ClassLoaderScope() |
Modifier and Type | Method and Description |
---|---|
<T> Optional<T> |
get(String resourceKey,
Class<T> resourceType)
Try to obtain the resource identified by given
resourceKey and with expected
resourceType . |
String |
getName()
Gets the scope name.
|
int |
getOrder()
Gets the scope order.
|
<T> Optional<T> |
put(String resourceKey,
T value)
Stores a resource reference identified by given
resourceKey . |
<T> Optional<T> |
putIfAbsent(String resourceKey,
T value)
Stores a resource reference identified by given
resourceKey , only if there is not a resource
instance already bound to given key. |
boolean |
remove(String resourceKey)
Removes the resource reference bound to the given
resourceKey from scope, if any. |
public static final int DEFAULT_ORDER
public String getName()
ContextScope
getName
in interface ContextScope
public int getOrder()
ContextScope
getOrder
in interface ContextScope
public <T> Optional<T> get(String resourceKey, Class<T> resourceType) throws TypeMismatchException
ContextScope
resourceKey
and with expected
resourceType
.get
in interface ContextScope
T
- Resource typeresourceKey
- Resource key (not null)resourceType
- Expected resource type (not null)TypeMismatchException
- If a resource is available but the expected type is not compatible with the
resource typepublic <T> Optional<T> put(String resourceKey, T value) throws UnsupportedOperationException
ContextScope
resourceKey
.put
in interface ContextScope
T
- Resource instance typeresourceKey
- Resource key (not null)value
- Resource instance. If null
, if a previous resource was bound to given resource key, it
will be removed from scope.UnsupportedOperationException
- If the concrete scope implementation does not support this operationpublic <T> Optional<T> putIfAbsent(String resourceKey, T value) throws UnsupportedOperationException
ContextScope
resourceKey
, only if there is not a resource
instance already bound to given key.putIfAbsent
in interface ContextScope
T
- Resource instance typeresourceKey
- Resource key (not null)value
- Resource instance, if null
, this method should do nothing.value
has been associated to the
resource key.UnsupportedOperationException
- If the concrete scope implementation does not support this operationpublic boolean remove(String resourceKey) throws UnsupportedOperationException
ContextScope
resourceKey
from scope, if any.remove
in interface ContextScope
resourceKey
- Resource key (not null)true
if a resource instance was bound to the given key and it's been removed,
false
otherwise.UnsupportedOperationException
- If the concrete scope implementation does not support this operationCopyright © 2019 The Holon Platform. All rights reserved.