Package org.glassfish.hk2.internal
Class DescriptorBuilderImpl
- java.lang.Object
-
- org.glassfish.hk2.internal.DescriptorBuilderImpl
-
- All Implemented Interfaces:
DescriptorBuilder
public class DescriptorBuilderImpl extends java.lang.Object implements DescriptorBuilder
This is a simple implementation of theDescriptorBuilder
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringanalysisNameprivate java.util.HashSet<java.lang.String>contractsprivate java.lang.Stringimplementationprivate HK2Loaderloaderprivate java.util.HashMap<java.lang.String,java.util.List<java.lang.String>>metadatasprivate java.lang.Stringnameprivate java.lang.Booleanproxyprivate java.lang.BooleanproxyForSameScopeprivate java.util.HashSet<java.lang.String>qualifiersprivate intrankprivate java.lang.Stringscopeprivate DescriptorVisibilityvisibility
-
Constructor Summary
Constructors Constructor Description DescriptorBuilderImpl()The basid constructorDescriptorBuilderImpl(java.lang.String implementation, boolean addToContracts)A descriptor builder with the given implementation
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DescriptorBuilderanalyzeWith(java.lang.String serviceName)Call this if the descriptor should be analyzed with theClassAnalyzerservice of the given nameDescriptorBuilderandLoadWith(HK2Loader loader)Call this if this descriptor should be loaded with the given HK2LoaderDescriptorImplbuild()Generates a descriptor that can be used in binding operationsFactoryDescriptorsbuildFactory()Generates a factory descriptor that can be used in binding operations.FactoryDescriptorsbuildFactory(java.lang.Class<? extends java.lang.annotation.Annotation> factoryScope)Generates a factory descriptor that can be used in binding operations.FactoryDescriptorsbuildFactory(java.lang.String factoryScope)Generates a factory descriptor that can be used in binding operations.DescriptorBuilderhas(java.lang.String key, java.lang.String value)An instance of data to be associated with this descriptorDescriptorBuilderhas(java.lang.String key, java.util.List<java.lang.String> values)An instance of data to be associated with this descriptorDescriptorBuilderin(java.lang.Class<? extends java.lang.annotation.Annotation> scope)A scope to be associated with this descriptor object.DescriptorBuilderin(java.lang.String scope)A scope to be associated with this descriptor object.DescriptorBuilderlocalOnly()This will cause the descriptorVisibility field of the returned descriptor to return LOCALDescriptorBuildernamed(java.lang.String name)The name for this descriptor object.DescriptorBuilderofRank(int rank)The rank to be associated with this descriptor.DescriptorBuilderproxy()This will cause the isProxiable field of the returned descriptor to return true (it will force this descriptor to use proxies).DescriptorBuilderproxy(boolean forceProxy)This will cause the isProxiable field of the returned descriptor to return the given value.DescriptorBuilderproxyForSameScope()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).DescriptorBuilderproxyForSameScope(boolean proxyForSameScope)This will cause the isProxyForSameScope field of the returned descriptor to return the given value.DescriptorBuilderqualifiedBy(java.lang.annotation.Annotation annotation)A qualifier to be associated with this descriptor object.DescriptorBuilderqualifiedBy(java.lang.String annotation)A qualifier to be associated with this descriptor objectDescriptorBuilderto(java.lang.Class<?> contract)A contract to be associated with this descriptor object.DescriptorBuilderto(java.lang.String contract)A contract to be associated with this descriptor object.DescriptorBuildervisibility(DescriptorVisibility visibility)This will set the descriptorVisibility field of the returned descriptor
-
-
-
Field Detail
-
name
private java.lang.String name
-
contracts
private final java.util.HashSet<java.lang.String> contracts
-
scope
private java.lang.String scope
-
qualifiers
private final java.util.HashSet<java.lang.String> qualifiers
-
metadatas
private final java.util.HashMap<java.lang.String,java.util.List<java.lang.String>> metadatas
-
implementation
private java.lang.String implementation
-
loader
private HK2Loader loader
-
rank
private int rank
-
proxy
private java.lang.Boolean proxy
-
proxyForSameScope
private java.lang.Boolean proxyForSameScope
-
visibility
private DescriptorVisibility visibility
-
analysisName
private java.lang.String analysisName
-
-
Constructor Detail
-
DescriptorBuilderImpl
public DescriptorBuilderImpl()
The basid constructor
-
DescriptorBuilderImpl
public DescriptorBuilderImpl(java.lang.String implementation, boolean addToContracts)A descriptor builder with the given implementation- Parameters:
implementation- The implementation this should takeaddToContracts- Whether or not to add the implementation to the set of contracts
-
-
Method Detail
-
named
public DescriptorBuilder named(java.lang.String name) throws java.lang.IllegalArgumentException
Description copied from interface:DescriptorBuilderThe 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.- Specified by:
namedin interfaceDescriptorBuilder- Parameters:
name- The name to be associated with this Descriptor- Returns:
- A DescriptorBuilder with the given name
- Throws:
java.lang.IllegalArgumentException- if there is more than one name on the predicate
-
to
public DescriptorBuilder to(java.lang.Class<?> contract) throws java.lang.IllegalArgumentException
Description copied from interface:DescriptorBuilderA contract to be associated with this descriptor object.- Specified by:
toin interfaceDescriptorBuilder- Parameters:
contract- A class that is annotated with Contract to be associated with this Descriptor- Returns:
- A DescriptorBuilder with the given name
- Throws:
java.lang.IllegalArgumentException- on failures
-
to
public DescriptorBuilder to(java.lang.String contract) throws java.lang.IllegalArgumentException
Description copied from interface:DescriptorBuilderA contract to be associated with this descriptor object.- Specified by:
toin interfaceDescriptorBuilder- Parameters:
contract- The fully qualified name of a class that is annotated with Contract.- Returns:
- A DescriptorBuilder with the given name
- Throws:
java.lang.IllegalArgumentException- on failures
-
in
public DescriptorBuilder in(java.lang.Class<? extends java.lang.annotation.Annotation> scope) throws java.lang.IllegalArgumentException
Description copied from interface:DescriptorBuilderA 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.- Specified by:
inin interfaceDescriptorBuilder- Parameters:
scope- The class of the scope this descriptor is to have.- Returns:
- A DescriptorBuilder with the given scope
- Throws:
java.lang.IllegalArgumentException- If in is called more than once
-
in
public DescriptorBuilder in(java.lang.String scope) throws java.lang.IllegalArgumentException
Description copied from interface:DescriptorBuilderA 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.- Specified by:
inin interfaceDescriptorBuilder- Parameters:
scope- The fully qualified class name of the scope this predicate is to have.- Returns:
- A DescriptorBuilder with the given scope
- Throws:
java.lang.IllegalArgumentException- If in is called more than once
-
qualifiedBy
public DescriptorBuilder qualifiedBy(java.lang.annotation.Annotation annotation) throws java.lang.IllegalArgumentException
Description copied from interface:DescriptorBuilderA 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)- Specified by:
qualifiedByin interfaceDescriptorBuilder- Parameters:
annotation- The annotation to be associated with this descriptor- Returns:
- A DescriptorBuilder with the given annotation
- Throws:
java.lang.IllegalArgumentException- on failures
-
qualifiedBy
public DescriptorBuilder qualifiedBy(java.lang.String annotation) throws java.lang.IllegalArgumentException
Description copied from interface:DescriptorBuilderA qualifier to be associated with this descriptor object- Specified by:
qualifiedByin interfaceDescriptorBuilder- Parameters:
annotation- The fully qualified class name of an annotation to be associated with this descriptor- Returns:
- A DescriptorBuilder with the given annotation
- Throws:
java.lang.IllegalArgumentException- on failures
-
has
public DescriptorBuilder has(java.lang.String key, java.lang.String value) throws java.lang.IllegalArgumentException
Description copied from interface:DescriptorBuilderAn instance of data to be associated with this descriptor- Specified by:
hasin interfaceDescriptorBuilder- 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:
java.lang.IllegalArgumentException
-
has
public DescriptorBuilder has(java.lang.String key, java.util.List<java.lang.String> values) throws java.lang.IllegalArgumentException
Description copied from interface:DescriptorBuilderAn instance of data to be associated with this descriptor- Specified by:
hasin interfaceDescriptorBuilder- 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:
java.lang.IllegalArgumentException
-
ofRank
public DescriptorBuilder ofRank(int rank)
Description copied from interface:DescriptorBuilderThe rank to be associated with this descriptor. The last rank bound wins- Specified by:
ofRankin interfaceDescriptorBuilder- Parameters:
rank- The rank to be associated with this descriptor.- Returns:
- A DescriptorBuilder with the given rank
-
proxy
public DescriptorBuilder proxy()
Description copied from interface:DescriptorBuilderThis will cause the isProxiable field of the returned descriptor to return true (it will force this descriptor to use proxies).- Specified by:
proxyin interfaceDescriptorBuilder- Returns:
- A DescriptorBuilder with the proxiable field set to true
-
proxy
public DescriptorBuilder proxy(boolean forceProxy)
Description copied from interface:DescriptorBuilderThis will cause the isProxiable field of the returned descriptor to return the given value.- Specified by:
proxyin interfaceDescriptorBuilder- 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
public DescriptorBuilder proxyForSameScope()
Description copied from interface:DescriptorBuilderThis 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).- Specified by:
proxyForSameScopein interfaceDescriptorBuilder- Returns:
- A DescriptorBuilder with the proxyForSameScope field set to true
-
proxyForSameScope
public DescriptorBuilder proxyForSameScope(boolean proxyForSameScope)
Description copied from interface:DescriptorBuilderThis will cause the isProxyForSameScope field of the returned descriptor to return the given value.- Specified by:
proxyForSameScopein interfaceDescriptorBuilder- 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
public DescriptorBuilder localOnly()
Description copied from interface:DescriptorBuilderThis will cause the descriptorVisibility field of the returned descriptor to return LOCAL- Specified by:
localOnlyin interfaceDescriptorBuilder- Returns:
- A DescriptorBuilder with the descriptorVisibility field to be set to LOCAL
-
visibility
public DescriptorBuilder visibility(DescriptorVisibility visibility)
Description copied from interface:DescriptorBuilderThis will set the descriptorVisibility field of the returned descriptor- Specified by:
visibilityin interfaceDescriptorBuilder- Parameters:
visibility- The non-null visibility that this descriptor should take- Returns:
- A DescriptorBuilder with the descriptorVisibility field set to the input value
-
andLoadWith
public DescriptorBuilder andLoadWith(HK2Loader loader) throws java.lang.IllegalArgumentException
Description copied from interface:DescriptorBuilderCall this if this descriptor should be loaded with the given HK2Loader- Specified by:
andLoadWithin interfaceDescriptorBuilder- Parameters:
loader- The loader to use with this descriptor- Returns:
- A DescriptorBuilder with the given HK2Loader
- Throws:
java.lang.IllegalArgumentException- if the HK2Loader is set non-null more than once
-
analyzeWith
public DescriptorBuilder analyzeWith(java.lang.String serviceName)
Description copied from interface:DescriptorBuilderCall this if the descriptor should be analyzed with theClassAnalyzerservice of the given name- Specified by:
analyzeWithin interfaceDescriptorBuilder- Parameters:
serviceName- the name of theClassAnalyzerservice that should be used to analyze this service- Returns:
- A DescriptorBuilder with the given analysis service
-
build
public DescriptorImpl build() throws java.lang.IllegalArgumentException
Description copied from interface:DescriptorBuilderGenerates a descriptor that can be used in binding operations- Specified by:
buildin interfaceDescriptorBuilder- Returns:
- The descriptor that has been built up with this DescriptorBuilder
- Throws:
java.lang.IllegalArgumentException- if the built descriptor is invalid
-
buildFactory
public FactoryDescriptors buildFactory(java.lang.String factoryScope) throws java.lang.IllegalArgumentException
Description copied from interface:DescriptorBuilderGenerates 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- Specified by:
buildFactoryin interfaceDescriptorBuilder- Parameters:
factoryScope- The scope the factory service itself is in.- Returns:
- The descriptor that has been built up with this DescriptorBuilder
- Throws:
java.lang.IllegalArgumentException- if the built descriptor is invalid
-
buildFactory
public FactoryDescriptors buildFactory() throws java.lang.IllegalArgumentException
Description copied from interface:DescriptorBuilderGenerates 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- Specified by:
buildFactoryin interfaceDescriptorBuilder- Returns:
- The descriptor that has been built up with this DescriptorBuilder
- Throws:
java.lang.IllegalArgumentException- if the built descriptor is invalid
-
buildFactory
public FactoryDescriptors buildFactory(java.lang.Class<? extends java.lang.annotation.Annotation> factoryScope) throws java.lang.IllegalArgumentException
Description copied from interface:DescriptorBuilderGenerates 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- Specified by:
buildFactoryin interfaceDescriptorBuilder- 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:
java.lang.IllegalArgumentException- if the built descriptor is invalid
-
-