org.apache.commons.discovery.tools
Class SPInterface<T>

java.lang.Object
  extended by org.apache.commons.discovery.tools.SPInterface<T>
Type Parameters:
T - The SPI type

public class SPInterface<T>
extends Object

Represents a Service Programming Interface (spi). - SPI's name - SPI's (provider) class - SPI's (alternate) override property name In addition, while there are many cases where this is NOT usefull, for those in which it is: - expected constructor argument types and parameters values.


Constructor Summary
SPInterface(Class<T> provider)
          Construct object representing Class provider.
SPInterface(Class<T> provider, Class<?>[] constructorParamClasses, Object[] constructorParams)
          Construct object representing Class provider.
SPInterface(Class<T> spi, String propertyName)
          Construct object representing Class provider.
SPInterface(Class<T> spi, String propertyName, Class<?>[] constructorParamClasses, Object[] constructorParams)
          Construct object representing Class provider.
 
Method Summary
 String getPropertyName()
          Returns the property name to be used for finding the name of the SPI implementation class.
 Class<T> getSPClass()
          Returns the SPI class.
 String getSPName()
          Returns the SPI class name.
<S extends T>
S
newInstance(Class<S> impl)
          Creates a new instance of the given SPI class.
static
<T> SPInterface<T>
newSPInterface(Class<T> provider)
          Construct object representing Class provider.
static
<T> SPInterface<T>
newSPInterface(Class<T> provider, Class<?>[] constructorParamClasses, Object[] constructorParams)
          Construct object representing Class provider.
static
<T> SPInterface<T>
newSPInterface(Class<T> provider, String propertyName)
          Construct object representing Class provider.
static
<T> SPInterface<T>
newSPInterface(Class<T> provider, String propertyName, Class<?>[] constructorParamClasses, Object[] constructorParams)
          Construct object representing Class provider.
<S extends T>
void
verifyAncestory(Class<S> impl)
          Verifies the given SPI implementation is a SPI specialization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SPInterface

public SPInterface(Class<T> provider)
Construct object representing Class provider.

Parameters:
provider - The SPI class

SPInterface

public SPInterface(Class<T> spi,
                   String propertyName)
Construct object representing Class provider.

Parameters:
spi - The SPI class
propertyName - when looking for the name of a class implementing the provider class, a discovery strategy may involve looking for (system or other) properties having either the name of the class (provider) or the propertyName.

SPInterface

public SPInterface(Class<T> provider,
                   Class<?>[] constructorParamClasses,
                   Object[] constructorParams)
Construct object representing Class provider.

Parameters:
provider - The SPI class
constructorParamClasses - classes representing the constructor argument types.
constructorParams - objects representing the constructor arguments.

SPInterface

public SPInterface(Class<T> spi,
                   String propertyName,
                   Class<?>[] constructorParamClasses,
                   Object[] constructorParams)
Construct object representing Class provider.

Parameters:
spi - The SPI class
propertyName - when looking for the name of a class implementing the provider class, a discovery strategy may involve looking for (system or other) properties having either the name of the class (provider) or the propertyName.
constructorParamClasses - classes representing the constructor argument types.
constructorParams - objects representing the constructor arguments.
Method Detail

newSPInterface

public static <T> SPInterface<T> newSPInterface(Class<T> provider)
Construct object representing Class provider.

Type Parameters:
T - The SPI type
Parameters:
provider - The SPI class
Returns:
A new object representing Class provider
Since:
0.5

newSPInterface

public static <T> SPInterface<T> newSPInterface(Class<T> provider,
                                                String propertyName)
Construct object representing Class provider.

Type Parameters:
T - The SPI type
Parameters:
provider - The SPI class
propertyName - when looking for the name of a class implementing the provider class, a discovery strategy may involve looking for (system or other) properties having either the name of the class (provider) or the propertyName.
Returns:
A new object representing Class provider
Since:
0.5

newSPInterface

public static <T> SPInterface<T> newSPInterface(Class<T> provider,
                                                Class<?>[] constructorParamClasses,
                                                Object[] constructorParams)
Construct object representing Class provider.

Type Parameters:
T - The SPI type
Parameters:
provider - The SPI class
constructorParamClasses - classes representing the constructor argument types
constructorParams - objects representing the constructor arguments
Returns:
A new object representing Class provider
Since:
0.5

newSPInterface

public static <T> SPInterface<T> newSPInterface(Class<T> provider,
                                                String propertyName,
                                                Class<?>[] constructorParamClasses,
                                                Object[] constructorParams)
Construct object representing Class provider.

Type Parameters:
T - The SPI type
Parameters:
provider - The SPI class
propertyName - when looking for the name of a class implementing the provider class, a discovery strategy may involve looking for (system or other) properties having either the name of the class (provider) or the propertyName.
constructorParamClasses - classes representing the constructor argument types
constructorParams - objects representing the constructor arguments
Returns:
A new object representing Class provider
Since:
0.5

getSPName

public String getSPName()
Returns the SPI class name.

Returns:
The SPI class name

getSPClass

public Class<T> getSPClass()
Returns the SPI class.

Returns:
The SPI class

getPropertyName

public String getPropertyName()
Returns the property name to be used for finding the name of the SPI implementation class.

Returns:
The property name to be used for finding the name of the SPI implementation class

newInstance

public <S extends T> S newInstance(Class<S> impl)
                        throws DiscoveryException,
                               InstantiationException,
                               IllegalAccessException,
                               NoSuchMethodException,
                               InvocationTargetException
Creates a new instance of the given SPI class.

Type Parameters:
S - Any type extends T
Parameters:
impl - The SPI class has to be instantiated
Returns:
A new instance of the given SPI class
Throws:
DiscoveryException - if the class implementing the SPI cannot be found, cannot be loaded and instantiated, or if the resulting class does not implement (or extend) the SPI
InstantiationException - see Class.newInstance()
IllegalAccessException - see Class.newInstance()
NoSuchMethodException - see Class.newInstance()
InvocationTargetException - see Class.newInstance()

verifyAncestory

public <S extends T> void verifyAncestory(Class<S> impl)
Verifies the given SPI implementation is a SPI specialization.

Type Parameters:
S - Any type extends T
Parameters:
impl - The SPI instantance


Copyright © 2002-2011 The Apache Software Foundation. All Rights Reserved.