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

java.lang.Object
  extended by org.glassfish.hk2.utilities.DescriptorImpl
      extended by org.glassfish.hk2.utilities.AbstractActiveDescriptor<T>
          extended by org.glassfish.hk2.utilities.AliasDescriptor<T>
All Implemented Interfaces:
Serializable, ActiveDescriptor<T>, Descriptor, SingleCache<T>

public class AliasDescriptor<T>
extends AbstractActiveDescriptor<T>

A descriptor class that serves as an alias for another descriptor.

Author:
tbeerbower
See Also:
Serialized Form

Constructor Summary
AliasDescriptor(ServiceLocator locator, ActiveDescriptor<T> descriptor, String contract, String name)
          Construct an AliasDescriptor.
 
Method Summary
 T create(ServiceHandle<?> root)
          Creates an instance of the ActiveDescriptor.
 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.
 ActiveDescriptor<T> getDescriptor()
          Get the descriptor being aliased.
 String getImplementation()
          Returns the fully qualified class name of the implementation class.
 Class<?> getImplementationClass()
          The implementation class that should be used to generate new instances of this descriptor.
 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
 void setCache(T cacheMe)
          Sets the value into the cache
 
Methods inherited from class org.glassfish.hk2.utilities.AbstractActiveDescriptor
addContractType, addQualifierAnnotation, getFactoryLocatorId, getFactoryServiceId, removeContractType, removeQualifierAnnotation, setFactoryId, setReified
 
Methods inherited from class org.glassfish.hk2.utilities.DescriptorImpl
addAdvertisedContract, addMetadata, addQualifier, equals, getAdvertisedContracts, getBaseDescriptor, getDescriptorType, 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.Descriptor
getAdvertisedContracts, getBaseDescriptor, getDescriptorType, getLoader, getLocatorId, getMetadata, getName, getQualifiers, getRanking, getScope, getServiceId, setRanking
 

Constructor Detail

AliasDescriptor

public AliasDescriptor(ServiceLocator locator,
                       ActiveDescriptor<T> descriptor,
                       String contract,
                       String name)
Construct an AliasDescriptor.

Parameters:
locator - the service locator
descriptor - the descriptor to be aliased
contract - the contact
name - the name
Method Detail

getImplementationClass

public Class<?> getImplementationClass()
Description copied from interface: ActiveDescriptor
The implementation class that should be used to generate new instances of this descriptor.

If the class returned is a Factory, then the factory is used to create instances. In this case the system will get an instance of the factory and use it to create the instances

Returns:
The class that directly implements the contract types, or the class that is the factory for an object that implements the contract types

create

public T create(ServiceHandle<?> root)
Description copied from interface: ActiveDescriptor
Creates an instance of the ActiveDescriptor. All of the Injectee's must be created prior to instantiation, and associated with the ExtendedProvider so that they can be destroyed properly

Parameters:
root - The root service handle, which can be used to associated all the PerLookup objects with this creation
Returns:
An instance of this ActiveDescriptor

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>
Overrides:
getCache in class AbstractActiveDescriptor<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>
Overrides:
isCacheSet in class AbstractActiveDescriptor<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>
Overrides:
setCache in class AbstractActiveDescriptor<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>
Overrides:
releaseCache in class AbstractActiveDescriptor<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>
Overrides:
isReified in class AbstractActiveDescriptor<T>
Returns:
true if this descriptor has been reified, false otherwise

getImplementation

public String getImplementation()
Description copied from interface: Descriptor
Returns the fully qualified class name of the implementation class. If this is a factory descriptor then this will return the fully qualified name of the class implementing the factory interface.

Specified by:
getImplementation in interface Descriptor
Overrides:
getImplementation in class DescriptorImpl
Returns:
Might return null in some cases, but will usually return the fully qualified class name of the implementation class or of the factory class for this descriptor

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>
Overrides:
getContractTypes in class AbstractActiveDescriptor<T>
Returns:
the set of types this ActiveDescriptor must implement or extend

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>
Overrides:
getScopeAnnotation in class AbstractActiveDescriptor<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>
Overrides:
getQualifierAnnotations in class AbstractActiveDescriptor<T>
Returns:
The set of annotations that this ActiveDescriptor provides

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>
Overrides:
getInjectees in class AbstractActiveDescriptor<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>
Overrides:
dispose in class AbstractActiveDescriptor<T>
Parameters:
instance - The instance to destroy

getDescriptor

public ActiveDescriptor<T> getDescriptor()
Get the descriptor being aliased.

Returns:
the descriptor


Copyright © 2013 Oracle Corporation. All Rights Reserved.