Package org.glassfish.hk2.utilities
Class DescriptorImpl
java.lang.Object
org.glassfish.hk2.utilities.DescriptorImpl
- All Implemented Interfaces:
Externalizable
,Serializable
,Descriptor
- Direct Known Subclasses:
AbstractActiveDescriptor
The implementation of the descriptor itself, with the
bonus of being externalizable, and having writeable fields
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
private String
private static final String
private DescriptorType
private DescriptorVisibility
private static final String
private static final char
private Long
private String
private HK2Loader
private static final String
private Long
private static final String
private String
private static final String
private static final String
private static final char
private static final String
private Boolean
private static final String
private static final String
private Boolean
private static final String
private int
private static final String
private String
private static final String
private static final long
For serializationprivate static final String
private static final char
private static final String
private static final String
private static final String
-
Constructor Summary
ConstructorsConstructorDescriptionFor serializationDescriptorImpl
(Set<String> contracts, String name, String scope, String implementation, Map<String, List<String>> metadatas, Set<String> qualifiers, DescriptorType descriptorType, DescriptorVisibility descriptorVisibility, HK2Loader loader, int rank, Boolean proxiable, Boolean proxyForSameScope, String analysisName, Long id, Long locatorId) This creates this descriptor impl, taking all of the fields as givenDescriptorImpl
(Descriptor copyMe) Does a deep copy of the incoming descriptor -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAdvertisedContract
(String addMe) Adds an advertised contract to the set of contracts advertised by this descriptorvoid
addMetadata
(String key, String value) Adds a value to the list of values associated with this keyvoid
addMetadata
(Map<String, List<String>> metadata) Adds all of the entries from this map to the existing descriptor's metadata.void
addQualifier
(String addMe) Adds the given string to the list of qualifiersvoid
Removes all metadata valuesstatic boolean
Tests if two descriptors are equal not taking into account the locator-id and server-id by comparing the following fields: implementation contracts name scope qualifiers descriptorType descriptorVisibility metadata proxiable proxyForSameScope analysisNameprivate static <T> boolean
private static <T> boolean
equalOrderedCollection
(Collection<T> a, Collection<T> b) boolean
This equals matches only if the following fields of the descriptor match: implementation contracts name scope qualifiers descriptorType descriptorVisibility metadata proxiable proxyForSameScope analysisNameReturns 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.int
hashCode()
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.static void
pretty
(StringBuffer sb, Descriptor d) Will pretty print a descriptorvoid
boolean
This can be used to read in instances of this object that were previously written out with writeObject.private void
boolean
removeAdvertisedContract
(String removeMe) Removes an advertised contract from the set of contracts advertised by this descriptorboolean
removeAllMetadata
(String key) Removes all the metadata values associated with keyboolean
removeMetadata
(String key, String value) Removes the given value from the given keyboolean
removeQualifier
(String removeMe) Removes the given qualifier from the list of qualifiersvoid
setClassAnalysisName
(String name) Sets the name of the service that will be used to analyze this classvoid
setDescriptorType
(DescriptorType descriptorType) Sets the descriptor typevoid
setDescriptorVisibility
(DescriptorVisibility descriptorVisibility) Sets the descriptor visilibityvoid
setImplementation
(String implementation) Sets the implementationvoid
Sets the loader to use with this descriptorvoid
setLocatorId
(Long locatorId) Sets the locator id for this descriptorvoid
setMetadata
(Map<String, List<String>> metadata) Sets the metadata of this DescriptorImpl to exactly the set of metadata in the incoming map.void
Sets the name this descriptor should havevoid
setProxiable
(Boolean proxiable) Sets whether or not this descriptor should be proxiedvoid
setProxyForSameScope
(Boolean proxyForSameScope) Sets whether or not to proxy this descriptor for other services in the same scopeint
setRanking
(int ranking) Returns the ranking of this descriptor.void
Sets the scope this descriptor should havevoid
setServiceId
(Long id) Sets the service id for this descriptortoString()
void
void
writeObject
(PrintWriter out) This writes this object to the data output stream in a human-readable format, excellent for writing out data files
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor serialization- See Also:
-
CONTRACT_KEY
- See Also:
-
NAME_KEY
- See Also:
-
SCOPE_KEY
- See Also:
-
QUALIFIER_KEY
- See Also:
-
TYPE_KEY
- See Also:
-
VISIBILITY_KEY
- See Also:
-
METADATA_KEY
- See Also:
-
RANKING_KEY
- See Also:
-
PROXIABLE_KEY
- See Also:
-
PROXY_FOR_SAME_SCOPE_KEY
- See Also:
-
ANALYSIS_KEY
- See Also:
-
PROVIDE_METHOD_DT
- See Also:
-
LOCAL_DT
- See Also:
-
START_START
- See Also:
-
END_START
- See Also:
-
END_START_CHAR
private static final char END_START_CHAR- See Also:
-
SINGLETON_DIRECTIVE
- See Also:
-
NOT_IN_CONTRACTS_DIRECTIVE
- See Also:
-
SINGLETON_DIRECTIVE_CHAR
private static final char SINGLETON_DIRECTIVE_CHAR- See Also:
-
NOT_IN_CONTRACTS_DIRECTIVE_CHAR
private static final char NOT_IN_CONTRACTS_DIRECTIVE_CHAR- See Also:
-
EMPTY_CONTRACTS_SET
-
EMPTY_QUALIFIER_SET
-
EMPTY_METADATAS_MAP
-
contracts
-
implementation
-
name
-
scope
-
metadatas
-
qualifiers
-
descriptorType
-
descriptorVisibility
-
loader
-
rank
private int rank -
proxiable
-
proxyForSameScope
-
analysisName
-
id
-
locatorId
-
-
Constructor Details
-
DescriptorImpl
public DescriptorImpl()For serialization -
DescriptorImpl
Does a deep copy of the incoming descriptor- Parameters:
copyMe
- The descriptor to copy
-
DescriptorImpl
public DescriptorImpl(Set<String> contracts, String name, String scope, String implementation, Map<String, List<String>> metadatas, Set<String> qualifiers, DescriptorType descriptorType, DescriptorVisibility descriptorVisibility, HK2Loader loader, int rank, Boolean proxiable, Boolean proxyForSameScope, String analysisName, Long id, Long locatorId) This creates this descriptor impl, taking all of the fields as given- Parameters:
contracts
- The set of contracts this descriptor impl should advertise (should not be null)name
- The name of this descriptor (may be null)scope
- The scope of this descriptor. If null PerLookup is assumedimplementation
- The name of the implementation class (should not be null)metadatas
- The metadata associated with this descriptor (should not be null)qualifiers
- The set of qualifiers associated with this descriptor (should not be null)descriptorType
- The type of this descriptor (should not be null)descriptorVisibility
- The visibility this descriptor should haveloader
- The HK2Loader to associated with this descriptor (may be null)rank
- The rank to initially associate with this descriptorproxiable
- The proxiable value to associate with this descriptor (may be null)proxyForSameScope
- The proxyForSameScope value to associate with this descriptor (may be null)analysisName
- The name of the ClassAnalysis service to useid
- The ID this descriptor should take (may be null)locatorId
- The locator ID this descriptor should take (may be null)
-
-
Method Details
-
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 interfaceDescriptor
- 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
-
addAdvertisedContract
Adds an advertised contract to the set of contracts advertised by this descriptor- Parameters:
addMe
- The contract to add. May not be null
-
removeAdvertisedContract
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
-
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 interfaceDescriptor
- 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
-
setImplementation
Sets the implementation- Parameters:
implementation
- The implementation this descriptor should have
-
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 interfaceDescriptor
- Returns:
- If this returns null then this descriptor is assumed to be in the default scope, which is PerLookup
-
setScope
Sets the scope this descriptor should have- Parameters:
scope
- The scope of this descriptor
-
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 interfaceDescriptor
- Returns:
- The name of this descriptor, or null if there is no name associated with this qualifier
-
setName
Sets the name this descriptor should have- Parameters:
name
- The name for this descriptor
-
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 interfaceDescriptor
- 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
-
addQualifier
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
-
removeQualifier
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
-
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 interfaceDescriptor
- Returns:
- Either CLASS or PROVIDE_METHOD
-
setDescriptorType
Sets the descriptor type- Parameters:
descriptorType
- The descriptor type. May not be null
-
getDescriptorVisibility
Description copied from interface:Descriptor
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
- Specified by:
getDescriptorVisibility
in interfaceDescriptor
- Returns:
- Either NORMAL or LOCAL
-
setDescriptorVisibility
Sets the descriptor visilibity- Parameters:
descriptorVisibility
- The visibility this descriptor should have
-
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 interfaceDescriptor
- 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
-
setMetadata
Sets the metadata of this DescriptorImpl to exactly the set of metadata in the incoming map. Any previous metadata values will be removed. A deep copy of the incoming map will be made, so it is safe to use the input map after use of this API- Parameters:
metadata
- The non-null metadata that this descriptor should have
-
addMetadata
Adds all of the entries from this map to the existing descriptor's metadata. None of the keys in the map may have the '=' character- Parameters:
metadata
- The non-null but possibly empty list of fields to add to the metadata map
-
addMetadata
Adds a value to the list of values associated with this key- Parameters:
key
- The key to which to add the value. May not be null. May not contain the character '='value
- The value to add. May not be null
-
removeMetadata
Removes the given value from the given key- Parameters:
key
- The key of the value to remove. May not be null, and may not contain the character '='value
- The value to remove. May not be null- Returns:
- true if the value was removed
-
removeAllMetadata
Removes all the metadata values associated with key- Parameters:
key
- The key of the metadata values to remove- Returns:
- true if any value was removed
-
clearMetadata
public void clearMetadata()Removes all metadata values -
getLoader
Description copied from interface:Descriptor
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.- Specified by:
getLoader
in interfaceDescriptor
- Returns:
- An HK2Loader that can be used to load this descriptor, or null if the default classloading algorithm should be used
-
setLoader
Sets the loader to use with this descriptor- Parameters:
loader
- The loader to use with this descriptor
-
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 interfaceDescriptor
- 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 interfaceDescriptor
- Parameters:
ranking
- The new ranking this descriptor should have- Returns:
- the previous ranking that this descriptor had
-
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 interfaceDescriptor
- 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
-
setServiceId
Sets the service id for this descriptor- Parameters:
id
- the service id for this descriptor
-
isProxiable
Description copied from interface:Descriptor
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).- Specified by:
isProxiable
in interfaceDescriptor
- 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
)
-
setProxiable
Sets whether or not this descriptor should be proxied- Parameters:
proxiable
- if true then this descriptor will be proxied. If false then this descriptor will not be proxied. If null this descriptor will follow the rules of the scope it is in
-
isProxyForSameScope
Description copied from interface:Descriptor
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.- Specified by:
isProxyForSameScope
in interfaceDescriptor
- 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)
-
setProxyForSameScope
Sets whether or not to proxy this descriptor for other services in the same scope- Parameters:
proxyForSameScope
- if true then this descriptor will be proxied for services in the same scope. If false then this descriptor will not be proxied for services in the same scope. If null this descriptor will follow the rules of the scope it is in
-
getClassAnalysisName
Description copied from interface:Descriptor
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- Specified by:
getClassAnalysisName
in interfaceDescriptor
- 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
-
setClassAnalysisName
Sets the name of the service that will be used to analyze this class- Parameters:
name
- The name of theClassAnalyzer
service that should be used to analyze this descriptor
-
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 interfaceDescriptor
- Returns:
- The id of the ServiceLocator this Descriptor is registered with, or null if this Descriptor is not registered with a ServiceLocator
-
setLocatorId
Sets the locator id for this descriptor- Parameters:
locatorId
- the locator id for this descriptor
-
hashCode
public int hashCode() -
equalOrderedCollection
-
equalMetadata
-
descriptorEquals
Tests if two descriptors are equal not taking into account the locator-id and server-id by comparing the following fields:- implementation
- contracts
- name
- scope
- qualifiers
- descriptorType
- descriptorVisibility
- metadata
- proxiable
- proxyForSameScope
- analysisName
- Parameters:
a
- The possibly null descriptor to compareb
- The possibly null descriptor to compare- Returns:
- true if they are the same, false otherwise
-
equals
This equals matches only if the following fields of the descriptor match:- implementation
- contracts
- name
- scope
- qualifiers
- descriptorType
- descriptorVisibility
- metadata
- proxiable
- proxyForSameScope
- analysisName
-
pretty
Will pretty print a descriptor- Parameters:
sb
- The string buffer put the pretty print intod
- The descriptor to write
-
toString
-
writeObject
This writes this object to the data output stream in a human-readable format, excellent for writing out data files- Parameters:
out
- The output stream to write this object out to- Throws:
IOException
- on failure
-
reinitialize
private void reinitialize() -
readObject
This can be used to read in instances of this object that were previously written out with writeObject. Useful for reading from external data files- Parameters:
in
- The reader to read from- Returns:
- true if a descriptor was read, false otherwise. This is useful if reading a file that might have comments at the end
- Throws:
IOException
- on failure
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-