Package org.glassfish.hk2.api
Interface Descriptor
- All Known Subinterfaces:
ActiveDescriptor<T>
- All Known Implementing Classes:
AbstractActiveDescriptor
,ActiveDescriptorBuilderImpl.BuiltActiveDescriptor
,AliasDescriptor
,AutoActiveDescriptor
,ConstantActiveDescriptor
,ConstantActiveDescriptor
,CrossOverDescriptor
,DelegatingNamedActiveDescriptor
,DescriptorImpl
,OperationDescriptor
,SystemDescriptor
public interface Descriptor
A Descriptor is a bean-like structure that describes a service
declaration in HK2. A descriptor is comprised only of basic
objects such as String or boolean (e.g., not Class or Annotation}.
A described service does not need to be classloaded in order to
have a Descriptor. However, this does imply that a Descriptor will
have some loss of information when compared to a classloaded service,
which is described with an
ActiveDescriptor
. For example, a
Descriptor can know that a service has a qualifier named Foo, but
will not know (without the use of Metadata
) what values
Foo contains.
Services have a number of optional attributes such as name and scope. A service is required to minimally have a type name representing the concrete (i.e., byType) definition.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionReturns the base class name of the contracts that this service describes.Returns the name of theClassAnalyzer
service that should be used to discover the constructors, initialization methods, field and postConstruct and preDestory methods.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 factoryReturns the visibility of this descriptor.Returns the fully qualified class name of the implementation class.This returns the loader that should be used when classloading this descriptor.This returns the id of the ServiceLocator which this descriptor is registered with.Returns all of the metadata associated that this object should be registered with or looked up bygetName()
The name of this descriptor.Returns all of the annotation classes that this object should be registered with or looked up byint
Returns the ranking of this descriptor.getScope()
Returns the fully qualified class name of the scope annotation that should be associated with this descriptor.This returns the unique identifier for this descriptor.If this returns true then the system will create a proxy for instances of this descriptor.This value determines whether or not this service should be proxied when being injected into other services of the same scope.int
setRanking
(int ranking) Returns the ranking of this descriptor.
-
Method Details
-
getImplementation
String getImplementation()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.- 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
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- 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
String getScope()Returns the fully qualified class name of the scope annotation that should be associated with this descriptor.- Returns:
- If this returns null then this descriptor is assumed to be in the default scope, which is PerLookup
-
getName
String getName()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- Returns:
- The name of this descriptor, or null if there is no name associated with this qualifier
-
getQualifiers
Returns all of the annotation classes that this object should be registered with or looked up by- 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
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- Returns:
- Either CLASS or PROVIDE_METHOD
-
getDescriptorVisibility
DescriptorVisibility getDescriptorVisibility()Returns the visibility of this descriptor.If the visibility is NORMAL then this descriptor may be seen by all children locators of the locator in which this descriptor is bound
If the visibility is LOCAL then this descriptor may only be seen by the servcie locator in which it is bound, and in none of the children of that locator
- Returns:
- Either NORMAL or LOCAL
-
getMetadata
Returns all of the metadata associated that this object should be registered with or looked up by- 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
HK2Loader getLoader()This returns the loader that should be used when classloading this descriptor. If this method returns null then the class will be loaded with the classloader of the Injectee if there is one, or with the classloader that loaded HK2 itself; failing that the context class loader on the thread will be tried.- Returns:
- An HK2Loader that can be used to load this descriptor, or null if the default classloading algorithm should be used
-
getRanking
int getRanking()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).- Returns:
- the ranking that should be associated with this descriptor
-
setRanking
int setRanking(int ranking) 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
- Parameters:
ranking
- The new ranking this descriptor should have- Returns:
- the previous ranking that this descriptor had
-
isProxiable
Boolean isProxiable()If this returns true then the system will create a proxy for instances of this descriptor. As with all proxies, the proxy created will also implement theProxyCtl
interfaceIt is an error for this method to return true if the scope that this descriptor is in is
Unproxiable
(such as PerLookup).- Returns:
- true if this descriptor must be proxied, false if this
descriptor must NOT be proxied (even if it is in an Unproxiable scope)
and null if this descriptor should take its proxiable status from
the scope it is in (i.e., it will only be proxied if the scope is
marked
Proxiable
)
-
isProxyForSameScope
Boolean isProxyForSameScope()This value determines whether or not this service should be proxied when being injected into other services of the same scope. If a scope is proxiable then it will have a default setting for whether or not its services should be proxied when being injected into the same scope. If this method returns null then the default setting for the scope will be used. Otherwise the value returned will determine whether or not this service will be proxied when being injected into a service of the same scope.- Returns:
- null if this descriptor should use the default ProxyForSameScope value for the scope. If it returns true then this service will be proxied even when being injected into the same scope. If it returns false then this service will NOT be proxied when being injected into the same scope (i.e., it cannot be used for lazy initialization of the service when injected into the same scope)
-
getClassAnalysisName
String getClassAnalysisName()Returns the name of theClassAnalyzer
service that should be used to discover the constructors, initialization methods, field and postConstruct and preDestory methods. If null the default implementation will be used. Will be ignored for descriptors that are not automatically analyzed by hk2- Returns:
- the possibly null name of the ClassAnalysis service that should be used to analyze the class represented by this descriptor. If null then the HK2 default analysis will be performed
-
getServiceId
Long getServiceId()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.- 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
-
getLocatorId
Long getLocatorId()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- Returns:
- The id of the ServiceLocator this Descriptor is registered with, or null if this Descriptor is not registered with a ServiceLocator
-