org.glassfish.hk2.utilities
Class AbstractActiveDescriptor<T>

java.lang.Object
  extended by org.glassfish.hk2.utilities.DescriptorImpl
      extended by org.glassfish.hk2.utilities.AbstractActiveDescriptor<T>
Type Parameters:
T - The type returned from the cache
All Implemented Interfaces:
Serializable, ActiveDescriptor<T>, Descriptor, SingleCache<T>
Direct Known Subclasses:
AliasDescriptor, AutoActiveDescriptor, ConstantActiveDescriptor, ConstantActiveDescriptor, DomDescriptor

public abstract class AbstractActiveDescriptor<T>
extends DescriptorImpl
implements ActiveDescriptor<T>, Serializable

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
See Also:
Serialized Form

Constructor Summary
  AbstractActiveDescriptor()
          For serialization
protected AbstractActiveDescriptor(Set<Type> advertisedContracts, Class<? extends Annotation> scope, String name, Set<Annotation> qualifiers, DescriptorType descriptorType, int ranking, Map<String,List<String>> metadata)
          This constructor must be called with the information about this descriptor
 
Method Summary
 void addContractType(Type addMe)
          Adds an advertised contract to the set of contracts advertised by this descriptor
 void addQualifierAnnotation(Annotation addMe)
          Adds the given string to the list of qualifiers
 void dispose(T instance)
          Disposes this instance.
 T getCache()
          This can be used for scopes that will only every be created once.
 Set<Type> getContractTypes()
          The set of types that this ActiveDescriptor must produce.
 Long getFactoryLocatorId()
          If this ActiveDescriptor has DescriptorType of PROVIDE_METHOD then this field will return the ServiceId of its associated Factory service.
 Long getFactoryServiceId()
          If this ActiveDescriptor has DescriptorType of PROVIDE_METHOD then this field will return the ServiceId of its associated Factory service.
 List<Injectee> getInjectees()
          Returns the full list of Injectees this class has.
 Set<Annotation> getQualifierAnnotations()
          The full set of qualifiers that this ActiveDescriptor provides
 Class<? extends Annotation> getScopeAnnotation()
          Returns the scope that this ActiveDescriptor belongs to
 boolean isCacheSet()
          Returns true if this cache has been set
 boolean isReified()
          This method returns true if this descriptor has been reified (class loaded).
 void releaseCache()
          Removes the cached value and makes it such that this cache has not been set
 boolean removeContractType(Type removeMe)
          Removes an advertised contract from the set of contracts advertised by this descriptor
 boolean removeQualifierAnnotation(Annotation removeMe)
          Removes the given qualifier from the list of qualifiers
 void setCache(T cacheMe)
          Sets the value into the cache
 void setFactoryId(Long locatorId, Long serviceId)
           
 void setReified(boolean reified)
          This method is called to change the state of the reification of this descriptor
 
Methods inherited from class org.glassfish.hk2.utilities.DescriptorImpl
addAdvertisedContract, addMetadata, addQualifier, equals, getAdvertisedContracts, getBaseDescriptor, getDescriptorType, getImplementation, getLoader, getLocatorId, getMetadata, getName, getQualifiers, getRanking, getScope, getServiceId, hashCode, pretty, readObject, removeAdvertisedContract, removeAllMetadata, removeMetadata, removeQualifier, setBaseDescriptor, setDescriptorType, setImplementation, setLoader, setLocatorId, setName, setRanking, setScope, setServiceId, toString, writeObject
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.glassfish.hk2.api.ActiveDescriptor
create, getImplementationClass
 
Methods inherited from interface org.glassfish.hk2.api.Descriptor
getAdvertisedContracts, getBaseDescriptor, getDescriptorType, getImplementation, getLoader, getLocatorId, getMetadata, getName, getQualifiers, getRanking, getScope, getServiceId, setRanking
 

Constructor Detail

AbstractActiveDescriptor

public AbstractActiveDescriptor()
For serialization


AbstractActiveDescriptor

protected AbstractActiveDescriptor(Set<Type> advertisedContracts,
                                   Class<? extends Annotation> scope,
                                   String name,
                                   Set<Annotation> qualifiers,
                                   DescriptorType descriptorType,
                                   int ranking,
                                   Map<String,List<String>> metadata)
This constructor must be called with the information about this descriptor

Parameters:
advertisedContracts - The contracts that should be advertised by this descriptor (may not be null, but may be empty)
scope - The scope of this descriptor (may not be null)
name - The name of this descriptor (may be null)
qualifiers - The qualifiers of this descriptor (may not be null, but may be empty)
ranking - The ranking for this descriptor
locatorId - The id of the locator for this descriptor
metadata - Metadata to add to this descriptor
Method Detail

getCache

public T getCache()
Description copied from interface: SingleCache
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

Specified by:
getCache in interface SingleCache<T>
Returns:
A value cached with this ActiveDescriptor

isCacheSet

public boolean isCacheSet()
Description copied from interface: SingleCache
Returns true if this cache has been set

Specified by:
isCacheSet in interface SingleCache<T>
Returns:
true if there is a currently cached value, false otherwise

setCache

public void setCache(T cacheMe)
Description copied from interface: SingleCache
Sets the value into the cache

Specified by:
setCache in interface SingleCache<T>
Parameters:
cacheMe - A single value that can be cached in this active descriptor

releaseCache

public void releaseCache()
Description copied from interface: SingleCache
Removes the cached value and makes it such that this cache has not been set

Specified by:
releaseCache in interface SingleCache<T>

isReified

public boolean isReified()
Description copied from interface: ActiveDescriptor
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

Specified by:
isReified in interface ActiveDescriptor<T>
Returns:
true if this descriptor has been reified, false otherwise

setReified

public void setReified(boolean reified)
This method is called to change the state of the reification of this descriptor

Parameters:
reified - true if this descriptor should appear reified, false otherwise

getContractTypes

public Set<Type> getContractTypes()
Description copied from interface: ActiveDescriptor
The set of types that this ActiveDescriptor must produce. These types may be Classes or ParameterizedTypes, and may be no other subclass of Type

Specified by:
getContractTypes in interface ActiveDescriptor<T>
Returns:
the set of types this ActiveDescriptor must implement or extend

addContractType

public void addContractType(Type addMe)
Adds an advertised contract to the set of contracts advertised by this descriptor

Parameters:
addMe - The contract to add. May not be null

removeContractType

public boolean removeContractType(Type removeMe)
Removes an advertised contract from the set of contracts advertised by this descriptor

Parameters:
removeMe - The contract to remove. May not be null
Returns:
true if removeMe was removed from the set

getScopeAnnotation

public Class<? extends Annotation> getScopeAnnotation()
Description copied from interface: ActiveDescriptor
Returns the scope that this ActiveDescriptor belongs to

Specified by:
getScopeAnnotation in interface ActiveDescriptor<T>
Returns:
The scope of this ActiveDescriptor

getQualifierAnnotations

public Set<Annotation> getQualifierAnnotations()
Description copied from interface: ActiveDescriptor
The full set of qualifiers that this ActiveDescriptor provides

Specified by:
getQualifierAnnotations in interface ActiveDescriptor<T>
Returns:
The set of annotations that this ActiveDescriptor provides

addQualifierAnnotation

public void addQualifierAnnotation(Annotation addMe)
Adds the given string to the list of qualifiers

Parameters:
addMe - The fully qualified class name of the qualifier to add. May not be null

removeQualifierAnnotation

public boolean removeQualifierAnnotation(Annotation removeMe)
Removes the given qualifier from the list of qualifiers

Parameters:
removeMe - The fully qualifier class name of the qualifier to remove. May not be null
Returns:
true if the given qualifier was removed

getFactoryServiceId

public Long getFactoryServiceId()
Description copied from interface: ActiveDescriptor
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

Specified by:
getFactoryServiceId in interface ActiveDescriptor<T>
Returns:
The service ID of the associated factory service

getFactoryLocatorId

public Long getFactoryLocatorId()
Description copied from interface: ActiveDescriptor
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

Specified by:
getFactoryLocatorId in interface ActiveDescriptor<T>
Returns:
The locator ID of the associated factory service

setFactoryId

public void setFactoryId(Long locatorId,
                         Long serviceId)

getInjectees

public List<Injectee> getInjectees()
Description copied from interface: ActiveDescriptor
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

Specified by:
getInjectees in interface ActiveDescriptor<T>
Returns:
Will not return null, but may return an empty list. The set of Injectees that must be resolved before this ActiveDescriptor can be constructed

dispose

public void dispose(T instance)
Description copied from interface: ActiveDescriptor
Disposes this instance. All the PerLookup objects that were created for this instance will be destroyed after this object has been destroyed

Specified by:
dispose in interface ActiveDescriptor<T>
Parameters:
instance - The instance to destroy


Copyright © 2013 Oracle Corporation. All Rights Reserved.