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

public abstract Class AbstractActiveDescriptor<T>

extends DescriptorImpl
implements ActiveDescriptor<T>
Class Inheritance
All Implemented Interfaces
org.glassfish.hk2.api.ActiveDescriptor, org.glassfish.hk2.api.SingleCache, org.glassfish.hk2.api.Descriptor
Known Direct Subclasses
org.glassfish.hk2.utilities.AliasDescriptor, org.glassfish.hk2.internal.ActiveDescriptorBuilderImpl.BuiltActiveDescriptor, org.glassfish.hk2.internal.ConstantActiveDescriptor
Type Parameters
<T>
The type returned from the cache
Imports
java.lang.annotation.Annotation, java.lang.reflect.Type, java.util.Collections, .LinkedHashSet, .List, .Map, .Set, java.util.concurrent.locks.Lock, .ReentrantReadWriteLock, jakarta.inject.Named, org.glassfish.hk2.api.ActiveDescriptor, .Descriptor, .DescriptorType, .DescriptorVisibility, .Injectee, org.glassfish.hk2.utilities.reflection.ReflectionHelper

This class can be used as a starting point for those writing their own ActiveDescriptor. It also has some helper methods to deal with metadata and adding and removing contracts and qualifiers, which can be helpful when customizing the implementation
Author
jwells

Field Summary

Modifier and TypeField and Description
private Set<Type>
private transient T
private transient boolean
private static final Set<Annotation>
private Long
private Long
private boolean
private Set<Annotation>
private final Lock
private final ReentrantReadWriteLock
private Class<? extends Annotation>
private Annotation
private static final long
private final Lock

Constructor Summary

AccessConstructor and Description
public
AbstractActiveDescriptor()

For serialization

protected
AbstractActiveDescriptor(Descriptor
The non-null base descriptor to copy values from
baseDescriptor
)

Creates a NON reified ActiveDescriptor based on a copy of the given baseDescriptor.

protected
AbstractActiveDescriptor(Set<Type>
The contracts that should be advertised by this descriptor (may not be null, but may be empty)
advertisedContracts
,
Class<? extends Annotation>
The scope of this descriptor (may not be null)
scope
,
String
The name of this descriptor (may be null)
name
,
Set<Annotation>
The qualifiers of this descriptor (may not be null, but may be empty)
qualifiers
,
DescriptorType descriptorType, DescriptorVisibility descriptorVisibility, int
The ranking for this descriptor
ranking
,
Boolean
whether the descriptor should be proxied
proxy
,
Boolean
whether or not to proxy this descriptor for other services in the same scope
proxyForSameScope
,
String
the name of the service used to analyze this class
analyzerName
,
Map<String, List<String>>
Metadata to add to this descriptor
metadata
)

This constructor must be called with the information about this descriptor

Method Summary

Modifier and TypeMethod and Description
public void
addContractType(Type
The contract to add. May not be null
addMe
)

Adds an advertised contract to the set of contracts advertised by this descriptor

public void
addQualifierAnnotation(Annotation
The fully qualified class name of the qualifier to add. May not be null
addMe
)

Adds the given string to the list of qualifiers

public void
dispose(T instance)

Implements org.glassfish.hk2.api.ActiveDescriptor.dispose.

Disposes this instance.

public boolean
equals(Object o)

Overrides org.glassfish.hk2.utilities.DescriptorImpl.equals.

This equals matches only if the following fields of the descriptor match:

  • implementation
  • contracts
  • name
  • scope
  • qualifiers
  • descriptorType
  • descriptorVisibility
  • metadata
  • proxiable
  • proxyForSameScope
  • analysisName
public T
getCache()

Implements org.glassfish.hk2.api.SingleCache.getCache.

This can be used for scopes that will only every be created once.

public Set<Type>
getContractTypes()

Implements org.glassfish.hk2.api.ActiveDescriptor.getContractTypes.

The set of types that this ActiveDescriptor must produce.

public Long
getFactoryLocatorId()

Implements org.glassfish.hk2.api.ActiveDescriptor.getFactoryLocatorId.

If this ActiveDescriptor has DescriptorType of PROVIDE_METHOD then this field will return the ServiceId of its associated Factory service.

public Long
getFactoryServiceId()

Implements org.glassfish.hk2.api.ActiveDescriptor.getFactoryServiceId.

If this ActiveDescriptor has DescriptorType of PROVIDE_METHOD then this field will return the ServiceId of its associated Factory service.

public List<Injectee>
getInjectees()

Implements org.glassfish.hk2.api.ActiveDescriptor.getInjectees.

Returns the full list of Injectees this class has.

public Set<Annotation>
getQualifierAnnotations()

Implements org.glassfish.hk2.api.ActiveDescriptor.getQualifierAnnotations.

The full set of qualifiers that this ActiveDescriptor provides

public Class<? extends Annotation>
getScopeAnnotation()

Implements org.glassfish.hk2.api.ActiveDescriptor.getScopeAnnotation.

Returns the scope that this ActiveDescriptor belongs to

public Annotation
getScopeAsAnnotation()

Implements org.glassfish.hk2.api.ActiveDescriptor.getScopeAsAnnotation.

Returns the scope as an Annotation implementation that this ActiveDescriptor belongs to

public int
hashCode()

Overrides org.glassfish.hk2.utilities.DescriptorImpl.hashCode.

Returns a hash code value for this object.

public boolean
isCacheSet()

Implements org.glassfish.hk2.api.SingleCache.isCacheSet.

Returns true if this cache has been set

public boolean
isReified()

Implements org.glassfish.hk2.api.ActiveDescriptor.isReified.

This method returns true if this descriptor has been reified (class loaded).

public void
releaseCache()

Implements org.glassfish.hk2.api.SingleCache.releaseCache.

Removes the cached value and makes it such that this cache has not been set

public boolean

Returns:

true if removeMe was removed from the set
removeContractType
(Type
The contract to remove. May not be null
removeMe
)

Removes an advertised contract from the set of contracts advertised by this descriptor

private void
public boolean

Returns:

true if the given qualifier was removed
removeQualifierAnnotation
(Annotation
The fully qualifier class name of the qualifier to remove. May not be null
removeMe
)

Removes the given qualifier from the list of qualifiers

public void
setCache(T cacheMe)

Implements org.glassfish.hk2.api.SingleCache.setCache.

Sets the value into the cache

public void
setFactoryId(Long
The locatorId of the factory associated with this method
locatorId
,
Long
The serviceId of the factory associated with this method
serviceId
)

Sets the locator and serviceId for the factory.

public void
public void
setName(String name)

Overrides org.glassfish.hk2.utilities.DescriptorImpl.setName.

Sets the name of this descriptor.

public void
setReified(boolean
true if this descriptor should appear reified, false otherwise
reified
)

This method is called to change the state of the reification of this descriptor

public void
setScopeAnnotation(Class<? extends Annotation>
The non-null scope annotation for this service
scopeAnnotation
)

Sets the scope annotation for this descriptor

public void
setScopeAsAnnotation(Annotation
The scope as an Annotation. May not be null
scopeAnnotation
)

Sets the scope as an Annotation implementation.

Inherited from org.glassfish.hk2.utilities.DescriptorImpl:
addAdvertisedContractaddMetadataaddMetadataaddQualifierclearMetadatadescriptorEqualsgetAdvertisedContractsgetClassAnalysisNamegetDescriptorTypegetDescriptorVisibilitygetImplementationgetLoadergetLocatorIdgetMetadatagetNamegetQualifiersgetRankinggetScopegetServiceIdisProxiableisProxyForSameScopeprettyreadExternalreadObjectremoveAdvertisedContractremoveAllMetadataremoveMetadataremoveQualifiersetClassAnalysisNamesetDescriptorTypesetDescriptorVisibilitysetImplementationsetLoadersetLocatorIdsetMetadatasetProxiablesetProxyForSameScopesetRankingsetScopesetServiceIdtoStringwriteExternalwriteObject

Field Detail

advertisedContractsback to summary
private Set<Type> advertisedContracts
cachedValueback to summary
private transient T cachedValue
cacheSetback to summary
private transient boolean cacheSet
EMPTY_QUALIFIER_SETback to summary
private static final Set<Annotation> EMPTY_QUALIFIER_SET

Hides org.glassfish.hk2.utilities.DescriptorImpl.EMPTY_QUALIFIER_SET.

factoryLocatorIdback to summary
private Long factoryLocatorId
factoryServiceIdback to summary
private Long factoryServiceId
isReifiedback to summary
private boolean isReified
qualifiersback to summary
private Set<Annotation> qualifiers

Hides org.glassfish.hk2.utilities.DescriptorImpl.qualifiers.

rLockback to summary
private final Lock rLock
rwLockback to summary
private final ReentrantReadWriteLock rwLock
scopeback to summary
private Class<? extends Annotation> scope

Hides org.glassfish.hk2.utilities.DescriptorImpl.scope.

scopeAnnotationback to summary
private Annotation scopeAnnotation
serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.glassfish.hk2.utilities.DescriptorImpl.serialVersionUID.

For serialization

wLockback to summary
private final Lock wLock

Constructor Detail

AbstractActiveDescriptorback to summary
public AbstractActiveDescriptor()

For serialization

AbstractActiveDescriptorback to summary
protected AbstractActiveDescriptor(Descriptor baseDescriptor)

Creates a NON reified ActiveDescriptor based on a copy of the given baseDescriptor. The values from the baseDescriptor will be copied deeply

Parameters
baseDescriptor:Descriptor

The non-null base descriptor to copy values from

AbstractActiveDescriptorback to summary
protected AbstractActiveDescriptor(Set<Type> advertisedContracts, Class<? extends Annotation> scope, String name, Set<Annotation> qualifiers, DescriptorType descriptorType, DescriptorVisibility descriptorVisibility, int ranking, Boolean proxy, Boolean proxyForSameScope, String analyzerName, Map<String, List<String>> metadata)

This constructor must be called with the information about this descriptor

Parameters
advertisedContracts:Set<Type>

The contracts that should be advertised by this descriptor (may not be null, but may be empty)

scope:Class<? extends Annotation>

The scope of this descriptor (may not be null)

name:String

The name of this descriptor (may be null)

qualifiers:Set<Annotation>

The qualifiers of this descriptor (may not be null, but may be empty)

ranking:int

The ranking for this descriptor

proxy:Boolean

whether the descriptor should be proxied

proxyForSameScope:Boolean

whether or not to proxy this descriptor for other services in the same scope

analyzerName:String

the name of the service used to analyze this class

metadata:Map<String, List<String>>

Metadata to add to this descriptor

Method Detail

addContractTypeback to summary
public void addContractType(Type addMe)

Adds an advertised contract to the set of contracts advertised by this descriptor

Parameters
addMe:Type

The contract to add. May not be null

addQualifierAnnotationback to summary
public void addQualifierAnnotation(Annotation addMe)

Adds the given string to the list of qualifiers

Parameters
addMe:Annotation

The fully qualified class name of the qualifier to add. May not be null

disposeback to summary
public void dispose(T instance)

Implements org.glassfish.hk2.api.ActiveDescriptor.dispose.

Doc from org.glassfish.hk2.api.ActiveDescriptor.dispose.

Disposes this instance. All the PerLookup objects that were created for this instance will be destroyed after this object has been destroyed

Annotations
@Override
equalsback to summary
public boolean equals(Object o)

Overrides org.glassfish.hk2.utilities.DescriptorImpl.equals.

Doc from org.glassfish.hk2.utilities.DescriptorImpl.equals.

This equals matches only if the following fields of the descriptor match:

  • implementation
  • contracts
  • name
  • scope
  • qualifiers
  • descriptorType
  • descriptorVisibility
  • metadata
  • proxiable
  • proxyForSameScope
  • analysisName
Annotations
@Override
getCacheback to summary
public T getCache()

Implements org.glassfish.hk2.api.SingleCache.getCache.

Doc from org.glassfish.hk2.api.SingleCache.getCache.

This can be used for scopes that will only every be created once. The returned value must have been set previously with setCache. If this is called when isCacheSet is false will result in a RuntimeException

Annotations
@Override
getContractTypesback to summary
public Set<Type> getContractTypes()

Implements org.glassfish.hk2.api.ActiveDescriptor.getContractTypes.

Doc from org.glassfish.hk2.api.ActiveDescriptor.getContractTypes.

The set of types that this ActiveDescriptor must produce. These types may be Classes or ParameterizedTypes, and may be no other subclass of Type

Annotations
@Override
getFactoryLocatorIdback to summary
public Long getFactoryLocatorId()

Implements org.glassfish.hk2.api.ActiveDescriptor.getFactoryLocatorId.

Doc from org.glassfish.hk2.api.ActiveDescriptor.getFactoryLocatorId.

If this ActiveDescriptor has DescriptorType of PROVIDE_METHOD then this field will return the ServiceId of its associated Factory service. Otherwise this method should return null

Annotations
@Override
getFactoryServiceIdback to summary
public Long getFactoryServiceId()

Implements org.glassfish.hk2.api.ActiveDescriptor.getFactoryServiceId.

Doc from org.glassfish.hk2.api.ActiveDescriptor.getFactoryServiceId.

If this ActiveDescriptor has DescriptorType of PROVIDE_METHOD then this field will return the ServiceId of its associated Factory service. Otherwise this method should return null

Annotations
@Override
getInjecteesback to summary
public List<Injectee> getInjectees()

Implements org.glassfish.hk2.api.ActiveDescriptor.getInjectees.

Doc from org.glassfish.hk2.api.ActiveDescriptor.getInjectees.

Returns the full list of Injectees this class has. These references will be resolved prior to the class being constructed, even if these injectees are field or method injectees.

If this descriptor is describing a factory created type then this list must have zero length

Annotations
@Override
getQualifierAnnotationsback to summary
public Set<Annotation> getQualifierAnnotations()

Implements org.glassfish.hk2.api.ActiveDescriptor.getQualifierAnnotations.

Doc from org.glassfish.hk2.api.ActiveDescriptor.getQualifierAnnotations.

The full set of qualifiers that this ActiveDescriptor provides

Annotations
@Override
getScopeAnnotationback to summary
public Class<? extends Annotation> getScopeAnnotation()

Implements org.glassfish.hk2.api.ActiveDescriptor.getScopeAnnotation.

Doc from org.glassfish.hk2.api.ActiveDescriptor.getScopeAnnotation.

Returns the scope that this ActiveDescriptor belongs to

Annotations
@Override
getScopeAsAnnotationback to summary
public Annotation getScopeAsAnnotation()

Implements org.glassfish.hk2.api.ActiveDescriptor.getScopeAsAnnotation.

Doc from org.glassfish.hk2.api.ActiveDescriptor.getScopeAsAnnotation.

Returns the scope as an Annotation implementation that this ActiveDescriptor belongs to

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides org.glassfish.hk2.utilities.DescriptorImpl.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
isCacheSetback to summary
public boolean isCacheSet()

Implements org.glassfish.hk2.api.SingleCache.isCacheSet.

Doc from org.glassfish.hk2.api.SingleCache.isCacheSet.

Returns true if this cache has been set

Annotations
@Override
isReifiedback to summary
public boolean isReified()

Implements org.glassfish.hk2.api.ActiveDescriptor.isReified.

Doc from org.glassfish.hk2.api.ActiveDescriptor.isReified.

This method returns true if this descriptor has been reified (class loaded). If this method returns false then the other methods in this interface will throw an IllegalStateException. Once this method returns true it may be

Annotations
@Override
releaseCacheback to summary
public void releaseCache()

Implements org.glassfish.hk2.api.SingleCache.releaseCache.

Doc from org.glassfish.hk2.api.SingleCache.releaseCache.

Removes the cached value and makes it such that this cache has not been set

Annotations
@Override
removeContractTypeback to summary
public boolean removeContractType(Type removeMe)

Removes an advertised contract from the set of contracts advertised by this descriptor

Parameters
removeMe:Type

The contract to remove. May not be null

Returns:boolean

true if removeMe was removed from the set

removeNamedQualifierback to summary
private void removeNamedQualifier()
removeQualifierAnnotationback to summary
public boolean removeQualifierAnnotation(Annotation removeMe)

Removes the given qualifier from the list of qualifiers

Parameters
removeMe:Annotation

The fully qualifier class name of the qualifier to remove. May not be null

Returns:boolean

true if the given qualifier was removed

setCacheback to summary
public void setCache(T cacheMe)

Implements org.glassfish.hk2.api.SingleCache.setCache.

Doc from org.glassfish.hk2.api.SingleCache.setCache.

Sets the value into the cache

Annotations
@Override
setFactoryIdback to summary
public void setFactoryId(Long locatorId, Long serviceId)

Sets the locator and serviceId for the factory. This descriptor must be of type PROVIDE_METHOD

Parameters
locatorId:Long

The locatorId of the factory associated with this method

serviceId:Long

The serviceId of the factory associated with this method

setImplementationTypeback to summary
public void setImplementationType(Type t)
setNameback to summary
public void setName(String name)

Overrides org.glassfish.hk2.utilities.DescriptorImpl.setName.

Sets the name of this descriptor. Will remove any existing Named qualifier and add a Named qualifier for this name

Annotations
@Override
setReifiedback to summary
public void setReified(boolean reified)

This method is called to change the state of the reification of this descriptor

Parameters
reified:boolean

true if this descriptor should appear reified, false otherwise

setScopeAnnotationback to summary
public void setScopeAnnotation(Class<? extends Annotation> scopeAnnotation)

Sets the scope annotation for this descriptor

Parameters
scopeAnnotation:Class<? extends Annotation>

The non-null scope annotation for this service

setScopeAsAnnotationback to summary
public void setScopeAsAnnotation(Annotation scopeAnnotation)

Sets the scope as an Annotation implementation. This method will also modify the scope as a Class and the underlying scope as a String

Parameters
scopeAnnotation:Annotation

The scope as an Annotation. May not be null