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.
Adapter factories can be registered programmatically using the registerAdapters
method. Alternatively, they can be registered declaratively using the
org.eclipse.core.runtime.adapters extension point. Factories registered
with this extension point will not be able to provide adapters until their
corresponding plugin has been activated.
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.
IAdaptableinterface) funnelIAdaptable.getAdapterinvocations to their adapter manager'sIAdapterManger.getAdaptermethod. The adapter manager then forwards this request unmodified to theIAdapterFactory.getAdaptermethod on one of the registered adapter factories.Adapter factories can be registered programmatically using the
registerAdaptersmethod. Alternatively, they can be registered declaratively using theorg.eclipse.core.runtime.adaptersextension point. Factories registered with this extension point will not be able to provide adapters until their corresponding plugin has been activated.The following code snippet shows how one might register an adapter of type
com.example.acme.Stickyon 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.