Package org.glassfish.hk2.utilities
Interface DescriptorBuilder
-
- All Known Implementing Classes:
DescriptorBuilderImpl
public interface DescriptorBuilder
This is an object that uses the Builder pattern in order to generate a Descriptor (for binding) or a Filter (for searching). It is intended to facilitate query strings of method calls that is simple to understand and read.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description DescriptorBuilder
analyzeWith(String serviceName)
Call this if the descriptor should be analyzed with theClassAnalyzer
service of the given nameDescriptorBuilder
andLoadWith(HK2Loader loader)
Call this if this descriptor should be loaded with the given HK2LoaderDescriptorImpl
build()
Generates a descriptor that can be used in binding operationsFactoryDescriptors
buildFactory()
Generates a factory descriptor that can be used in binding operations.FactoryDescriptors
buildFactory(Class<? extends Annotation> factoryScope)
Generates a factory descriptor that can be used in binding operations.FactoryDescriptors
buildFactory(String factoryScope)
Generates a factory descriptor that can be used in binding operations.DescriptorBuilder
has(String key, String value)
An instance of data to be associated with this descriptorDescriptorBuilder
has(String key, List<String> values)
An instance of data to be associated with this descriptorDescriptorBuilder
in(Class<? extends Annotation> scope)
A scope to be associated with this descriptor object.DescriptorBuilder
in(String scope)
A scope to be associated with this descriptor object.DescriptorBuilder
localOnly()
This will cause the descriptorVisibility field of the returned descriptor to return LOCALDescriptorBuilder
named(String name)
The name for this descriptor object.DescriptorBuilder
ofRank(int rank)
The rank to be associated with this descriptor.DescriptorBuilder
proxy()
This will cause the isProxiable field of the returned descriptor to return true (it will force this descriptor to use proxies).DescriptorBuilder
proxy(boolean forceProxy)
This will cause the isProxiable field of the returned descriptor to return the given value.DescriptorBuilder
proxyForSameScope()
This will cause the isProxyForSameScope field of the returned descriptor to return true (it will force this descriptor to proxy even when injecting into the same scope).DescriptorBuilder
proxyForSameScope(boolean proxyForSameScope)
This will cause the isProxyForSameScope field of the returned descriptor to return the given value.DescriptorBuilder
qualifiedBy(Annotation annotation)
A qualifier to be associated with this descriptor object.DescriptorBuilder
qualifiedBy(String annotation)
A qualifier to be associated with this descriptor objectDescriptorBuilder
to(Class<?> contract)
A contract to be associated with this descriptor object.DescriptorBuilder
to(String contract)
A contract to be associated with this descriptor object.DescriptorBuilder
visibility(DescriptorVisibility visibility)
This will set the descriptorVisibility field of the returned descriptor
-
-
-
Method Detail
-
named
DescriptorBuilder named(String name) throws IllegalArgumentException
The name for this descriptor object. Note that at the current time a descriptor can only have one name, hence this method will throw an IllegalArgumentException if named is called more than once.- Parameters:
name
- The name to be associated with this Descriptor- Returns:
- A DescriptorBuilder with the given name
- Throws:
IllegalArgumentException
- if there is more than one name on the predicate
-
to
DescriptorBuilder to(Class<?> contract) throws IllegalArgumentException
A contract to be associated with this descriptor object.- Parameters:
contract
- A class that is annotated with Contract to be associated with this Descriptor- Returns:
- A DescriptorBuilder with the given name
- Throws:
IllegalArgumentException
- on failures
-
to
DescriptorBuilder to(String contract) throws IllegalArgumentException
A contract to be associated with this descriptor object.- Parameters:
contract
- The fully qualified name of a class that is annotated with Contract.- Returns:
- A DescriptorBuilder with the given name
- Throws:
IllegalArgumentException
- on failures
-
in
DescriptorBuilder in(Class<? extends Annotation> scope) throws IllegalArgumentException
A scope to be associated with this descriptor object. Note that at the current time a descriptor can only have one scope, hence this method will throw an IllegalArgumentException if in is called more than once.- Parameters:
scope
- The class of the scope this descriptor is to have.- Returns:
- A DescriptorBuilder with the given scope
- Throws:
IllegalArgumentException
- If in is called more than once
-
in
DescriptorBuilder in(String scope) throws IllegalArgumentException
A scope to be associated with this descriptor object. Note that at the current time a descriptor can only have one scope, hence this method will throw an IllegalArgumentException if in is called more than once.- Parameters:
scope
- The fully qualified class name of the scope this predicate is to have.- Returns:
- A DescriptorBuilder with the given scope
- Throws:
IllegalArgumentException
- If in is called more than once
-
qualifiedBy
DescriptorBuilder qualifiedBy(Annotation annotation) throws IllegalArgumentException
A qualifier to be associated with this descriptor object. It is dangerous to use this method with a ghost annotation (one that is not on the object) if that annotation has fields, as these fields will NOT survive being put into theDescriptor
. Use this method with care and ONLY with annotations that do not have fields. A safe version of this method for use with ghost annotations isActiveDescriptorBuilder.qualifiedBy(Annotation)
- Parameters:
annotation
- The annotation to be associated with this descriptor- Returns:
- A DescriptorBuilder with the given annotation
- Throws:
IllegalArgumentException
- on failures
-
qualifiedBy
DescriptorBuilder qualifiedBy(String annotation) throws IllegalArgumentException
A qualifier to be associated with this descriptor object- Parameters:
annotation
- The fully qualified class name of an annotation to be associated with this descriptor- Returns:
- A DescriptorBuilder with the given annotation
- Throws:
IllegalArgumentException
- on failures
-
has
DescriptorBuilder has(String key, String value) throws IllegalArgumentException
An instance of data to be associated with this descriptor- Parameters:
key
- The key for the data to be associated with this descriptorvalue
- The value this key should take (single value metadata)- Returns:
- A DescriptorBuilder with the given metadata
- Throws:
IllegalArgumentException
-
has
DescriptorBuilder has(String key, List<String> values) throws IllegalArgumentException
An instance of data to be associated with this descriptor- Parameters:
key
- The key for the data to be associated with this descriptorvalues
- The values this key should take (single value metadata)- Returns:
- A DescriptorBuilder with the given metadata
- Throws:
IllegalArgumentException
-
ofRank
DescriptorBuilder ofRank(int rank)
The rank to be associated with this descriptor. The last rank bound wins- Parameters:
rank
- The rank to be associated with this descriptor.- Returns:
- A DescriptorBuilder with the given rank
-
proxy
DescriptorBuilder proxy()
This will cause the isProxiable field of the returned descriptor to return true (it will force this descriptor to use proxies).- Returns:
- A DescriptorBuilder with the proxiable field set to true
-
proxy
DescriptorBuilder proxy(boolean forceProxy)
This will cause the isProxiable field of the returned descriptor to return the given value.- Parameters:
forceProxy
- if true then this descriptor will be proxied, if false then this descriptor will NOT be proxied- Returns:
- A DescriptorBuilder with the proxiable field set to the given value
-
proxyForSameScope
DescriptorBuilder proxyForSameScope()
This will cause the isProxyForSameScope field of the returned descriptor to return true (it will force this descriptor to proxy even when injecting into the same scope).- Returns:
- A DescriptorBuilder with the proxyForSameScope field set to true
-
proxyForSameScope
DescriptorBuilder proxyForSameScope(boolean proxyForSameScope)
This will cause the isProxyForSameScope field of the returned descriptor to return the given value.- Parameters:
proxyForSameScope
- if true then this descriptor will be proxied even when being injected into the same scope, if false then this descriptor will NOT be proxied when injected into a service of the same scope- Returns:
- A DescriptorBuilder with the proxyForSameScope field set to the given value
-
localOnly
DescriptorBuilder localOnly()
This will cause the descriptorVisibility field of the returned descriptor to return LOCAL- Returns:
- A DescriptorBuilder with the descriptorVisibility field to be set to LOCAL
-
visibility
DescriptorBuilder visibility(DescriptorVisibility visibility)
This will set the descriptorVisibility field of the returned descriptor- Parameters:
visibility
- The non-null visibility that this descriptor should take- Returns:
- A DescriptorBuilder with the descriptorVisibility field set to the input value
-
andLoadWith
DescriptorBuilder andLoadWith(HK2Loader loader) throws IllegalArgumentException
Call this if this descriptor should be loaded with the given HK2Loader- Parameters:
loader
- The loader to use with this descriptor- Returns:
- A DescriptorBuilder with the given HK2Loader
- Throws:
IllegalArgumentException
- if the HK2Loader is set non-null more than once
-
analyzeWith
DescriptorBuilder analyzeWith(String serviceName)
Call this if the descriptor should be analyzed with theClassAnalyzer
service of the given name- Parameters:
serviceName
- the name of theClassAnalyzer
service that should be used to analyze this service- Returns:
- A DescriptorBuilder with the given analysis service
-
build
DescriptorImpl build() throws IllegalArgumentException
Generates a descriptor that can be used in binding operations- Returns:
- The descriptor that has been built up with this DescriptorBuilder
- Throws:
IllegalArgumentException
- if the built descriptor is invalid
-
buildFactory
FactoryDescriptors buildFactory() throws IllegalArgumentException
Generates a factory descriptor that can be used in binding operations. The generated factory service will have no name, no qualifiers and the same metadata as given to this builder. The factory will be put into PerLookup scope- Returns:
- The descriptor that has been built up with this DescriptorBuilder
- Throws:
IllegalArgumentException
- if the built descriptor is invalid
-
buildFactory
FactoryDescriptors buildFactory(String factoryScope) throws IllegalArgumentException
Generates a factory descriptor that can be used in binding operations. The generated factory service will have no name, no qualifiers and the same metadata as given to this builder. The generated service will have had the implementation class removed from its set of advertised contracts- Parameters:
factoryScope
- The scope the factory service itself is in.- Returns:
- The descriptor that has been built up with this DescriptorBuilder
- Throws:
IllegalArgumentException
- if the built descriptor is invalid
-
buildFactory
FactoryDescriptors buildFactory(Class<? extends Annotation> factoryScope) throws IllegalArgumentException
Generates a factory descriptor that can be used in binding operations. The generated factory service will have no name, no qualifiers and the same metadata as given to this builder. The generated service will have had the implementation class removed from its set of advertised contracts- Parameters:
factoryScope
- The scope the factory service itself is in. If this is null the PerLookup scope will be used- Returns:
- The descriptor that has been built up with this DescriptorBuilder
- Throws:
IllegalArgumentException
- if the built descriptor is invalid
-
-