Package com.bc.ceres.core
Class SingleTypeExtensionFactory<T,E>
- java.lang.Object
-
- com.bc.ceres.core.SingleTypeExtensionFactory<T,E>
-
- All Implemented Interfaces:
ExtensionFactory
public class SingleTypeExtensionFactory<T,E> extends Object implements ExtensionFactory
An implementation of aExtensionFactory
for a single extension type.- Since:
- Ceres 0.9
- Version:
- $Revision$ $Date$
-
-
Constructor Summary
Constructors Constructor Description SingleTypeExtensionFactory(Class<E> extensionType)
Constructs aSingleTypeExtensionFactory
for extensions of the given type.SingleTypeExtensionFactory(Class<E> extensionType, Class<? extends E> extensionSubType)
Constructs aSingleTypeExtensionFactory
for extensions of the given sub-type which implement the given type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description E
getExtension(Object object, Class<?> extensionType)
Gets an instance of an extension type for the specified object of type T.protected E
getExtensionImpl(T object, Class<E> extensionType)
Creates an extension object for the givenobject
.Class<? extends E>
getExtensionSubType()
Class<E>
getExtensionType()
Class<?>[]
getExtensionTypes()
-
-
-
Constructor Detail
-
SingleTypeExtensionFactory
public SingleTypeExtensionFactory(Class<E> extensionType)
Constructs aSingleTypeExtensionFactory
for extensions of the given type. TheextensionSubType
will be the same as the given type.- Parameters:
extensionType
- The extension type.
-
SingleTypeExtensionFactory
public SingleTypeExtensionFactory(Class<E> extensionType, Class<? extends E> extensionSubType)
Constructs aSingleTypeExtensionFactory
for extensions of the given sub-type which implement the given type.- Parameters:
extensionType
- The extension type. Must beassignable from
extensionSubType
.extensionSubType
- The specific extension sub-type.
-
-
Method Detail
-
getExtensionSubType
public final Class<? extends E> getExtensionSubType()
- Returns:
- The specific extension sub-type.
-
getExtension
public final E getExtension(Object object, Class<?> extensionType)
Gets an instance of an extension type for the specified object of type T. If this factory'sextensionType
is assignable from the givenextensionType
, the method callsgetExtensionImpl(Object, Class)
. Otherwisenull
is returned.- Specified by:
getExtension
in interfaceExtensionFactory
- Parameters:
object
- The object to be extended.extensionType
- The type of the requested extension.- Returns:
- The extension object, or
null
if the given object is not extensible by this factory or if an error occurs during the call togetExtensionImpl(Object, Class)
.
-
getExtensionImpl
protected E getExtensionImpl(T object, Class<E> extensionType) throws Throwable
Creates an extension object for the givenobject
. The new extension object must be an instance of theextensionSubType
passed to the constructor. Called if, and only if this factory'sextensionType
is assignable from the givenextensionType
.The default implementation returns a new instance of
extensionSubType
, either created from its public no-arg constructor or its public 1-arg constructor which can take the givenobject
. Clients may subclass and override this method in order to implement a more sophisticated instance creation.- Parameters:
object
- The object to be extended.extensionType
- The type of the requested extension.- Returns:
- The extension object.
- Throws:
Throwable
- If an error occurs.
-
getExtensionTypes
public final Class<?>[] getExtensionTypes()
- Specified by:
getExtensionTypes
in interfaceExtensionFactory
- Returns:
- The array containing the
extensionType
and optionally theextensionSubType
supported by this factory.
-
-