public class ComponentBag
extends java.lang.Object
contract provider
model
for the registered component type and stores it with the component registration.
The rules for managing components inside a component bag are derived from the
rules of JAX-RS Configurable
API. In short:
Modifier and Type | Class and Description |
---|---|
private static class |
ComponentBag.ImmutableComponentBag
Immutable version of
ComponentBag . |
Modifier and Type | Field and Description |
---|---|
static Inflector<ContractProvider.Builder,ContractProvider> |
AS_IS
Contract provider model enhancer that builds a model as is, without any
modifications.
|
static com.google.common.base.Predicate<ContractProvider> |
BINDERS_ONLY
A filtering strategy that includes only models that contain HK2 Binder provider contract.
|
private java.util.Set<java.lang.Class<?>> |
classes
Registered component classes collection and it's immutable view.
|
private java.util.Set<java.lang.Class<?>> |
classesView |
static com.google.common.base.Predicate<ContractProvider> |
EXCLUDE_EMPTY
A filtering strategy that excludes models with no recognized contracts.
|
static com.google.common.base.Predicate<ContractProvider> |
EXCLUDE_META_PROVIDERS
A filtering strategy that excludes all pure meta-provider models (i.e.
|
static com.google.common.base.Predicate<ContractProvider> |
INCLUDE_ALL
A filtering strategy that accepts any contract provider model.
|
private java.util.Set<java.lang.Object> |
instances
Registered component instances collection and it's immutable view.
|
private java.util.Set<java.lang.Object> |
instancesView |
private java.util.Set<java.lang.Class<?>> |
modelKeysView |
private java.util.Map<java.lang.Class<?>,ContractProvider> |
models
Map of contract provider models for the registered component classes and instances
it's immutable view.
|
private com.google.common.base.Predicate<ContractProvider> |
registrationStrategy
Contract provider model registration strategy.
|
Modifier | Constructor and Description |
---|---|
private |
ComponentBag(com.google.common.base.Predicate<ContractProvider> registrationStrategy) |
private |
ComponentBag(com.google.common.base.Predicate<ContractProvider> registrationStrategy,
java.util.Set<java.lang.Class<?>> classes,
java.util.Set<java.lang.Object> instances,
java.util.Map<java.lang.Class<?>,ContractProvider> models) |
Modifier and Type | Method and Description |
---|---|
private static java.util.Map<java.lang.Class<?>,java.lang.Integer> |
asMap(java.util.Set<java.lang.Class<?>> contractSet) |
void |
clear()
Removes all the component registrations and resets the component bag instance to
a state as if it was create anew.
|
ComponentBag |
copy()
Get a copy of this component bag.
|
java.util.Set<java.lang.Class<?>> |
getClasses()
Get all registered component classes, including
features
and binders mtea-providers. |
java.util.Set<java.lang.Class<?>> |
getClasses(com.google.common.base.Predicate<ContractProvider> filter)
Get a subset of all registered component classes using the
filter predicate
to determine for each component class based on it's contract provider class model whether
it should be kept or filtered out. |
java.util.Set<java.lang.Object> |
getInstances()
Get all registered component instances, including
features
and binders meta-providers. |
java.util.Set<java.lang.Object> |
getInstances(com.google.common.base.Predicate<ContractProvider> filter)
Get a subset of all registered component instances using the
filter predicate
to determine for each component instance based on it's contract provider class model whether
it should be kept or filtered out. |
ContractProvider |
getModel(java.lang.Class<?> componentClass)
Get a model for a given component class, or
null if no such component is registered
in the component bag. |
java.util.Set<java.lang.Class<?>> |
getRegistrations()
Get an unmodifiable view of all component classes, for which a registration exists
(either class or instance based) in the component bag.
|
ComponentBag |
immutableCopy()
Get immutable copy of a component bag.
|
void |
loadFrom(ComponentBag bag)
Clear and initialize the component registrations from given bag instance.
|
static ContractProvider |
modelFor(java.lang.Class<?> componentClass)
Create a contract provider model by introspecting a component class.
|
private static ContractProvider |
modelFor(java.lang.Class<?> componentClass,
int defaultPriority,
java.util.Map<java.lang.Class<?>,java.lang.Integer> contractMap,
Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
Create a contract provider for a given component class.
|
static ComponentBag |
newInstance(com.google.common.base.Predicate<ContractProvider> registrationStrategy)
Create new empty component bag.
|
boolean |
register(java.lang.Class<?> componentClass,
Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
Register a component class using a given registration strategy.
|
boolean |
register(java.lang.Class<?> componentClass,
int priority,
Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
Register a component class as a contract provider with an explicitly specified binding priority.
|
boolean |
register(java.lang.Class<?> componentClass,
java.util.Map<java.lang.Class<?>,java.lang.Integer> contracts,
Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
Register a component class as a contract provider for the specified contracts.
|
boolean |
register(java.lang.Class<?> componentClass,
java.util.Set<java.lang.Class<?>> contracts,
Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
Register a component class as a contract provider for the specified contracts.
|
boolean |
register(java.lang.Object component,
Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
Register a component using a given registration strategy.
|
boolean |
register(java.lang.Object component,
int priority,
Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
Register a component as a contract provider with an explicitly specified binding priority.
|
boolean |
register(java.lang.Object component,
java.util.Map<java.lang.Class<?>,java.lang.Integer> contracts,
Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
Register a component as a contract provider for the specified contracts.
|
boolean |
register(java.lang.Object component,
java.util.Set<java.lang.Class<?>> contracts,
Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
Register a component as a contract provider for the specified contracts.
|
private boolean |
registerModel(java.lang.Class<?> componentClass,
int defaultPriority,
java.util.Map<java.lang.Class<?>,java.lang.Integer> contractMap,
Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
Register a
contract provider model for a given class. |
public static final com.google.common.base.Predicate<ContractProvider> EXCLUDE_META_PROVIDERS
Feature
and/or Binder
).
This filter predicate returns false
for all contract provider models
that represent a model containing only recognized meta-provider contracts.
public static final com.google.common.base.Predicate<ContractProvider> BINDERS_ONLY
This filter predicate returns true
for all contract provider models
that represent a provider registered to provide HK2 Binder
contract.
public static final com.google.common.base.Predicate<ContractProvider> EXCLUDE_EMPTY
This filter predicate returns false
for all contract provider models
that are empty, i.e. do not contain any recognized contracts.
public static final com.google.common.base.Predicate<ContractProvider> INCLUDE_ALL
This filter predicate returns true
for any contract provider model.
public static final Inflector<ContractProvider.Builder,ContractProvider> AS_IS
private final com.google.common.base.Predicate<ContractProvider> registrationStrategy
private final java.util.Set<java.lang.Class<?>> classes
private final java.util.Set<java.lang.Class<?>> classesView
private final java.util.Set<java.lang.Object> instances
private final java.util.Set<java.lang.Object> instancesView
private final java.util.Map<java.lang.Class<?>,ContractProvider> models
private final java.util.Set<java.lang.Class<?>> modelKeysView
private ComponentBag(com.google.common.base.Predicate<ContractProvider> registrationStrategy)
private ComponentBag(com.google.common.base.Predicate<ContractProvider> registrationStrategy, java.util.Set<java.lang.Class<?>> classes, java.util.Set<java.lang.Object> instances, java.util.Map<java.lang.Class<?>,ContractProvider> models)
public static ComponentBag newInstance(com.google.common.base.Predicate<ContractProvider> registrationStrategy)
registrationStrategy
- function driving the decision (based on the introspected
contract provider model
) whether
or not should the component class registration continue
towards a successful completion.public boolean register(java.lang.Class<?> componentClass, Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
componentClass
- class to be introspected as a contract provider and registered, based
on the registration strategy decision.modelEnhancer
- custom contract provider model enhancer.true
if the component registration was successful.public boolean register(java.lang.Class<?> componentClass, int priority, Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
componentClass
- class to be introspected as a contract provider and registered.priority
- explicitly specified binding priority for the provider contracts implemented
by the component.modelEnhancer
- custom contract provider model enhancer.true
if the component registration was successful.public boolean register(java.lang.Class<?> componentClass, java.util.Set<java.lang.Class<?>> contracts, Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
componentClass
- class to be introspected as a contract provider and registered.contracts
- contracts to bind the component class to.modelEnhancer
- custom contract provider model enhancer.true
if the component registration was successful.public boolean register(java.lang.Class<?> componentClass, java.util.Map<java.lang.Class<?>,java.lang.Integer> contracts, Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
componentClass
- class to be introspected as a contract provider and registered.contracts
- contracts with their priorities to bind the component class to.modelEnhancer
- custom contract provider model enhancer.true
if the component registration was successful.public boolean register(java.lang.Object component, Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
component
- instance to be introspected as a contract provider and registered, based
on the registration strategy decision.modelEnhancer
- custom contract provider model enhancer.true
if the component registration was successful.public boolean register(java.lang.Object component, int priority, Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
component
- instance to be introspected as a contract provider and registered, based
on the registration strategy decision.priority
- explicitly specified binding priority for the provider contracts implemented
by the component.modelEnhancer
- custom contract provider model enhancer.true
if the component registration was successful.public boolean register(java.lang.Object component, java.util.Set<java.lang.Class<?>> contracts, Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
component
- instance to be introspected as a contract provider and registered, based
on the registration strategy decision.contracts
- contracts to bind the component to.modelEnhancer
- custom contract provider model enhancer.true
if the component registration was successful.public boolean register(java.lang.Object component, java.util.Map<java.lang.Class<?>,java.lang.Integer> contracts, Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
component
- instance to be introspected as a contract provider and registered, based
on the registration strategy decision.contracts
- contracts with their priorities to bind the component to.modelEnhancer
- custom contract provider model enhancer.true
if the component registration was successful.private boolean registerModel(java.lang.Class<?> componentClass, int defaultPriority, java.util.Map<java.lang.Class<?>,java.lang.Integer> contractMap, Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
contract provider model
for a given class.componentClass
- registered component class.defaultPriority
- default component priority. If ,
the value from the component class Priority
annotation will be used
(if any).contractMap
- map of contracts and their binding priorities. If null
, the contracts will
gathered by introspecting the component class. Content of the contract map
may be modified during the registration processing.modelEnhancer
- custom contract provider model enhancer.true
upon successful registration of a contract provider model for a given component class,
false
otherwise.public static ContractProvider modelFor(java.lang.Class<?> componentClass)
componentClass
- component class to create contract provider model for.private static ContractProvider modelFor(java.lang.Class<?> componentClass, int defaultPriority, java.util.Map<java.lang.Class<?>,java.lang.Integer> contractMap, Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
componentClass
- component class to create contract provider model for.defaultPriority
- default component priority. If ,
the value from the component class Priority
annotation will be used
(if any).contractMap
- map of contracts and their binding priorities. If null
, the contracts will
gathered by introspecting the component class. Content of the contract map
may be modified during the registration processing.modelEnhancer
- custom contract provider model enhancer.private static java.util.Map<java.lang.Class<?>,java.lang.Integer> asMap(java.util.Set<java.lang.Class<?>> contractSet)
public java.util.Set<java.lang.Class<?>> getClasses()
features
and binders
mtea-providers.public java.util.Set<java.lang.Object> getInstances()
features
and binders
meta-providers.public java.util.Set<java.lang.Class<?>> getClasses(com.google.common.base.Predicate<ContractProvider> filter)
filter
predicate
to determine for each component class based on it's contract provider class model whether
it should be kept or filtered out.filter
- function that decides whether a particular class should be returned
or not.public java.util.Set<java.lang.Object> getInstances(com.google.common.base.Predicate<ContractProvider> filter)
filter
predicate
to determine for each component instance based on it's contract provider class model whether
it should be kept or filtered out.filter
- function that decides whether a particular class should be returned
or not.public java.util.Set<java.lang.Class<?>> getRegistrations()
public ContractProvider getModel(java.lang.Class<?> componentClass)
null
if no such component is registered
in the component bag.componentClass
- class of the registered component to retrieve the
contract provider model for.null
if no such component is registered.public ComponentBag copy()
public ComponentBag immutableCopy()
public void clear()
public void loadFrom(ComponentBag bag)
bag
- component bag to initialize this one with.