|
Eclipse Platform 2.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
An adapter manager maintains a registry of adapter factories.
Clients directly invoke methods on an adapter manager to register
and unregister adapters.
All adaptable objects (that is, objects that implement the
IAdaptable
interface) funnel
IAdaptable.getAdapter
invocations to their
adapter manager's IAdapterManger.getAdapter
method. The adapter manager then forwards this request
unmodified to the IAdapterFactory.getAdapter
method on one of the registered adapter factories.
The following code snippet shows how one might register
an adapter of type com.example.acme.Sticky
on resources in the workspace.
IAdapterFactory pr = new IAdapterFactory() { public Class[] getAdapterList() { return new Class[] { com.example.acme.Sticky.class }; } public Object getAdapter(Object adaptableObject, adapterType) { IResource res = (IResource) adaptableObject; QualifiedName key = new QualifiedName("com.example.acme", "sticky-note"); try { com.example.acme.Sticky v = (com.example.acme.Sticky) res.getSessionProperty(key); if (v == null) { v = new com.example.acme.Sticky(); res.setSessionProperty(key, v); } } catch (CoreException e) { // unable to access session property - ignore } return v; } } Platform.getAdapterManager().registerAdapters(pr, IResource.class);
This interface is not intended to be implemented by clients.
IAdaptable
,
IAdapterFactory
Method Summary | |
Object |
getAdapter(Object adaptable,
Class adapterType)
Returns an object which is an instance of the given class associated with the given object. |
void |
registerAdapters(IAdapterFactory factory,
Class adaptable)
Registers the given adapter factory as extending objects of the given type. |
void |
unregisterAdapters(IAdapterFactory factory)
Removes the given adapter factory completely from the list of registered factories. |
void |
unregisterAdapters(IAdapterFactory factory,
Class adaptable)
Removes the given adapter factory from the list of factories registered as extending the given class. |
Method Detail |
public Object getAdapter(Object adaptable, Class adapterType)
null
if
no such object can be found.
adaptable
- the adaptable object being queried
(usually an instance of IAdaptable
)adapterType
- the type of adapter to look up
null
if the given adaptable object does not
have an adapter of the given typepublic void registerAdapters(IAdapterFactory factory, Class adaptable)
If 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.
factory
- the adapter factoryadaptable
- the type being extendedunregisterAdapters(org.eclipse.core.runtime.IAdapterFactory)
public void unregisterAdapters(IAdapterFactory factory)
unregisterAdapters(IAdapterFactory,Class)
on all classes against which it had been explicitly registered.
Does nothing if the given factory is not currently registered.
factory
- the adapter factory to removeregisterAdapters(org.eclipse.core.runtime.IAdapterFactory, java.lang.Class)
public void unregisterAdapters(IAdapterFactory factory, Class adaptable)
factory
- the adapter factory to removeadaptable
- one of the types against which the given
factory is registeredregisterAdapters(org.eclipse.core.runtime.IAdapterFactory, java.lang.Class)
|
Eclipse Platform 2.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |