|
|||||||||
| Home >> All >> org >> eclipse >> core >> [ runtime overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.eclipse.core.runtime
Interface IAdapterManager

- public interface IAdapterManager
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 programatically 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
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.
| Method Summary | |
java.lang.Object |
getAdapter(java.lang.Object adaptable,
java.lang.Class 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 adapterTypeName)
Returns an object which is an instance of the given class name associated with the given object. |
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. |
void |
registerAdapters(IAdapterFactory factory,
java.lang.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,
java.lang.Class adaptable)
Removes the given adapter factory from the list of factories registered as extending the given class. |
| Method Detail |
getAdapter
public java.lang.Object getAdapter(java.lang.Object adaptable, java.lang.Class adapterType)
- Returns an object which is an instance of the given class associated
with the given object. Returns
nullif 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.
getAdapter
public java.lang.Object getAdapter(java.lang.Object adaptable, java.lang.String adapterTypeName)
- Returns an object which is an instance of the given class name associated
with the given object. Returns
nullif 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 theloadAdaptermethod instead.- Since:
- 3.0
hasAdapter
public boolean hasAdapter(java.lang.Object adaptable, java.lang.String adapterTypeName)
- Returns whether there is an adapter factory registered that may be able
to convert
adaptableto an object of typeadapterTypeName.Note that a return value of
truedoes not guarantee that a subsequent call togetAdapterwith 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 returnsnull, thengetAdapterwill still returnnull.- Since:
- 3.0
loadAdapter
public 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. Returns
nullif no such object can be found.Note that unlike the
getAdaptermethods, 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 usinggetAdapterinstead.- Since:
- 3.0
registerAdapters
public void registerAdapters(IAdapterFactory factory, java.lang.Class adaptable)
- Registers the given adapter factory as extending objects of the given
type.
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.
unregisterAdapters
public void unregisterAdapters(IAdapterFactory factory)
- Removes the given adapter factory completely from the list of registered
factories. Equivalent to calling
unregisterAdapters(IAdapterFactory,Class)on all classes against which it had been explicitly registered. Does nothing if the given factory is not currently registered.
unregisterAdapters
public void unregisterAdapters(IAdapterFactory factory, java.lang.Class adaptable)
- Removes the given adapter factory from the list of factories registered
as extending the given class. Does nothing if the given factory and type
combination is not registered.
|
|||||||||
| Home >> All >> org >> eclipse >> core >> [ runtime overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC