org.jvnet.hk2.internal
Class SystemDescriptor<T>

java.lang.Object
  extended by org.jvnet.hk2.internal.SystemDescriptor<T>
Type Parameters:
T - The type from the cache
All Implemented Interfaces:
ActiveDescriptor<T>, Descriptor, SingleCache<T>

public class SystemDescriptor<T>
extends Object
implements ActiveDescriptor<T>

Author:
jwells

Method Summary
 T create(ServiceHandle<?> root)
          Creates an instance of the ActiveDescriptor.
 void dispose(T instance)
          Disposes this instance.
 boolean equals(Object o)
           
 Set<String> getAdvertisedContracts()
          Returns the base class name of the contracts that this service describes.
 Descriptor getBaseDescriptor()
          If this descriptor is based on another descriptor (for example via the Configuration bind call) then this method will return the original basis for this descriptor.
 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.
 DescriptorType getDescriptorType()
          Returns CLASS if this is a class descriptor and FACTORY if this is a descriptor describing a factory for a type, in which case the implClass should point to the implementation class of the factory
 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.
 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.
 HK2Loader getLoader()
          This returns the loader that should be used when classloading this descriptor.
 Long getLocatorId()
          This returns the id of the ServiceLocator which this descriptor is registered with.
 Map<String,List<String>> getMetadata()
          Returns all of the metadata associated that this object should be registered with or looked up by
 String getName()
          The name of this descriptor.
 Set<Annotation> getQualifierAnnotations()
          The full set of qualifiers that this ActiveDescriptor provides
 Set<String> getQualifiers()
          Returns all of the annotation classes that this object should be registered with or looked up by
 int getRanking()
          Returns the ranking of this descriptor.
 String getScope()
          Returns the fully qualified class name of the scope annotation that should be associated with this descriptor.
 Class<? extends Annotation> getScopeAnnotation()
          Returns the scope that this ActiveDescriptor belongs to
 Long getServiceId()
          This returns the unique identifier for this descriptor.
 int hashCode()
           
 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
 int setRanking(int ranking)
          Returns the ranking of this descriptor.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

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
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

getAdvertisedContracts

public Set<String> getAdvertisedContracts()
Description copied from interface: Descriptor
Returns the base class name of the contracts that this service describes. If the contract is a paramterized type this will return the raw class. If this service can be looked up by its implementation class then the name of the implementation class must also be found in this list

Specified by:
getAdvertisedContracts in interface Descriptor
Returns:
Will never return null, but may return an empty set. The returned strings are the fully qualified class names of contracts the predicate describes

getScope

public String getScope()
Description copied from interface: Descriptor
Returns the fully qualified class name of the scope annotation that should be associated with this descriptor.

Specified by:
getScope in interface Descriptor
Returns:
If this returns null then this descriptor is assumed to be in the default scope, which is PerLookup

getName

public String getName()
Description copied from interface: Descriptor
The name of this descriptor. Note that if this returns not null then there must also be the Named qualifier in the set of qualifiers with the same value

Specified by:
getName in interface Descriptor
Returns:
The name of this descriptor, or null if there is no name associated with this qualifier

getQualifiers

public Set<String> getQualifiers()
Description copied from interface: Descriptor
Returns all of the annotation classes that this object should be registered with or looked up by

Specified by:
getQualifiers in interface Descriptor
Returns:
Never returns null, but may return an empty set. The set of fully qualified class names that are annotations that this object must have

getDescriptorType

public DescriptorType getDescriptorType()
Description copied from interface: Descriptor
Returns CLASS if this is a class descriptor and FACTORY if this is a descriptor describing a factory for a type, in which case the implClass should point to the implementation class of the factory

Specified by:
getDescriptorType in interface Descriptor
Returns:
Either CLASS or FACTORY

getMetadata

public Map<String,List<String>> getMetadata()
Description copied from interface: Descriptor
Returns all of the metadata associated that this object should be registered with or looked up by

Specified by:
getMetadata in interface Descriptor
Returns:
Never returns null, but may return an empty set. The set of metadata associated with the object. The values in the returned map will never be null, and will always have at least one member

getLoader

public HK2Loader getLoader()
Description copied from interface: Descriptor
This returns the loader that should be used when classloading this descriptor. If this returns null then class will either be loaded with the classloader of the Injectee if there is one, or with the classloader that loaded HK2 itself.

Specified by:
getLoader in interface Descriptor
Returns:
An HK2Loader that can be used to load this descriptor, or null if the default classloading algorithm should be used

getRanking

public int getRanking()
Description copied from interface: Descriptor
Returns the ranking of this descriptor. Rankings with higher value will be considered "better" than rankings of lower value. Descriptors with the same ranking will be returned in the reverse ServiceID order (in other words, the least service ID is considered "better" than any higher service ID).

Specified by:
getRanking in interface Descriptor
Returns:
the ranking that should be associated with this descriptor

setRanking

public int setRanking(int ranking)
Description copied from interface: Descriptor
Returns the ranking of this descriptor. Rankings with higher value will be considered "better" than rankings of lower value. Descriptors with the same ranking will be returned in the reverse ServiceID order (in other words, the least service ID is considered "better" than any higher service ID).

The ranking of a service may change at any time during the life of the descriptor

Specified by:
setRanking in interface Descriptor
Parameters:
ranking - The new ranking this descriptor should have
Returns:
the previous ranking that this descriptor had

getBaseDescriptor

public Descriptor getBaseDescriptor()
Description copied from interface: Descriptor
If this descriptor is based on another descriptor (for example via the Configuration bind call) then this method will return the original basis for this descriptor.

On bind calls the value of this parameter will be ignored, and will be filled in by the system.

Note that even if the values in the returned descriptor are modified it will not affect the values in the parent descriptor (the fields must have been copied out of the base descriptor, not referenced)

Specified by:
getBaseDescriptor in interface Descriptor
Returns:
The original descriptor upon which this descriptor is based, or null if there is no known base descriptor. This field is filled in by the system at bind time

getServiceId

public Long getServiceId()
Description copied from interface: Descriptor
This returns the unique identifier for this descriptor. This field will be ignored upon binding, and will then be assigned by the system. However, this field can be set on search operations, in which case this search will match exactly one Provider in the system.

Specified by:
getServiceId in interface Descriptor
Returns:
The service id for this object. Note that this field may return null if this is an initial bind, as it is not the responsibility of the binder to set this value. If this returns non-null on a bind operation the return value will be ignored

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

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

Specified by:
getImplementationClass in interface ActiveDescriptor<T>
Returns:
The class that directly implements the contract types, or the class that is the factory for an object that implements the contract types

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

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

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

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

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

Specified by:
create in interface ActiveDescriptor<T>
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

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

getLocatorId

public Long getLocatorId()
Description copied from interface: Descriptor
This returns the id of the ServiceLocator which this descriptor is registered with. Returns null if this descriptor is not yet registered with a ServiceLocator

Specified by:
getLocatorId in interface Descriptor
Returns:
The id of the ServiceLocator this Descriptor is registered with, or null if this Descriptor is not registered with a ServiceLocator

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013 Oracle Corporation. All Rights Reserved.