public final class AdapterManager extends java.lang.Object implements IAdapterManager
IAdapterManager. It provides
fast lookup of property values with the following semantics:
null value. Remaining factories won't be invoked.class X extends Y implements A, BObject
getInterfaces (in the example, X's
superinterfaces then Y's superinterfaces) IAdapterFactory,
IAdapterManagerLOADED, NONE, NOT_LOADED| Modifier and Type | Method and Description |
|---|---|
java.lang.String[] |
computeAdapterTypes(java.lang.Class<? extends java.lang.Object> adaptable)
Returns the types that can be obtained by converting
adaptableClass
via this manager. |
<T> java.lang.Class<? super T>[] |
computeClassOrder(java.lang.Class<T> adaptable)
Returns the super-type search order starting with
adaptable. |
void |
flushLookup()
Flushes the cache of adapter search paths.
|
<T> T |
getAdapter(java.lang.Object adaptable,
java.lang.Class<T> adapterType)
Returns an object which is an instance of the given class associated
with the given object.
|
java.lang.Object |
getAdapter(java.lang.Object adaptable,
java.lang.String adapterType)
Returns an object which is an instance of the given class name associated
with the given object.
|
static AdapterManager |
getDefault() |
java.util.Map<java.lang.String,java.util.List<IAdapterFactory>> |
getFactories() |
boolean |
hasAdapter(java.lang.Object adaptable,
java.lang.String adapterTypeName)
Returns whether there is an adapter factory registered that may be able
to convert
adaptable to an object of type adapterTypeName. |
java.lang.Object |
loadAdapter(java.lang.Object adaptable,
java.lang.String adapterTypeName)
Returns an object that is an instance of the given class name associated
with the given object.
|
int |
queryAdapter(java.lang.Object adaptable,
java.lang.String adapterTypeName)
Returns a status of an adapter factory registered that may be able
to convert
adaptable to an object of type adapterTypeName. |
void |
registerAdapters(IAdapterFactory factory,
java.lang.Class<?> adaptable)
Registers the given adapter factory as extending objects of the given
type.
|
void |
registerFactory(IAdapterFactory factory,
java.lang.String adaptableType) |
void |
registerLazyFactoryProvider(IAdapterManagerProvider factoryProvider) |
void |
unregisterAdapters(IAdapterFactory factory)
Removes the given adapter factory completely from the list of registered
factories.
|
void |
unregisterAdapters(IAdapterFactory factory,
java.lang.Class<?> adaptable)
Removes the given adapter factory from the list of factories registered
as extending the given class.
|
void |
unregisterAllAdapters() |
boolean |
unregisterLazyFactoryProvider(IAdapterManagerProvider factoryProvider) |
public static AdapterManager getDefault()
public java.lang.String[] computeAdapterTypes(java.lang.Class<? extends java.lang.Object> adaptable)
IAdapterManageradaptableClass
via this manager. Converting means that subsequent calls to getAdapter()
or loadAdapter() could result in an adapted object.
Note that the returned types do not guarantee that
a subsequent call to getAdapter with the same type as an argument
will return a non-null result. If the factory's plug-in has not yet been
loaded, or if the factory itself returns null, then
getAdapter will still return null.
computeAdapterTypes in interface IAdapterManageradaptable - the adaptable class being queriedadaptableClass via this manager. An empty array
is returned if there are none.public <T> java.lang.Class<? super T>[] computeClassOrder(java.lang.Class<T> adaptable)
adaptable.
The search order is defined in this class' comment.computeClassOrder in interface IAdapterManageradaptable - the class for which to return the class order.public void flushLookup()
It is likely easier to just toss the whole cache rather than trying to be smart and remove only those entries affected.
public <T> T getAdapter(java.lang.Object adaptable,
java.lang.Class<T> adapterType)
IAdapterManagernull if no such object can
be found.
Note that this method will never cause plug-ins to be loaded. If the
only suitable factory is not yet loaded, this method will return null.
In most cases, it is preferable for client code to use
Adapters.adapt(Object, Class, boolean) rather than calling this
method directly since doing so will also detect interfaces supplied by the
IAdaptable interface
getAdapter in interface IAdapterManageradaptable - the adaptable object being queried (usually an instance
of IAdaptable)adapterType - the type of adapter to look upnull
if the given adaptable object does not have an available adapter of the
given typepublic java.lang.Object getAdapter(java.lang.Object adaptable,
java.lang.String adapterType)
IAdapterManagernull if no such object can
be found.
Note that this method will never cause plug-ins to be loaded. If the
only suitable factory is not yet loaded, this method will return null.
If activation of the plug-in providing the factory is required, use the
loadAdapter method instead.
In most cases, it is preferable for client code to use
Adapters.adapt(Object, Class, boolean) rather than calling this
method directly since doing so will also detect interfaces supplied by the
IAdaptable interface
getAdapter in interface IAdapterManageradaptable - the adaptable object being queried (usually an instance
of IAdaptable)adapterType - the fully qualified name of the type of adapter to look upnull
if the given adaptable object does not have an available adapter of the
given typepublic boolean hasAdapter(java.lang.Object adaptable,
java.lang.String adapterTypeName)
IAdapterManageradaptable to an object of type adapterTypeName.
Note that a return value of true does not guarantee that
a subsequent call to getAdapter with the same arguments
will return a non-null result. If the factory's plug-in has not yet been
loaded, or if the factory itself returns null, then
getAdapter will still return null.
hasAdapter in interface IAdapterManageradaptable - the adaptable object being queried (usually an instance
of IAdaptable)adapterTypeName - the fully qualified class name of an adapter to
look uptrue if there is an adapter factory that claims
it can convert adaptable to an object of type adapterType,
and false otherwise.public int queryAdapter(java.lang.Object adaptable,
java.lang.String adapterTypeName)
IAdapterManageradaptable to an object of type adapterTypeName.
One of the following values can be returned:
IAdapterManager.NONE if no applicable adapter factory was found;IAdapterManager.NOT_LOADED if an adapter factory was found, but has not been loaded;IAdapterManager.LOADED if an adapter factory was found, and it is loaded.queryAdapter in interface IAdapterManageradaptable - the adaptable object being queried (usually an instance
of IAdaptable)adapterTypeName - the fully qualified class name of an adapter to
look uppublic java.lang.Object loadAdapter(java.lang.Object adaptable,
java.lang.String adapterTypeName)
IAdapterManagernull if no such object can
be found.
Note that unlike the getAdapter methods, this method
will cause the plug-in that contributes the adapter factory to be loaded
if necessary. As such, this method should be used judiciously, in order
to avoid unnecessary plug-in activations. Most clients should avoid
activation by using getAdapter instead.
In most cases, it is preferable for client code to use
Adapters.adapt(Object, Class, boolean) rather than calling this
method directly since doing so will also detect interfaces supplied by the
IAdaptable interface.
loadAdapter in interface IAdapterManageradaptable - the adaptable object being queried (usually an instance
of IAdaptable)adapterTypeName - the fully qualified name of the type of adapter to look upnull
if the given adaptable object does not have an available adapter of the
given typepublic void registerAdapters(IAdapterFactory factory, java.lang.Class<?> adaptable)
IAdapterManagerIf the type being extended is a class, the given factory's adapters are available on instances of that class and any of its subclasses. If it is an interface, the adapters are available to all classes that directly or indirectly implement that interface.
registerAdapters in interface IAdapterManagerfactory - the adapter factoryadaptable - the type being extendedIAdapterManager.unregisterAdapters(IAdapterFactory),
IAdapterManager.unregisterAdapters(IAdapterFactory, Class)public void registerFactory(IAdapterFactory factory, java.lang.String adaptableType)
public void unregisterAdapters(IAdapterFactory factory)
IAdapterManagerunregisterAdapters(IAdapterFactory,Class)
on all classes against which it had been explicitly registered. Does
nothing if the given factory is not currently registered.unregisterAdapters in interface IAdapterManagerfactory - the adapter factory to removeIAdapterManager.registerAdapters(IAdapterFactory, Class)public void unregisterAdapters(IAdapterFactory factory, java.lang.Class<?> adaptable)
IAdapterManagerunregisterAdapters in interface IAdapterManagerfactory - the adapter factory to removeadaptable - one of the types against which the given factory is
registeredIAdapterManager.registerAdapters(IAdapterFactory, Class)public void unregisterAllAdapters()
public void registerLazyFactoryProvider(IAdapterManagerProvider factoryProvider)
public boolean unregisterLazyFactoryProvider(IAdapterManagerProvider factoryProvider)
public java.util.Map<java.lang.String,java.util.List<IAdapterFactory>> getFactories()