org.glassfish.jersey.model.internal
Class ComponentBag

java.lang.Object
  extended by org.glassfish.jersey.model.internal.ComponentBag

public class ComponentBag
extends Object

An internal Jersey container for custom component classes and instances. The component bag can automatically compute a 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:

Author:
Marek Potociar (marek.potociar at oracle.com)

Field Summary
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.
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.
 
Method Summary
 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.
 Set<Class<?>> getClasses()
          Get all registered component classes, including features and binders mtea-providers.
 Set<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.
 Set<Object> getInstances()
          Get all registered component instances, including features and binders meta-providers.
 Set<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(Class<?> componentClass)
          Get a model for a given component class, or null if no such component is registered in the component bag.
 Set<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.
static ContractProvider modelFor(Class<?> componentClass)
          Create a contract provider model by introspecting a component class.
static ComponentBag newInstance(com.google.common.base.Predicate<ContractProvider> registrationStrategy)
          Create new empty component bag.
 boolean register(Class<?> componentClass, Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
          Register a component class using a given registration strategy.
 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.
 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.
 boolean register(Class<?> componentClass, Set<Class<?>> contracts, Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
          Register a component class as a contract provider for the specified contracts.
 boolean register(Object component, Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
          Register a component using a given registration strategy.
 boolean register(Object component, int priority, Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
          Register a component as a contract provider with an explicitly specified binding priority.
 boolean register(Object component, Map<Class<?>,Integer> contracts, Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
          Register a component as a contract provider for the specified contracts.
 boolean register(Object component, Set<Class<?>> contracts, Inflector<ContractProvider.Builder,ContractProvider> modelEnhancer)
          Register a component as a contract provider for the specified contracts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXCLUDE_META_PROVIDERS

public static final com.google.common.base.Predicate<ContractProvider> EXCLUDE_META_PROVIDERS
A filtering strategy that excludes all pure meta-provider models (i.e. models that only contain recognized meta-provider contracts - Feature and/or Binder).

This filter predicate returns false for all contract provider models that represent a model containing only recognized meta-provider contracts.


BINDERS_ONLY

public static final com.google.common.base.Predicate<ContractProvider> BINDERS_ONLY
A filtering strategy that includes only models that contain HK2 Binder provider contract.

This filter predicate returns true for all contract provider models that represent a provider registered to provide HK2 Binder contract.


EXCLUDE_EMPTY

public static final com.google.common.base.Predicate<ContractProvider> EXCLUDE_EMPTY
A filtering strategy that excludes models with no recognized contracts.

This filter predicate returns false for all contract provider models that are empty, i.e. do not contain any recognized contracts.


INCLUDE_ALL

public static final com.google.common.base.Predicate<ContractProvider> INCLUDE_ALL
A filtering strategy that accepts any contract provider model.

This filter predicate returns true for any contract provider model.


AS_IS

public static final Inflector<ContractProvider.Builder,ContractProvider> AS_IS
Contract provider model enhancer that builds a model as is, without any modifications.

Method Detail

newInstance

public static ComponentBag newInstance(com.google.common.base.Predicate<ContractProvider> registrationStrategy)
Create new empty component bag.

Parameters:
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.
Returns:
a new empty component bag.

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:
true if 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:
true if 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:
true if 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:
true if 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:
true if 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:
true if 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:
true if 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:
true if the component registration was successful.

modelFor

public static ContractProvider modelFor(Class<?> componentClass)
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.

getClasses

public Set<Class<?>> getClasses()
Get all registered component classes, including features and binders mtea-providers.

Returns:
all registered component classes.

getInstances

public Set<Object> getInstances()
Get all registered component instances, including features and binders meta-providers.

Returns:
all registered component instances.

getClasses

public Set<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.

Parameters:
filter - function that decides whether a particular class should be returned or not.
Returns:
filtered subset of registered component classes.

getInstances

public Set<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.

Parameters:
filter - function that decides whether a particular class should be returned or not.
Returns:
filtered subset of registered component instances.

getRegistrations

public Set<Class<?>> 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

public ContractProvider getModel(Class<?> componentClass)
Get a model for a given component class, or null if 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 null if no such component is registered.

copy

public ComponentBag copy()
Get a copy of this component bag.

Returns:
component bag copy.

immutableCopy

public ComponentBag 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.



Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.