Class ComponentBag
- Direct Known Subclasses:
ComponentBag.ImmutableComponentBag
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:
- The iteration order of registered components mirrors the registration order of these components.
- There can be only one registration for any given component type.
- Existing registrations cannot be overridden (any attempt to override an existing registration will be rejected).
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final Inflector<ContractProvider.Builder, ContractProvider> Contract provider model enhancer that builds a model as is, without any modifications.static final Predicate<ContractProvider> A filtering strategy that includes only models that containBinderprovider contract.Registered component classes collection and it's immutable view.static final Predicate<ContractProvider> A filtering strategy that excludes models with no recognized contracts.private static final Predicate<ContractProvider> A filtering strategy that excludes all pure meta-provider models (i.e.static final Predicate<ContractProvider> A filtering strategy that includes only models that containExecutorServiceProviderprovider contract.static final BiPredicate<ContractProvider, InjectionManager> A filtering strategy that includes only models that contain contract registrable byInjectionManager.static final Predicate<ContractProvider> A filtering strategy that accepts any contract provider model.Registered component instances collection and it's immutable view.private final Map<Class<?>, ContractProvider> Map of contract provider models for the registered component classes and instances it's immutable view.private final Predicate<ContractProvider> Contract provider model registration strategy.static final Predicate<ContractProvider> A filtering strategy that includes only models that containScheduledExecutorServiceProviderprovider contract. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateComponentBag(Predicate<ContractProvider> registrationStrategy) privateComponentBag(Predicate<ContractProvider> registrationStrategy, Set<Class<?>> classes, Set<Object> instances, Map<Class<?>, ContractProvider> models) -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all the component registrations and resets the component bag instance to a state as if it was create anew.copy()Get a copy of this component bag.static Predicate<ContractProvider> excludeMetaProviders(InjectionManager injectionManager) A method creates thePredicatewhich is able to filter all Jersey meta-providers along with the components which is able to register the current usedInjectionManager.Get all registered component classes, includingfeaturesandbindersmeta-providers.getClasses(Predicate<ContractProvider> filter) Get a subset of all registered component classes using thefilterpredicate to determine for each component class based on it's contract provider class model whether it should be kept or filtered out.static <T> List<T> getFromBinders(InjectionManager injectionManager, ComponentBag componentBag, Function<Object, T> cast, Predicate<Binding> filter) IfTobject is registered inComponentBagusing theBinder,Tis not visible using the methods for getting classes and instancesgetClasses(Predicate)andgetInstances(Predicate).Get all registered component instances, includingfeaturesandbindersmeta-providers.getInstances(Predicate<ContractProvider> filter) Get a subset of all registered component instances using thefilterpredicate to determine for each component instance based on it's contract provider class model whether it should be kept or filtered out.Get a model for a given component class, ornullif no such component is registered in the component bag.Get an unmodifiable view of all component classes, for which a registration exists (either class or instance based) in the component bag.Get immutable copy of a component bag.(package private) voidloadFrom(ComponentBag bag) Clear and initialize the component registrations from given bag instance.static ContractProviderCreate a contract provider model by introspecting a component class.private static ContractProvidermodelFor(Class<?> componentClass, int defaultPriority, Map<Class<?>, Integer> contractMap, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Create a contract provider for a given component class.static ComponentBagnewInstance(Predicate<ContractProvider> registrationStrategy) Create new empty component bag.booleanregister(Class<?> componentClass, int priority, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register a component class as a contract provider with an explicitly specified binding priority.booleanregister(Class<?> componentClass, Map<Class<?>, Integer> contracts, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register a component class as a contract provider for the specified contracts.booleanregister(Class<?> componentClass, Set<Class<?>> contracts, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register a component class as a contract provider for the specified contracts.booleanregister(Class<?> componentClass, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register a component class using a given registration strategy.booleanregister(Object component, int priority, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register a component as a contract provider with an explicitly specified binding priority.booleanregister(Object component, Map<Class<?>, Integer> contracts, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register a component as a contract provider for the specified contracts.booleanregister(Object component, Set<Class<?>> contracts, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register a component as a contract provider for the specified contracts.booleanregister(Object component, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register a component using a given registration strategy.private booleanregisterModel(Class<?> componentClass, int defaultPriority, Map<Class<?>, Integer> contractMap, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register acontract provider modelfor a given class.
-
Field Details
-
EXCLUDE_META_PROVIDERS
A filtering strategy that excludes all pure meta-provider models (i.e. models that only contain recognized meta-provider contracts -Featureand/orBinderand/or external meta-provider fromInjectionManager.isRegistrable(Class)).This filter predicate returns
falsefor allcontract provider modelsthat represent a model containing only recognized meta-provider contracts. -
CAST_TO_BINDER
-
EXTERNAL_ONLY
A filtering strategy that includes only models that contain contract registrable byInjectionManager.This filter predicate returns
truefor allcontract provider modelsthat represent an object which can be registered using specificInjectionManagercontract. -
BINDERS_ONLY
A filtering strategy that includes only models that containBinderprovider contract.This filter predicate returns
truefor allcontract provider modelsthat represent a provider registered to provideBindercontract. -
EXECUTOR_SERVICE_PROVIDER_ONLY
A filtering strategy that includes only models that containExecutorServiceProviderprovider contract.This filter predicate returns
truefor allcontract provider modelsthat represent a provider registered to provideExecutorServiceProvidercontract. -
SCHEDULED_EXECUTOR_SERVICE_PROVIDER_ONLY
A filtering strategy that includes only models that containScheduledExecutorServiceProviderprovider contract.This filter predicate returns
truefor allcontract provider modelsthat represent a provider registered to provideScheduledExecutorServiceProvidercontract. -
EXCLUDE_EMPTY
A filtering strategy that excludes models with no recognized contracts.This filter predicate returns
falsefor allcontract provider modelsthat are empty, i.e. do not contain any recognized contracts. -
INCLUDE_ALL
A filtering strategy that accepts any contract provider model.This filter predicate returns
truefor any contract provider model. -
AS_IS
Contract provider model enhancer that builds a model as is, without any modifications. -
registrationStrategy
Contract provider model registration strategy. -
classes
Registered component classes collection and it's immutable view. -
classesView
-
instances
Registered component instances collection and it's immutable view. -
instancesView
-
models
Map of contract provider models for the registered component classes and instances it's immutable view. -
modelKeysView
-
-
Constructor Details
-
ComponentBag
-
ComponentBag
private ComponentBag(Predicate<ContractProvider> registrationStrategy, Set<Class<?>> classes, Set<Object> instances, Map<Class<?>, ContractProvider> models)
-
-
Method Details
-
excludeMetaProviders
A method creates thePredicatewhich is able to filter all Jersey meta-providers along with the components which is able to register the current usedInjectionManager.- Parameters:
injectionManager- current injection manager.- Returns:
Predicateexcluding Jersey meta-providers and the specific ones for a currentInjectionManager.
-
newInstance
Create new empty component bag.- Parameters:
registrationStrategy- function driving the decision (based on the introspectedcontract provider model) whether or not should the component class registration continue towards a successful completion.- Returns:
- a new empty component bag.
-
getFromBinders
public static <T> List<T> getFromBinders(InjectionManager injectionManager, ComponentBag componentBag, Function<Object, T> cast, Predicate<Binding> filter) IfTobject is registered inComponentBagusing theBinder,Tis not visible using the methods for getting classes and instancesgetClasses(Predicate)andgetInstances(Predicate).Method selects all
bindingsand picks up the instances or creates the instances fromClassBinding(injection does not work at this moment).- Parameters:
injectionManager- injection manager to create an object fromTclass.componentBag- component bag which provides registered binders.- Returns:
- all instances/classes registered using binders.
-
register
public boolean register(Class<?> componentClass, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register a component class using a given registration strategy.- Parameters:
componentClass- class to be introspected as a contract provider and registered, based on the registration strategy decision.modelEnhancer- custom contract provider model enhancer.- Returns:
trueif the component registration was successful.
-
register
public boolean register(Class<?> componentClass, int priority, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register a component class as a contract provider with an explicitly specified binding priority.- Parameters:
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.- Returns:
trueif the component registration was successful.
-
register
public boolean register(Class<?> componentClass, Set<Class<?>> contracts, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register a component class as a contract provider for the specified contracts.- Parameters:
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.- Returns:
trueif the component registration was successful.
-
register
public boolean register(Class<?> componentClass, Map<Class<?>, Integer> contracts, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register a component class as a contract provider for the specified contracts.- Parameters:
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.- Returns:
trueif the component registration was successful.
-
register
public boolean register(Object component, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register a component using a given registration strategy.- Parameters:
component- instance to be introspected as a contract provider and registered, based on the registration strategy decision.modelEnhancer- custom contract provider model enhancer.- Returns:
trueif the component registration was successful.
-
register
public boolean register(Object component, int priority, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register a component as a contract provider with an explicitly specified binding priority.- Parameters:
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.- Returns:
trueif the component registration was successful.
-
register
public boolean register(Object component, Set<Class<?>> contracts, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register a component as a contract provider for the specified contracts.- Parameters:
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.- Returns:
trueif the component registration was successful.
-
register
public boolean register(Object component, Map<Class<?>, Integer> contracts, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register a component as a contract provider for the specified contracts.- Parameters:
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.- Returns:
trueif the component registration was successful.
-
registerModel
private boolean registerModel(Class<?> componentClass, int defaultPriority, Map<Class<?>, Integer> contractMap, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Register acontract provider modelfor a given class.- Parameters:
componentClass- registered component class.defaultPriority- default component priority. If -1, the value from the component classPriorityannotation will be used (if any).contractMap- map of contracts and their binding priorities. Ifnull, 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.- Returns:
trueupon successful registration of a contract provider model for a given component class,falseotherwise.
-
modelFor
Create a contract provider model by introspecting a component class.- Parameters:
componentClass- component class to create contract provider model for.- Returns:
- contract provider model for the class.
-
modelFor
private static ContractProvider modelFor(Class<?> componentClass, int defaultPriority, Map<Class<?>, Integer> contractMap, Inflector<ContractProvider.Builder, ContractProvider> modelEnhancer) Create a contract provider for a given component class.- Parameters:
componentClass- component class to create contract provider model for.defaultPriority- default component priority. If -1, the value from the component classPriorityannotation will be used (if any).contractMap- map of contracts and their binding priorities. Ifnull, 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.- Returns:
- contract provider model for the class.
-
asMap
-
getClasses
Get all registered component classes, includingfeaturesandbindersmeta-providers.- Returns:
- all registered component classes.
-
getInstances
Get all registered component instances, includingfeaturesandbindersmeta-providers.- Returns:
- all registered component instances.
-
getClasses
Get a subset of all registered component classes using thefilterpredicate to determine for each component class based on it's contract provider class model whether it should be kept or filtered out.- Parameters:
filter- function that decides whether a particular class should be returned or not.- Returns:
- filtered subset of registered component classes.
-
getInstances
Get a subset of all registered component instances using thefilterpredicate to determine for each component instance based on it's contract provider class model whether it should be kept or filtered out.- Parameters:
filter- function that decides whether a particular class should be returned or not.- Returns:
- filtered subset of registered component instances.
-
getRegistrations
Get an unmodifiable view of all component classes, for which a registration exists (either class or instance based) in the component bag.- Returns:
- set of classes of all component classes and instances registered in this component bag.
-
getModel
Get a model for a given component class, ornullif no such component is registered in the component bag.- Parameters:
componentClass- class of the registered component to retrieve the contract provider model for.- Returns:
- model for a given component class, or
nullif no such component is registered.
-
copy
Get a copy of this component bag.- Returns:
- component bag copy.
-
immutableCopy
Get immutable copy of a component bag.- Returns:
- immutable view of a component bag.
-
clear
public void clear()Removes all the component registrations and resets the component bag instance to a state as if it was create anew. -
loadFrom
Clear and initialize the component registrations from given bag instance.- Parameters:
bag- component bag to initialize this one with.
-