public interface ContextualRegistry
Context contains also a notion of classifiers. Classifier is any object defining additional key for registered objects. To obtain such registered object, the same classifier (precisely, any equal object) has to be used.
Classifiers can be used as follows:
String, ...
// User detail provider service
registry.register("NAME_PARAM_ID", "Smith");
registry.register("GENDER_PARAM_ID", "male");
...
// User consumer service
String name = registry.get("name", String.class);
// In some central security service.
registry.register(securityFrameworkInternalInstance, new AuthenticatedInternalIdentity(...));
...
// In some authorization filter known by a central security service
AuthenticatedInternalIdentity auth = registry.get(securityFrameworkInternalInstance, AuthenticatedInternalIdentity.class);
| Modifier and Type | Method and Description |
|---|---|
static ContextualRegistry |
create()
Creates a new empty instance.
|
static ContextualRegistry |
create(ContextualRegistry parent)
Creates a new empty instance backed by its parent read-through
ContextualRegistry. |
<T> Optional<T> |
get(Class<T> type)
Optionally gets registered instance by its type.
|
<T> Optional<T> |
get(Object classifier,
Class<T> type)
Optionally gets a registered instance by its type.
|
<T> void |
register(Object classifier,
T instance)
Register a new instance with specified classifier.
|
<T> void |
register(T instance)
Register a new instance.
|
<T> void |
supply(Class<T> type,
Supplier<T> supplier)
Register a new instance using a provided supplier.
|
<T> void |
supply(Object classifier,
Class<T> type,
Supplier<T> supplier)
Registers a new instance using a provided supplier.
|
static ContextualRegistry create()
static ContextualRegistry create(ContextualRegistry parent)
ContextualRegistry.
Parent registry is used only for get methods and only if this registry doesn't have registered required type.
parent - a parent registry<T> void register(T instance)
T - a type of the registered instanceinstance - an instance to registerNullPointerException - if the registered object is null<T> void supply(Class<T> type, Supplier<T> supplier)
get(Class) method. The returned value is then registered and the supplier is never used again.T - a type of supplied objecttype - a type of supplied instancesupplier - a supplier of the instance to registerNullPointerException - if the type or the supplier is null<T> Optional<T> get(Class<T> type)
More specifically, it returns the last registered instance without specified classifier which can be cast to the requested type.
T - a type of requested instancetype - a type of requested instance<T> void register(Object classifier, T instance)
Registered instance can be obtained only using get(Object, Class) method with a classifier equal with
the one used during registration.
T - a type of the registered instanceclassifier - an additional registered instance classifierinstance - an instance to registerNullPointerException - if classifier or registered object is null<T> void supply(Object classifier, Class<T> type, Supplier<T> supplier)
get(Object, Class) method. The returned value gets registered and the supplier is never called
again.
Registered instance can be obtained only using get(Object, Class) method with a classifier equal with
the one used during registration.
T - a type of supplied objectclassifier - an additional registered instance classifiertype - a type of requested instancesupplier - a supplier of the instance to registerNullPointerException - If any parameter is null.<T> Optional<T> get(Object classifier, Class<T> type)
More specifically, it returns the last registered instance with equal classifier which can be cast to the requested type.
T - a type of requested instanceclassifier - an additional registered instance classifiertype - a type of requested instanceNullPointerException - If classifier is null.Copyright © 2018–2019 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.