Interface AdapterFactory
-
- All Known Implementing Classes:
WorkItemAdapterFactory
@ConsumerType public interface AdapterFactory
TheAdapterFactory
interface defines the API for helpers which may be provided to enhance the adaptability of adaptable objects.Implementations of this interface are registered as OSGi services and are used by the
AdapterManager
to adapt objects on demand. TheAdapterFactory
services are not really intended to be used by clients directly.The
AdapterManager
implementations ensures that thegetAdapter(Object, Class)
method is only called for the combination of adaptable and adapter type which is allowed as per the service registration propertiesADAPTABLE_CLASSES
andADAPTER_CLASSES
.If multiple implementations for the same combination of adapter and adaptable are registered, the implementation with the lowest service ranking wins (or with the highest service id, if the ranking is the same).
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ADAPTABLE_CLASSES
The service registration property listing the fully qualified names of classes which can be adapted by this adapter factory (value is "adaptables").static java.lang.String
ADAPTER_CLASSES
The service registration property listing the fully qualified names of classes to which this factory can adapt adaptables (value is "adapters").static java.lang.String
SERVICE_NAME
The service name to use when registering implementations of this interface as services.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <AdapterType>
AdapterTypegetAdapter(@NotNull java.lang.Object adaptable, @NotNull java.lang.Class<AdapterType> type)
Adapt the given object to the adaptable type.
-
-
-
Field Detail
-
SERVICE_NAME
static final java.lang.String SERVICE_NAME
The service name to use when registering implementations of this interface as services.- See Also:
- Constant Field Values
-
ADAPTABLE_CLASSES
static final java.lang.String ADAPTABLE_CLASSES
The service registration property listing the fully qualified names of classes which can be adapted by this adapter factory (value is "adaptables"). The "adaptable" parameters of thegetAdapter(Object, Class)
method must be an instance of one of these classes for this factory to be able to adapt the object.- See Also:
- Constant Field Values
-
ADAPTER_CLASSES
static final java.lang.String ADAPTER_CLASSES
The service registration property listing the fully qualified names of classes to which this factory can adapt adaptables (value is "adapters").- See Also:
- Constant Field Values
-
-
Method Detail
-
getAdapter
@Nullable <AdapterType> AdapterType getAdapter(@NotNull @NotNull java.lang.Object adaptable, @NotNull @NotNull java.lang.Class<AdapterType> type)
Adapt the given object to the adaptable type. The adaptable object is guaranteed to be an instance of one of the classes listed in theADAPTABLE_CLASSES
services registration property. The type parameter is one of the classes listed in theADAPTER_CLASSES
service registration properties.This method may return
null
if the adaptable object cannot be adapted to the adapter (target) type for any reason. In this case, the implementation should log a message to the log facility noting the cause for not being able to adapt.Note that the
adaptable
object is not required to implement theAdaptable
interface, though most of the time this method is called by means of calling theAdaptable.adaptTo(Class)
method.- Type Parameters:
AdapterType
- The generic type of the adapter (target) type.- Parameters:
adaptable
- The object to adapt to the adapter type.type
- The type to which the object is to be adapted.- Returns:
- The adapted object or
null
if this factory instance cannot adapt the object.
-
-