org.glassfish.hk2.utilities
Class DescriptorImpl

java.lang.Object
  extended by org.glassfish.hk2.utilities.DescriptorImpl
All Implemented Interfaces:
Serializable, Descriptor
Direct Known Subclasses:
AbstractActiveDescriptor, AbstractInhabitantImpl

public class DescriptorImpl
extends Object
implements Descriptor, Serializable

The implementation of the descriptor itself, with the bonus of being externalizable, and having writeable fields

Author:
jwells
See Also:
Serialized Form

Constructor Summary
DescriptorImpl()
          For serialization
DescriptorImpl(Descriptor copyMe)
          Does a deep copy of the incoming descriptor
DescriptorImpl(Set<String> contracts, String name, String scope, String implementation, Map<String,List<String>> metadatas, Set<String> qualifiers, DescriptorType descriptorType, HK2Loader loader, int rank, Descriptor baseDescriptor, Long id, Long locatorId)
          This creates this descriptor impl, taking all of the fields as given
 
Method Summary
 void addAdvertisedContract(String addMe)
          Adds an advertised contract to the set of contracts advertised by this descriptor
 void addMetadata(String key, String value)
          Adds a value to the list of values associated with this key
 void addQualifier(String addMe)
          Adds the given string to the list of qualifiers
 boolean equals(Object a)
           
 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.
 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
 String getImplementation()
          Returns the fully qualified class name of the implementation class.
 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<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.
 Long getServiceId()
          This returns the unique identifier for this descriptor.
 int hashCode()
           
static void pretty(StringBuffer sb, Descriptor d)
          Will pretty print a descriptor
 boolean readObject(BufferedReader in)
          This can be used to read in instances of this object that were previously written out with writeObject.
 boolean removeAdvertisedContract(String removeMe)
          Removes an advertised contract from the set of contracts advertised by this descriptor
 boolean removeAllMetadata(String key)
          Removes all the metadata values associated with key
 boolean removeMetadata(String key, String value)
          Removes the given value from the given key
 boolean removeQualifier(String removeMe)
          Removes the given qualifier from the list of qualifiers
 void setBaseDescriptor(Descriptor baseDescriptor)
          Sets the base descriptor to be associated with this descriptor
 void setDescriptorType(DescriptorType descriptorType)
          Sets the descriptor type
 void setImplementation(String implementation)
          Sets the implementation
 void setLoader(HK2Loader loader)
          Sets the loader to use with this descriptor
 void setLocatorId(Long locatorId)
          Sets the locator id for this descriptor
 void setName(String name)
          Sets the name this descriptor should have
 int setRanking(int ranking)
          Returns the ranking of this descriptor.
 void setScope(String scope)
          Sets the scope this descriptor should have
 void setServiceId(Long id)
          Sets the service id for this descriptor
 String toString()
           
 void writeObject(PrintWriter out)
          This writes this object to the data output stream in a human-readable format, excellent for writing out data files
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DescriptorImpl

public DescriptorImpl()
For serialization


DescriptorImpl

public DescriptorImpl(Descriptor copyMe)
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,
                      HK2Loader loader,
                      int rank,
                      Descriptor baseDescriptor,
                      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 assumed
implementation - 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)
loader - The HK2Loader to associated with this descriptor (may be null)
rank - The rank to initially associate with this descriptor
baseDescriptor - The base descriptor to associated with this descriptor
id - The ID this descriptor should take (may be null)
locatorId - The locator ID this descriptor should take (may be null)
Method Detail

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

addAdvertisedContract

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

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

removeAdvertisedContract

public boolean removeAdvertisedContract(String 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

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

setImplementation

public void setImplementation(String implementation)
Sets the implementation

Parameters:
implementation - The implementation this descriptor should have

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

setScope

public void setScope(String scope)
Sets the scope this descriptor should have

Parameters:
scope - The scope of this descriptor

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

setName

public void setName(String name)
Sets the name this descriptor should have

Parameters:
name - The name for this descriptor

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

addQualifier

public void addQualifier(String 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

removeQualifier

public boolean removeQualifier(String 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

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

setDescriptorType

public void setDescriptorType(DescriptorType descriptorType)
Sets the descriptor type

Parameters:
descriptorType - The descriptor type. May not be null

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

addMetadata

public void addMetadata(String key,
                        String value)
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
value - The value to add. May not be null

removeMetadata

public boolean removeMetadata(String key,
                              String value)
Removes the given value from the given key

Parameters:
key - The key of the value to remove. May not be null
value - The value to remove. May not be null
Returns:
true if the value was removed

removeAllMetadata

public boolean removeAllMetadata(String key)
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

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

setLoader

public void setLoader(HK2Loader loader)
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 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

setBaseDescriptor

public void setBaseDescriptor(Descriptor baseDescriptor)
Sets the base descriptor to be associated with this descriptor

Parameters:
baseDescriptor - The base descriptor to be associated with this descriptor

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

setServiceId

public void setServiceId(Long id)
Sets the service id for this descriptor

Parameters:
id - the service id for this descriptor

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

setLocatorId

public void setLocatorId(Long locatorId)
Sets the locator id for this descriptor

Parameters:
locatorId - the locator id for this descriptor

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

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

pretty

public static void pretty(StringBuffer sb,
                          Descriptor d)
Will pretty print a descriptor

Parameters:
sb - The string buffer put the pretty print into
d - The descriptor to write

toString

public String toString()
Overrides:
toString in class Object

writeObject

public void writeObject(PrintWriter out)
                 throws IOException
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

readObject

public boolean readObject(BufferedReader in)
                   throws IOException
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


Copyright © 2013 Oracle Corporation. All Rights Reserved.