org.glassfish.hk2.utilities
Class BuilderHelper

java.lang.Object
  extended by org.glassfish.hk2.utilities.BuilderHelper

public class BuilderHelper
extends Object

This class is used to generate DescriptorBuilders to be used as a simple mechanism to create a Filter or Descriptor.


Constructor Summary
BuilderHelper()
           
 
Method Summary
static ActiveDescriptorBuilder activeLink(Class<?> implementationClass)
          This method creates an ActiveDescriptorBuilder, whose job it is to create an unreified ActiveDescriptor.
static Filter allFilter()
          Returns a filter of type Descriptor that matches all descriptors
static
<T> AbstractActiveDescriptor<T>
createConstantDescriptor(T constant)
          This creates a descriptor that will always return the given object.
static IndexedFilter createContractFilter(String contract)
          Returns an indexed filter that will return all descriptors that have contract as an advertised contract
static DescriptorImpl createDescriptorFromClass(Class<?> clazz)
          This returns a DescriptorImpl based on the given class.
static IndexedFilter createNameAndContractFilter(String contract, String name)
          Returns an indexed filter that will return all descriptors that have the given name and given contract
static IndexedFilter createNameFilter(String name)
          Returns an indexed filter that will return all descriptors that have the given name
static IndexedFilter createSpecificDescriptorFilter(ActiveDescriptor<?> descriptor)
          This method creates a filter that will match one and only one descriptor.
static DescriptorImpl deepCopyDescriptor(Descriptor copyMe)
          Makes a deep copy of the incoming descriptor
static void getMetadataValues(Annotation annotation, Map<String,List<String>> metadata)
          This is a helper method that gets the metadata values from the Metadata annotations found in an annotation.
static DescriptorBuilder link(Class<?> implementationClass)
          This method links an implementation class with a DescriptorBuilder, to be used to further build the Descriptor.
static DescriptorBuilder link(Class<?> implementationClass, boolean addToContracts)
          This method links an implementation class with a DescriptorBuilder, to be used to further build the Descriptor
static DescriptorBuilder link(String implementationClass)
          This method links an implementation class with a DescriptorBuilder, to be used to further build the Descriptor.
static DescriptorBuilder link(String implementationClass, boolean addToContracts)
          This method links an implementation class with a DescriptorBuilder, to be used to further build the Descriptor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BuilderHelper

public BuilderHelper()
Method Detail

createContractFilter

public static IndexedFilter createContractFilter(String contract)
Returns an indexed filter that will return all descriptors that have contract as an advertised contract

Parameters:
contract - The advertised contract to look for
Returns:
The indexed filter that can be used to calls to ServiceLocator methods

createNameFilter

public static IndexedFilter createNameFilter(String name)
Returns an indexed filter that will return all descriptors that have the given name

Parameters:
name - The name to look for
Returns:
The indexed filter that can be used to calls to ServiceLocator methods

createNameAndContractFilter

public static IndexedFilter createNameAndContractFilter(String contract,
                                                        String name)
Returns an indexed filter that will return all descriptors that have the given name and given contract

Parameters:
contract - The advertised contract to look for
name - The name to look for
Returns:
The indexed filter that can be used to calls to ServiceLocator methods

createSpecificDescriptorFilter

public static IndexedFilter createSpecificDescriptorFilter(ActiveDescriptor<?> descriptor)
This method creates a filter that will match one and only one descriptor. The passed in descriptor must have both its serviceID and locatorId filled in, or else this method will throw an IllegalArgumentException

Parameters:
descriptor - The descriptor from which to create a filter
Returns:
A filter to use that will match this descriptor exactly

allFilter

public static Filter allFilter()
Returns a filter of type Descriptor that matches all descriptors

Returns:
A filter that matches all descriptors

link

public static DescriptorBuilder link(String implementationClass,
                                     boolean addToContracts)
                              throws IllegalArgumentException
This method links an implementation class with a DescriptorBuilder, to be used to further build the Descriptor.

Parameters:
implementationClass - The fully qualified name of the implementation class to be associated with the DescriptorBuilder.
addToContracts - if true, this implementation class will be added to the list of contracts
Returns:
A DescriptorBuilder that can be used to further build up the Descriptor
Throws:
IllegalArgumentException - if implementationClass is null

link

public static DescriptorBuilder link(String implementationClass)
                              throws IllegalArgumentException
This method links an implementation class with a DescriptorBuilder, to be used to further build the Descriptor. This method will automatically put the implementationClass into the list of advertised contracts.

Parameters:
implementationClass - The fully qualified name of the implementation class to be associated with the PredicateBuilder.
Returns:
A DescriptorBuilder that can be used to further build up the Descriptor
Throws:
IllegalArgumentException - if implementationClass is null

link

public static DescriptorBuilder link(Class<?> implementationClass,
                                     boolean addToContracts)
                              throws IllegalArgumentException
This method links an implementation class with a DescriptorBuilder, to be used to further build the Descriptor

Parameters:
implementationClass - The implementation class to be associated with the DescriptorBuilder.
addToContracts - true if this impl class should be automatically added to the list of contracts
Returns:
A DescriptorBuilder that can be used to further build up the Descriptor
Throws:
IllegalArgumentException - if implementationClass is null

link

public static DescriptorBuilder link(Class<?> implementationClass)
                              throws IllegalArgumentException
This method links an implementation class with a DescriptorBuilder, to be used to further build the Descriptor.

Parameters:
implementationClass - The implementation class to be associated with the DescriptorBuilder.
Returns:
A DescriptorBuilder that can be used to further build up the Descriptor
Throws:
IllegalArgumentException - if implementationClass is null

activeLink

public static ActiveDescriptorBuilder activeLink(Class<?> implementationClass)
                                          throws IllegalArgumentException
This method creates an ActiveDescriptorBuilder, whose job it is to create an unreified ActiveDescriptor. The implementation class given will NOT automatically be added to the set of contracts of the ActiveDescriptor.

Parameters:
implementationClass - The implementation class to be associated with the ActiveDescriptorBuilder.
Returns:
A ActiveDescriptorBuilder that can be used to further build up the Descriptor
Throws:
IllegalArgumentException - if implementationClass is null

createConstantDescriptor

public static <T> AbstractActiveDescriptor<T> createConstantDescriptor(T constant)
This creates a descriptor that will always return the given object. The set of types in the advertised contracts will contain the class of the constant along with:

Parameters:
constant - The non-null constant that should always be returned from the create method of this ActiveDescriptor.
Returns:
The descriptor returned can be used in calls to DynamicConfiguration.addActiveDescriptor
Throws:
IllegalArgumentException - if constant is null

createDescriptorFromClass

public static DescriptorImpl createDescriptorFromClass(Class<?> clazz)
This returns a DescriptorImpl based on the given class. The returned descriptor will include the class itself as an advertised contract and all implemented interfaces that are marked @Contract

Parameters:
clazz - The class to analyze
Returns:
The DescriptorImpl corresponding to this class

deepCopyDescriptor

public static DescriptorImpl deepCopyDescriptor(Descriptor copyMe)
Makes a deep copy of the incoming descriptor

Parameters:
copyMe - The descriptor to copy
Returns:
A new descriptor with all fields copied

getMetadataValues

public static void getMetadataValues(Annotation annotation,
                                     Map<String,List<String>> metadata)
This is a helper method that gets the metadata values from the Metadata annotations found in an annotation.

Parameters:
annotation - The annotation to find Metadata values from. May not be null.
metadata - A non-null metadata map. The values found in the annotation will be added to this metadata map
Throws:
IllegalArgumentException - if annotation or metadata is null
MultiException - if there was an error invoking the methods of the annotation


Copyright © 2013 Oracle Corporation. All Rights Reserved.