Class SPInterface<T>
- java.lang.Object
-
- org.apache.commons.discovery.tools.SPInterface<T>
-
- Type Parameters:
T
- The SPI type
public class SPInterface<T> extends java.lang.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
Constructors Constructor Description SPInterface(java.lang.Class<T> provider)
Construct object representing Classprovider
.SPInterface(java.lang.Class<T> provider, java.lang.Class<?>[] constructorParamClasses, java.lang.Object[] constructorParams)
Construct object representing Classprovider
.SPInterface(java.lang.Class<T> spi, java.lang.String propertyName)
Construct object representing Classprovider
.SPInterface(java.lang.Class<T> spi, java.lang.String propertyName, java.lang.Class<?>[] constructorParamClasses, java.lang.Object[] constructorParams)
Construct object representing Classprovider
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getPropertyName()
Returns the property name to be used for finding the name of the SPI implementation class.java.lang.Class<T>
getSPClass()
Returns the SPI class.java.lang.String
getSPName()
Returns the SPI class name.<S extends T>
SnewInstance(java.lang.Class<S> impl)
Creates a new instance of the given SPI class.static <T> SPInterface<T>
newSPInterface(java.lang.Class<T> provider)
Construct object representing Classprovider
.static <T> SPInterface<T>
newSPInterface(java.lang.Class<T> provider, java.lang.Class<?>[] constructorParamClasses, java.lang.Object[] constructorParams)
Construct object representing Classprovider
.static <T> SPInterface<T>
newSPInterface(java.lang.Class<T> provider, java.lang.String propertyName)
Construct object representing Classprovider
.static <T> SPInterface<T>
newSPInterface(java.lang.Class<T> provider, java.lang.String propertyName, java.lang.Class<?>[] constructorParamClasses, java.lang.Object[] constructorParams)
Construct object representing Classprovider
.<S extends T>
voidverifyAncestory(java.lang.Class<S> impl)
Verifies the given SPI implementation is a SPI specialization.
-
-
-
Constructor Detail
-
SPInterface
public SPInterface(java.lang.Class<T> provider)
Construct object representing Classprovider
.- Parameters:
provider
- The SPI class
-
SPInterface
public SPInterface(java.lang.Class<T> spi, java.lang.String propertyName)
Construct object representing Classprovider
.- Parameters:
spi
- The SPI classpropertyName
- 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 thepropertyName
.
-
SPInterface
public SPInterface(java.lang.Class<T> provider, java.lang.Class<?>[] constructorParamClasses, java.lang.Object[] constructorParams)
Construct object representing Classprovider
.- Parameters:
provider
- The SPI classconstructorParamClasses
- classes representing the constructor argument types.constructorParams
- objects representing the constructor arguments.
-
SPInterface
public SPInterface(java.lang.Class<T> spi, java.lang.String propertyName, java.lang.Class<?>[] constructorParamClasses, java.lang.Object[] constructorParams)
Construct object representing Classprovider
.- Parameters:
spi
- The SPI classpropertyName
- 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 thepropertyName
.constructorParamClasses
- classes representing the constructor argument types.constructorParams
- objects representing the constructor arguments.
-
-
Method Detail
-
newSPInterface
public static <T> SPInterface<T> newSPInterface(java.lang.Class<T> provider)
Construct object representing Classprovider
.- 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(java.lang.Class<T> provider, java.lang.String propertyName)
Construct object representing Classprovider
.- Type Parameters:
T
- The SPI type- Parameters:
provider
- The SPI classpropertyName
- 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 thepropertyName
.- Returns:
- A new object representing Class
provider
- Since:
- 0.5
-
newSPInterface
public static <T> SPInterface<T> newSPInterface(java.lang.Class<T> provider, java.lang.Class<?>[] constructorParamClasses, java.lang.Object[] constructorParams)
Construct object representing Classprovider
.- Type Parameters:
T
- The SPI type- Parameters:
provider
- The SPI classconstructorParamClasses
- classes representing the constructor argument typesconstructorParams
- objects representing the constructor arguments- Returns:
- A new object representing Class
provider
- Since:
- 0.5
-
newSPInterface
public static <T> SPInterface<T> newSPInterface(java.lang.Class<T> provider, java.lang.String propertyName, java.lang.Class<?>[] constructorParamClasses, java.lang.Object[] constructorParams)
Construct object representing Classprovider
.- Type Parameters:
T
- The SPI type- Parameters:
provider
- The SPI classpropertyName
- 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 thepropertyName
.constructorParamClasses
- classes representing the constructor argument typesconstructorParams
- objects representing the constructor arguments- Returns:
- A new object representing Class
provider
- Since:
- 0.5
-
getSPName
public java.lang.String getSPName()
Returns the SPI class name.- Returns:
- The SPI class name
-
getSPClass
public java.lang.Class<T> getSPClass()
Returns the SPI class.- Returns:
- The SPI class
-
getPropertyName
public java.lang.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(java.lang.Class<S> impl) throws DiscoveryException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.NoSuchMethodException, java.lang.reflect.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 SPIjava.lang.InstantiationException
- seeClass.newInstance()
java.lang.IllegalAccessException
- seeClass.newInstance()
java.lang.NoSuchMethodException
- seeClass.newInstance()
java.lang.reflect.InvocationTargetException
- seeClass.newInstance()
-
verifyAncestory
public <S extends T> void verifyAncestory(java.lang.Class<S> impl)
Verifies the given SPI implementation is a SPI specialization.- Type Parameters:
S
- Any type extends T- Parameters:
impl
- The SPI instantance
-
-