Class AbstractBindingBuilder<T>
java.lang.Object
org.glassfish.hk2.utilities.binding.AbstractBindingBuilder<T>
- Type Parameters:
T
- bound service type.
- All Implemented Interfaces:
BindingBuilder<T>
,NamedBindingBuilder<T>
,ScopedBindingBuilder<T>
,ScopedNamedBindingBuilder<T>
,ServiceBindingBuilder<T>
- Direct Known Subclasses:
AbstractBindingBuilder.ClassBasedBindingBuilder
,AbstractBindingBuilder.FactoryInstanceBasedBindingBuilder
,AbstractBindingBuilder.FactoryTypeBasedBindingBuilder
,AbstractBindingBuilder.InstanceBasedBindingBuilder
abstract class AbstractBindingBuilder<T>
extends Object
implements ServiceBindingBuilder<T>, NamedBindingBuilder<T>, ScopedBindingBuilder<T>, ScopedNamedBindingBuilder<T>
Abstract binding builder implementation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static class
private static class
private static class
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) String
Analyzer to use with this descriptorContracts the service should be bound to.(package private) Type
(package private) HK2Loader
Bound service loader.Binding metadata (e.g.(package private) String
Binding name (see @Named).(package private) Boolean
Injectee is proxiable.(package private) Boolean
Injectee should be proxied even inside the same scope(package private) Set
<Annotation> Qualifiers (other than @Named).(package private) Integer
Binding rank.(package private) Class
<? extends Annotation> Binding scope.(package private) Annotation
Binding scope as annotation -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionanalyzeWith
(String analyzer) Set the name of theClassAnalyzer
on the binding.Call this if the parameterized type of the implementation class is known.(package private) abstract void
complete
(DynamicConfiguration configuration, HK2Loader defaultLoader) Build the binding descriptor and bind it in thedynamic configuration
.(package private) static <T> AbstractBindingBuilder
<T> Create a new service binding builder.(package private) static <T> AbstractBindingBuilder
<T> Create a new service binding builder.(package private) static <T> AbstractBindingBuilder
<T> create
(TypeLiteral<T> serviceType, boolean bindAsContract) Create a new service binding builder.(package private) static <T> AbstractBindingBuilder
<T> create
(T service) Create a new service binding builder.(package private) static <T> AbstractBindingBuilder
<T> createFactoryBinder
(Class<? extends Factory<T>> factoryType, Class<? extends Annotation> factoryScope) Create a new service binding builder.(package private) static <T> AbstractBindingBuilder
<T> createFactoryBinder
(Factory<T> factory) Create a new service binding builder.in
(Annotation scopeAnnotation) Scope a binding.in
(Class<? extends Annotation> scopeAnnotation) Scope a binding.Custom HK2 loader to be used when service class is about to be loaded.Name
the binding.proxy
(boolean proxiable) Set proxy flag on the binding.proxyForSameScope
(boolean proxyForSameScope) Set proxyForSameScope flag on the bindingqualifiedBy
(Annotation annotation) Add a binding qualifier annotation.void
ranked
(int rank) Rank the binding.Bind a new contract to a service.Bind a new contract to a service.to
(TypeLiteral<?> contract) Bind a new contract to a service.withMetadata
(String key, String value) Add binding descriptor metadata.withMetadata
(String key, List<String> values) Add binding descriptor metadata.
-
Field Details
-
contracts
Contracts the service should be bound to. -
loader
HK2Loader loaderBound service loader. -
metadata
Binding metadata (e.g. useful for filtering). -
qualifiers
Set<Annotation> qualifiersQualifiers (other than @Named). -
scopeAnnotation
Annotation scopeAnnotationBinding scope as annotation -
scope
Class<? extends Annotation> scopeBinding scope. -
ranked
Integer rankedBinding rank. -
name
String nameBinding name (see @Named). -
proxiable
Boolean proxiableInjectee is proxiable. -
proxyForSameScope
Boolean proxyForSameScopeInjectee should be proxied even inside the same scope -
implementationType
Type implementationType -
analyzer
String analyzerAnalyzer to use with this descriptor
-
-
Constructor Details
-
AbstractBindingBuilder
AbstractBindingBuilder()
-
-
Method Details
-
proxy
Description copied from interface:ServiceBindingBuilder
Set proxy flag on the binding.- Specified by:
proxy
in interfaceNamedBindingBuilder<T>
- Specified by:
proxy
in interfaceScopedBindingBuilder<T>
- Specified by:
proxy
in interfaceScopedNamedBindingBuilder<T>
- Specified by:
proxy
in interfaceServiceBindingBuilder<T>
- Parameters:
proxiable
- flag to determine if the binding should be proxiable.
-
proxyForSameScope
Description copied from interface:ServiceBindingBuilder
Set proxyForSameScope flag on the binding- Specified by:
proxyForSameScope
in interfaceScopedBindingBuilder<T>
- Specified by:
proxyForSameScope
in interfaceServiceBindingBuilder<T>
- Parameters:
proxyForSameScope
- flag to determine if proxies should be generated even within the same scope- Returns:
- A further refined ServiceBindingBuilder
-
analyzeWith
Description copied from interface:ServiceBindingBuilder
Set the name of theClassAnalyzer
on the binding.- Specified by:
analyzeWith
in interfaceScopedBindingBuilder<T>
- Specified by:
analyzeWith
in interfaceScopedNamedBindingBuilder<T>
- Specified by:
analyzeWith
in interfaceServiceBindingBuilder<T>
- Parameters:
analyzer
- The name of the analyzer that should be used. May be null to indicate the default class analzyer
-
to
Description copied from interface:ServiceBindingBuilder
Bind a new contract to a service.- Specified by:
to
in interfaceNamedBindingBuilder<T>
- Specified by:
to
in interfaceScopedBindingBuilder<T>
- Specified by:
to
in interfaceScopedNamedBindingBuilder<T>
- Specified by:
to
in interfaceServiceBindingBuilder<T>
- Parameters:
contract
- contract type.- Returns:
- updated binder.
-
to
Description copied from interface:ServiceBindingBuilder
Bind a new contract to a service.- Specified by:
to
in interfaceNamedBindingBuilder<T>
- Specified by:
to
in interfaceScopedBindingBuilder<T>
- Specified by:
to
in interfaceScopedNamedBindingBuilder<T>
- Specified by:
to
in interfaceServiceBindingBuilder<T>
- Parameters:
contract
- contract type.- Returns:
- updated binder.
-
to
Description copied from interface:ServiceBindingBuilder
Bind a new contract to a service.- Specified by:
to
in interfaceServiceBindingBuilder<T>
- Parameters:
contract
- contract type.- Returns:
- updated binder.
-
loadedBy
Description copied from interface:ServiceBindingBuilder
Custom HK2 loader to be used when service class is about to be loaded.- Specified by:
loadedBy
in interfaceNamedBindingBuilder<T>
- Specified by:
loadedBy
in interfaceScopedBindingBuilder<T>
- Specified by:
loadedBy
in interfaceScopedNamedBindingBuilder<T>
- Specified by:
loadedBy
in interfaceServiceBindingBuilder<T>
- Parameters:
loader
- custom service loader.- Returns:
- updated binder.
-
withMetadata
Description copied from interface:ServiceBindingBuilder
Add binding descriptor metadata. The metadata can be later used to e.g.filter
binding descriptors. If this is forFactory
descriptors the metadata will be placed on both the Factory as a service and on the FactoriesFactory.provide()
method- Specified by:
withMetadata
in interfaceNamedBindingBuilder<T>
- Specified by:
withMetadata
in interfaceScopedBindingBuilder<T>
- Specified by:
withMetadata
in interfaceScopedNamedBindingBuilder<T>
- Specified by:
withMetadata
in interfaceServiceBindingBuilder<T>
- Parameters:
key
- metadata key.value
- metadata value.- Returns:
- updated binder.
-
withMetadata
Description copied from interface:ServiceBindingBuilder
Add binding descriptor metadata. The metadata can be later used to e.g.filter
binding descriptors. If this is forFactory
descriptors the metadata will be placed on both the Factory as a service and on the FactoriesFactory.provide()
method- Specified by:
withMetadata
in interfaceNamedBindingBuilder<T>
- Specified by:
withMetadata
in interfaceScopedBindingBuilder<T>
- Specified by:
withMetadata
in interfaceScopedNamedBindingBuilder<T>
- Specified by:
withMetadata
in interfaceServiceBindingBuilder<T>
- Parameters:
key
- metadata key.values
- metadata values.- Returns:
- updated binder.
-
qualifiedBy
Description copied from interface:ServiceBindingBuilder
Add a binding qualifier annotation. If this is being used with aFactory
then both the Factory Service and theFactory.provide()
method will get the qualifier- Specified by:
qualifiedBy
in interfaceNamedBindingBuilder<T>
- Specified by:
qualifiedBy
in interfaceScopedBindingBuilder<T>
- Specified by:
qualifiedBy
in interfaceScopedNamedBindingBuilder<T>
- Specified by:
qualifiedBy
in interfaceServiceBindingBuilder<T>
- Parameters:
annotation
- qualifier annotation.- Returns:
- updated binder.
-
in
Description copied from interface:ServiceBindingBuilder
Scope a binding.- Specified by:
in
in interfaceServiceBindingBuilder<T>
- Parameters:
scopeAnnotation
- scope annotation.- Returns:
- updated binding.
-
in
Description copied from interface:ServiceBindingBuilder
Scope a binding.- Specified by:
in
in interfaceNamedBindingBuilder<T>
- Specified by:
in
in interfaceServiceBindingBuilder<T>
- Parameters:
scopeAnnotation
- scope annotation.- Returns:
- updated binding.
-
named
Description copied from interface:ServiceBindingBuilder
Name
the binding.- Specified by:
named
in interfaceScopedBindingBuilder<T>
- Specified by:
named
in interfaceServiceBindingBuilder<T>
- Parameters:
name
- new name value.- Returns:
- updated binding.
-
ranked
public void ranked(int rank) Description copied from interface:ServiceBindingBuilder
Rank the binding. The higher rank, the more prominent position in an injectediterable provider
for a contract.- Specified by:
ranked
in interfaceNamedBindingBuilder<T>
- Specified by:
ranked
in interfaceScopedBindingBuilder<T>
- Specified by:
ranked
in interfaceScopedNamedBindingBuilder<T>
- Specified by:
ranked
in interfaceServiceBindingBuilder<T>
- Parameters:
rank
- binding rank to be used to resolve ordering in case of multiple services are bound to the same contract.
-
asType
Description copied from interface:ServiceBindingBuilder
Call this if the parameterized type of the implementation class is known. This must only be called with a ParameterizedType- Specified by:
asType
in interfaceNamedBindingBuilder<T>
- Specified by:
asType
in interfaceServiceBindingBuilder<T>
- Parameters:
t
- The non-null ParameterizedType describing the implementation- Returns:
- A DescriptorBuilder with the given implementationType
-
complete
Build the binding descriptor and bind it in thedynamic configuration
.- Parameters:
configuration
- dynamic binding configuration.defaultLoader
- default HK2 loader that should be used in case a custom loader was not set.
-
create
Create a new service binding builder.- Type Parameters:
T
- service type.- Parameters:
serviceType
- service class.bindAsContract
- iftrue
, the service class will be bound as one of the contracts.- Returns:
- initialized binding builder.
-
create
Create a new service binding builder.- Type Parameters:
T
- service type.- Parameters:
serviceType
- service class.bindAsContract
- iftrue
, the service class will be bound as one of the contracts.- Returns:
- initialized binding builder.
-
create
Create a new service binding builder.- Type Parameters:
T
- service type.- Parameters:
serviceType
- generic service type.bindAsContract
- iftrue
, the service class will be bound as one of the contracts.- Returns:
- initialized binding builder.
-
create
Create a new service binding builder.- Parameters:
service
- service instance.- Returns:
- initialized binding builder.
-
createFactoryBinder
Create a new service binding builder.- Parameters:
factory
- service factory instance.- Returns:
- initialized binding builder.
-
createFactoryBinder
static <T> AbstractBindingBuilder<T> createFactoryBinder(Class<? extends Factory<T>> factoryType, Class<? extends Annotation> factoryScope) Create a new service binding builder.- Parameters:
factoryType
- service factory class.factoryScope
- service factory scope.- Returns:
- initialized binding builder.
-