Top Description Fields Constructors Methods
org.glassfish.hk2.utilities.binding

public abstract Class AbstractBinder

extends Object
implements Binder, DynamicConfiguration
Class Inheritance
All Implemented Interfaces
org.glassfish.hk2.api.DynamicConfiguration, org.glassfish.hk2.utilities.Binder
Known Direct Subclasses
org.glassfish.hk2.utilities.EnableLookupExceptionsModule, org.glassfish.hk2.utilities.ImmediateScopeModule, org.glassfish.hk2.utilities.InheritableThreadScopeModule, org.glassfish.hk2.utilities.PerThreadScopeModule
Imports
java.lang.annotation.Annotation, java.lang.reflect.Type, java.security.AccessController, .PrivilegedAction, org.glassfish.hk2.api.ActiveDescriptor, .Descriptor, .DynamicConfiguration, .Factory, .FactoryDescriptors, .Filter, .HK2Loader, .MultiException, .TwoPhaseResource, .TypeLiteral, org.glassfish.hk2.utilities.Binder, .DescriptorImpl

Skeleton implementation of injection binder with convenience methods for binding definitions.
Author
Marek Potociar (marek.potociar at oracle.com)

Field Summary

Modifier and TypeField and Description
private transient DynamicConfiguration
private transient AbstractBindingBuilder<?>
private transient HK2Loader

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public <T> ActiveDescriptor<T>
addActiveDescriptor(ActiveDescriptor<T> activeDescriptor)

Implements org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

This allows third party systems to add reified active descriptors to the system.

public <T> ActiveDescriptor<T>
addActiveDescriptor(ActiveDescriptor<T> activeDescriptor, boolean requiresDeepCopy)

Implements org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

This allows third party systems to add reified active descriptors to the system.

public <T> ActiveDescriptor<T>
addActiveDescriptor(Class<T> rawClass)

Implements org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

This adds an active descriptor to the system based completely on the analysis of the given class.

public <T> FactoryDescriptors
addActiveFactoryDescriptor(Class<? extends Factory<T>> rawFactoryClass)

Implements org.glassfish.hk2.api.DynamicConfiguration.addActiveFactoryDescriptor.

This adds two active descriptors to the system based completely on the analysis of the given Factory class.

public void
addIdempotentFilter(Filter... unbindFilter)

Implements org.glassfish.hk2.api.DynamicConfiguration.addIdempotentFilter.

At commit time all idempotent filters in this dynamic configuration will be run against all validation-visible descriptors.

public void
addUnbindFilter(Filter unbindFilter)

Implements org.glassfish.hk2.api.DynamicConfiguration.addUnbindFilter.

This filter will added to the list of filters in this Configuration that will determine which Descriptors will be removed from the system.

public <
service type.
T
>
ServiceBindingBuilder<T>

Returns:

initialized binding builder.
bind
(Class<T>
service class.
serviceType
)

Start building a new class-based service binding.

public <
service type.
T
>
ScopedBindingBuilder<T>

Returns:

initialized binding builder.
bind
(T
service instance.
service
)

Start building a new instance-based service binding.

public void
bind(DynamicConfiguration configuration)

Implements org.glassfish.hk2.utilities.Binder.bind.

This method will be called by the ServiceLocatorUtilities#bind(org.glassfish.hk2.api.ServiceLocator, Binder...) method for each binder given.

public <T> ActiveDescriptor<T>
bind(Descriptor descriptor)

Implements org.glassfish.hk2.api.DynamicConfiguration.bind.

This method will bind the given descriptor to this Module.

public <T> ActiveDescriptor<T>
bind(Descriptor descriptor, boolean requiresDeepCopy)

Implements org.glassfish.hk2.api.DynamicConfiguration.bind.

This method will bind the given descriptor to this Module.

public FactoryDescriptors
bind(FactoryDescriptors factoryDescriptors)

Implements org.glassfish.hk2.api.DynamicConfiguration.bind.

This method will bind the descriptors found in the FactoryDescriptors.

public FactoryDescriptors
bind(FactoryDescriptors factoryDescriptors, boolean requiresDeepCopy)

Implements org.glassfish.hk2.api.DynamicConfiguration.bind.

This method will bind the descriptors found in the FactoryDescriptors.

public <
service type.
T
>
ServiceBindingBuilder<T>

Returns:

initialized binding builder.
bindAsContract
(Class<T>
service class.
serviceType
)

Start building a new class-based service binding.

public <
service type.
T
>
ServiceBindingBuilder<T>

Returns:

initialized binding builder.
bindAsContract
(TypeLiteral<T>
generic service type information.
serviceType
)

Start building a new generic type-based service binding.

public <
service type.
T
>
ServiceBindingBuilder<T>

Returns:

initialized binding builder.
bindAsContract
(Type
generic service type information.
serviceType
)

Start building a new generic type-based service binding.

public <
service type.
T
>
ServiceBindingBuilder<T>

Returns:

initialized binding builder.
bindFactory
(Class<? extends Factory<T>>
service factory class.
factoryType
,
Class<? extends Annotation>
factory scope.
factoryScope
)

Start building a new factory class-based service binding.

public <
service type.
T
>
ServiceBindingBuilder<T>

Returns:

initialized binding builder.
bindFactory
(Class<? extends Factory<T>>
service factory class.
factoryType
)

Start building a new factory class-based service binding.

public <
service type.
T
>
ServiceBindingBuilder<T>

Returns:

initialized binding builder.
bindFactory
(Factory<T>
service instance.
factory
)

Start building a new factory instance-based service binding.

public void
commit()

Implements org.glassfish.hk2.api.DynamicConfiguration.commit.

This causes the configuration to get committed.

private void
private DynamicConfiguration

Returns:

dynamic configuration instance used for binding configuration.
configuration
()

Get the active binder factory instance used for binding configuration.

protected abstract void
configure()

Implement to provide binding definitions using the exposed binding methods.

private HK2Loader
public final void
install(Binder...
binders whose binding definitions should be configured.
binders
)

Adds all binding definitions from the binders to the binding configuration.

public void
registerTwoPhaseResources(TwoPhaseResource... resources)

Implements org.glassfish.hk2.api.DynamicConfiguration.registerTwoPhaseResources.

Registers two-phase resources in the order in which they are to run.

private <T> AbstractBindingBuilder<T>
private void
setLoader(Descriptor descriptor)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

configurationback to summary
private transient DynamicConfiguration configuration
currentBuilderback to summary
private transient AbstractBindingBuilder<?> currentBuilder
defaultLoaderback to summary
private transient HK2Loader defaultLoader

Constructor Detail

AbstractBinderback to summary
public AbstractBinder()

Method Detail

addActiveDescriptorback to summary
public <T> ActiveDescriptor<T> addActiveDescriptor(ActiveDescriptor<T> activeDescriptor) throws IllegalArgumentException

Implements org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

Doc from org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

This allows third party systems to add reified active descriptors to the system. The active descriptor given must be fully reified (isReified must return true) and the create and destroy methods must be implemented. A deep copy will be made of the descriptor

This method can be called only in the execution context of the configure() method.

Annotations
@Override
Exceptions
IllegalArgumentException:
if the descriptor is not reified
addActiveDescriptorback to summary
public <T> ActiveDescriptor<T> addActiveDescriptor(ActiveDescriptor<T> activeDescriptor, boolean requiresDeepCopy) throws IllegalArgumentException

Implements org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

Doc from org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

This allows third party systems to add reified active descriptors to the system. The active descriptor given must be fully reified (isReified must return true) and the create and destroy methods must be implemented. A deep copy will be made of the descriptor

Annotations
@Override
Exceptions
IllegalArgumentException:
if the descriptor is not reified
addActiveDescriptorback to summary
public <T> ActiveDescriptor<T> addActiveDescriptor(Class<T> rawClass) throws MultiException, IllegalArgumentException

Implements org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

Doc from org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

This adds an active descriptor to the system based completely on the analysis of the given class. The class itself and all interfaces marked contract will be in the list of advertised services. The scope and qualifiers will be taken from the annotations on the class.

This method can be called only in the execution context of the configure() method.

Annotations
@Override
Exceptions
MultiException:
If this class cannot be a service
IllegalArgumentException:
if rawClass is null
addActiveFactoryDescriptorback to summary
public <T> FactoryDescriptors addActiveFactoryDescriptor(Class<? extends Factory<T>> rawFactoryClass) throws MultiException, IllegalArgumentException

Implements org.glassfish.hk2.api.DynamicConfiguration.addActiveFactoryDescriptor.

Doc from org.glassfish.hk2.api.DynamicConfiguration.addActiveFactoryDescriptor.

This adds two active descriptors to the system based completely on the analysis of the given Factory class. The Factory class itself and all interfaces marked contract will be in the list of advertised services. The scope and qualifiers will be taken from the annotations on the class. The annotations on the Factory#provide method will provide the scope and qualifiers of the service produced by the Factory

This method can be called only in the execution context of the configure() method.

Annotations
@Override
Exceptions
MultiException:
If this class cannot be a service
IllegalArgumentException:
if rawClass is null
addIdempotentFilterback to summary
public void addIdempotentFilter(Filter... unbindFilter) throws IllegalArgumentException

Implements org.glassfish.hk2.api.DynamicConfiguration.addIdempotentFilter.

Doc from org.glassfish.hk2.api.DynamicConfiguration.addIdempotentFilter.

At commit time all idempotent filters in this dynamic configuration will be run against all validation-visible descriptors. If any of the idempotent filters are a match then the commit will FAIL and none of the descriptors in this DynamicConfiguration will be added or removed. The idempotent filters will be run under the same lock as the commit, and hence can guarantee true idempotency of the transaction.

The normal use case for the use of this filter is to ensure that a service is only added once to the ServiceLocator, even when multiple threads may be attempting to add the same service

The filter passed in should not do any change to the set of descriptors itself, any attempt to do so will leave the system in an inconsistent state. IndexedFilter is supported and is the normal use of an idempotent filter, though it is not required

This method can be called only in the execution context of the configure() method.

Annotations
@Override
Exceptions
IllegalArgumentException:
If any of the filters are null
addUnbindFilterback to summary
public void addUnbindFilter(Filter unbindFilter) throws IllegalArgumentException

Implements org.glassfish.hk2.api.DynamicConfiguration.addUnbindFilter.

Doc from org.glassfish.hk2.api.DynamicConfiguration.addUnbindFilter.

This filter will added to the list of filters in this Configuration that will determine which Descriptors will be removed from the system. Only services directly from this Configuration objects' associated ServiceLocator will be given to this Filter (it will not be given descriptors from the ServiceLocators parent). The descriptors passed into this filter may be cast to ActiveDescriptor. The descriptors passed into this filter may or may not have been reified. This filter should not reify passed in descriptors.

And descriptor for which this filter returns true will be removed from the ServiceLocator prior to any additions that are performed with this Configuration object. Hence a Configuration can remove and add a descriptor of the same type in one commit.

In order to unbind a filter the caller of commit must pass the LOOKUP validators and the UNBIND validators.

This method can be called only in the execution context of the configure() method.

Annotations
@Override
Exceptions
IllegalArgumentException:
if unbindFilter is null
bindback to summary
public <T> ServiceBindingBuilder<T> bind(Class<T> serviceType)

Start building a new class-based service binding. Does NOT bind the service type itself as a contract type.

Parameters
<T>
service type.
serviceType:Class<T>

service class.

Returns:ServiceBindingBuilder<T>

initialized binding builder.

bindback to summary
public <T> ScopedBindingBuilder<T> bind(T service)

Start building a new instance-based service binding. The binding is naturally considered to be a singleton-scoped. Does NOT bind the service type itself as a contract type.

Parameters
<T>
service type.
service:T

service instance.

Returns:ScopedBindingBuilder<T>

initialized binding builder.

bindback to summary
public void bind(DynamicConfiguration configuration)

Implements org.glassfish.hk2.utilities.Binder.bind.

Doc from org.glassfish.hk2.utilities.Binder.bind.

This method will be called by the ServiceLocatorUtilities#bind(org.glassfish.hk2.api.ServiceLocator, Binder...) method for each binder given. All of the updates will be committed as one commit operation.

Annotations
@Override
bindback to summary
public <T> ActiveDescriptor<T> bind(Descriptor descriptor)

Implements org.glassfish.hk2.api.DynamicConfiguration.bind.

Doc from org.glassfish.hk2.api.DynamicConfiguration.bind.

This method will bind the given descriptor to this Module. If the descriptor given is not an ActiveDescriptor then a non-reified ActiveDescriptor will be returned with the system provided fields set. If the descriptor given is a reified ActiveDescriptor then the descriptor returned will be a reified ActiveDescriptor that takes all values except for the id from the given descriptor. A deep copy will be made of the incoming descriptor

This method can be called only in the execution context of the configure() method.

Annotations
@Override
bindback to summary
public <T> ActiveDescriptor<T> bind(Descriptor descriptor, boolean requiresDeepCopy)

Implements org.glassfish.hk2.api.DynamicConfiguration.bind.

Doc from org.glassfish.hk2.api.DynamicConfiguration.bind.

This method will bind the given descriptor to this Module. If the descriptor given is not an ActiveDescriptor then a non-reified ActiveDescriptor will be returned with the system provided fields set. If the descriptor given is a reified ActiveDescriptor then the descriptor returned will be a reified ActiveDescriptor that takes all values except for the id from the given descriptor.

Annotations
@Override
bindback to summary
public FactoryDescriptors bind(FactoryDescriptors factoryDescriptors)

Implements org.glassfish.hk2.api.DynamicConfiguration.bind.

Doc from org.glassfish.hk2.api.DynamicConfiguration.bind.

This method will bind the descriptors found in the FactoryDescriptors. This method will first validate the descriptors from the FactoryDescriptors and then simply bind them into this configuration as two independent descriptors. A deep copy will be made of both descriptors

This method can be called only in the execution context of the configure() method.

Annotations
@Override
bindback to summary
public FactoryDescriptors bind(FactoryDescriptors factoryDescriptors, boolean requiresDeepCopy)

Implements org.glassfish.hk2.api.DynamicConfiguration.bind.

Doc from org.glassfish.hk2.api.DynamicConfiguration.bind.

This method will bind the descriptors found in the FactoryDescriptors. This method will first validate the descriptors from the FactoryDescriptors and then simply bind them into this configuration as two independent descriptors. A deep copy will be made of both descriptors

Annotations
@Override
bindAsContractback to summary
public <T> ServiceBindingBuilder<T> bindAsContract(Class<T> serviceType)

Start building a new class-based service binding. Binds the service type itself as a contract type.

Parameters
<T>
service type.
serviceType:Class<T>

service class.

Returns:ServiceBindingBuilder<T>

initialized binding builder.

bindAsContractback to summary
public <T> ServiceBindingBuilder<T> bindAsContract(TypeLiteral<T> serviceType)

Start building a new generic type-based service binding. Binds the generic service type itself as a contract type.

Parameters
<T>
service type.
serviceType:TypeLiteral<T>

generic service type information.

Returns:ServiceBindingBuilder<T>

initialized binding builder.

bindAsContractback to summary
public <T> ServiceBindingBuilder<T> bindAsContract(Type serviceType)

Start building a new generic type-based service binding. Binds the generic service type itself as a contract type.

Parameters
<T>
service type.
serviceType:Type

generic service type information.

Returns:ServiceBindingBuilder<T>

initialized binding builder.

bindFactoryback to summary
public <T> ServiceBindingBuilder<T> bindFactory(Class<? extends Factory<T>> factoryType, Class<? extends Annotation> factoryScope)

Start building a new factory class-based service binding.

Parameters
<T>
service type.
factoryType:Class<? extends Factory<T>>

service factory class.

factoryScope:Class<? extends Annotation>

factory scope.

Returns:ServiceBindingBuilder<T>

initialized binding builder.

bindFactoryback to summary
public <T> ServiceBindingBuilder<T> bindFactory(Class<? extends Factory<T>> factoryType)

Start building a new factory class-based service binding. The factory itself is bound in a per-lookup scope.

Parameters
<T>
service type.
factoryType:Class<? extends Factory<T>>

service factory class.

Returns:ServiceBindingBuilder<T>

initialized binding builder.

bindFactoryback to summary
public <T> ServiceBindingBuilder<T> bindFactory(Factory<T> factory)

Start building a new factory instance-based service binding.

Parameters
<T>
service type.
factory:Factory<T>

service instance.

Returns:ServiceBindingBuilder<T>

initialized binding builder.

commitback to summary
public void commit() throws MultiException

Implements org.glassfish.hk2.api.DynamicConfiguration.commit.

Doc from org.glassfish.hk2.api.DynamicConfiguration.commit.

This causes the configuration to get committed. This method may only be called once

This method can be called only in the execution context of the configure() method.

Annotations
@Override
Exceptions
MultiException:
If errors were found in the commit process
completeback to summary
private void complete()
configurationback to summary
private DynamicConfiguration configuration()

Get the active binder factory instance used for binding configuration. This method can only be called from within the scope of the configure() method.

Returns:DynamicConfiguration

dynamic configuration instance used for binding configuration.

Exceptions
IllegalStateException:
in case the method is not called from within an active call to configure() method.
configureback to summary
protected abstract void configure()

Implement to provide binding definitions using the exposed binding methods.

getDefaultBinderLoaderback to summary
private HK2Loader getDefaultBinderLoader()
installback to summary
public final void install(Binder... binders)

Adds all binding definitions from the binders to the binding configuration.

Parameters
binders:Binder[]

binders whose binding definitions should be configured.

registerTwoPhaseResourcesback to summary
public void registerTwoPhaseResources(TwoPhaseResource... resources)

Implements org.glassfish.hk2.api.DynamicConfiguration.registerTwoPhaseResources.

Doc from org.glassfish.hk2.api.DynamicConfiguration.registerTwoPhaseResources.

Registers two-phase resources in the order in which they are to run. Subsequent calls to this method will add resources at the end of the existing list

Annotations
@Override
resetBuilderback to summary
private <T> AbstractBindingBuilder<T> resetBuilder(AbstractBindingBuilder<T> newBuilder)
setLoaderback to summary
private void setLoader(Descriptor descriptor)