comparison dwtx/core/runtime/IAdapterManager.d @ 3:6518c18a01f7

eclipse.core package without osgi dependencies
author Frank Benoit <benoit@tionex.de>
date Wed, 26 Mar 2008 00:57:19 +0100
parents
children 46a6e0e6ccd4
comparison
equal deleted inserted replaced
2:a012107a911c 3:6518c18a01f7
1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module dwtx.core.runtime.IAdapterManager;
14
15 import dwtx.core.runtime.IAdapterFactory;
16
17 import dwt.dwthelper.utils;
18
19 /**
20 * An adapter manager maintains a registry of adapter factories. Clients
21 * directly invoke methods on an adapter manager to register and unregister
22 * adapters. All adaptable objects (that is, objects that implement the <code>IAdaptable</code>
23 * interface) funnel <code>IAdaptable.getAdapter</code> invocations to their
24 * adapter manager's <code>IAdapterManger.getAdapter</code> method. The
25 * adapter manager then forwards this request unmodified to the <code>IAdapterFactory.getAdapter</code>
26 * method on one of the registered adapter factories.
27 * <p>
28 * Adapter factories can be registered programmatically using the <code>registerAdapters</code>
29 * method. Alternatively, they can be registered declaratively using the
30 * <code>dwtx.core.runtime.adapters</code> extension point. Factories registered
31 * with this extension point will not be able to provide adapters until their
32 * corresponding plugin has been activated.
33 * <p>
34 * The following code snippet shows how one might register an adapter of type
35 * <code>com.example.acme.Sticky</code> on resources in the workspace.
36 * <p>
37 *
38 * <pre>
39 * IAdapterFactory pr = new IAdapterFactory() {
40 * public Class[] getAdapterList() {
41 * return new Class[] { com.example.acme.Sticky.class };
42 * }
43 * public Object getAdapter(Object adaptableObject, Class adapterType) {
44 * IResource res = (IResource) adaptableObject;
45 * QualifiedName key = new QualifiedName(&quot;com.example.acme&quot;, &quot;sticky-note&quot;);
46 * try {
47 * com.example.acme.Sticky v = (com.example.acme.Sticky) res.getSessionProperty(key);
48 * if (v is null) {
49 * v = new com.example.acme.Sticky();
50 * res.setSessionProperty(key, v);
51 * }
52 * } catch (CoreException e) {
53 * // unable to access session property - ignore
54 * }
55 * return v;
56 * }
57 * }
58 * Platform.getAdapterManager().registerAdapters(pr, IResource.class);
59 * </pre>
60 *
61 * </p><p>
62 * This interface can be used without OSGi running.
63 * </p><p>
64 * This interface is not intended to be implemented by clients.
65 * </p>
66 * @see IAdaptable
67 * @see IAdapterFactory
68 */
69 public interface IAdapterManager {
70
71 /**
72 * This value can be returned to indicate that no applicable adapter factory
73 * was found.
74 * @since dwtx.equinox.common 3.3
75 */
76 public static const int NONE = 0;
77
78 /**
79 * This value can be returned to indicate that an adapter factory was found,
80 * but has not been loaded.
81 * @since dwtx.equinox.common 3.3
82 */
83 public static const int NOT_LOADED = 1;
84
85 /**
86 * This value can be returned to indicate that an adapter factory is loaded.
87 * @since dwtx.equinox.common 3.3
88 */
89 public static const int LOADED = 2;
90
91 /**
92 * Returns the types that can be obtained by converting <code>adaptableClass</code>
93 * via this manager. Converting means that subsequent calls to <code>getAdapter()</code>
94 * or <code>loadAdapter()</code> could result in an adapted object.
95 * <p>
96 * Note that the returned types do not guarantee that
97 * a subsequent call to <code>getAdapter</code> with the same type as an argument
98 * will return a non-null result. If the factory's plug-in has not yet been
99 * loaded, or if the factory itself returns <code>null</code>, then
100 * <code>getAdapter</code> will still return <code>null</code>.
101 * </p>
102 * @param adaptableClass the adaptable class being queried
103 * @return an array of type names that can be obtained by converting
104 * <code>adaptableClass</code> via this manager. An empty array
105 * is returned if there are none.
106 * @since 3.1
107 */
108 public String[] computeAdapterTypes(ClassInfo adaptableClass);
109
110 /**
111 * Returns the class search order for a given class. The search order from a
112 * class with the definition <br>
113 * <code>class X extends Y implements A, B</code><br>
114 * is as follows:
115 * <ul>
116 * <li>the target's class: X
117 * <li>X's superclasses in order to <code>Object</code>
118 * <li>a breadth-first traversal of the target class's interfaces in the
119 * order returned by <code>getInterfaces</code> (in the example, A and its
120 * superinterfaces then B and its superinterfaces) </li>
121 * </ul>
122 *
123 * @param clazz the class for which to return the class order.
124 * @return the class search order for the given class. The returned
125 * search order will minimally contain the target class.
126 * @since 3.1
127 */
128 public ClassInfo[] computeClassOrder(ClassInfo clazz);
129
130 /**
131 * Returns an object which is an instance of the given class associated
132 * with the given object. Returns <code>null</code> if no such object can
133 * be found.
134 * <p>
135 * Note that this method will never cause plug-ins to be loaded. If the
136 * only suitable factory is not yet loaded, this method will return <code>null</code>.
137 *
138 * @param adaptable the adaptable object being queried (usually an instance
139 * of <code>IAdaptable</code>)
140 * @param adapterType the type of adapter to look up
141 * @return an object castable to the given adapter type, or <code>null</code>
142 * if the given adaptable object does not have an available adapter of the
143 * given type
144 */
145 public Object getAdapter(Object adaptable, ClassInfo adapterType);
146
147 /**
148 * Returns an object which is an instance of the given class name associated
149 * with the given object. Returns <code>null</code> if no such object can
150 * be found.
151 * <p>
152 * Note that this method will never cause plug-ins to be loaded. If the
153 * only suitable factory is not yet loaded, this method will return <code>null</code>.
154 * If activation of the plug-in providing the factory is required, use the
155 * <code>loadAdapter</code> method instead.
156 *
157 * @param adaptable the adaptable object being queried (usually an instance
158 * of <code>IAdaptable</code>)
159 * @param adapterTypeName the fully qualified name of the type of adapter to look up
160 * @return an object castable to the given adapter type, or <code>null</code>
161 * if the given adaptable object does not have an available adapter of the
162 * given type
163 * @since 3.0
164 */
165 public Object getAdapter(Object adaptable, String adapterTypeName);
166
167 /**
168 * Returns whether there is an adapter factory registered that may be able
169 * to convert <code>adaptable</code> to an object of type <code>adapterTypeName</code>.
170 * <p>
171 * Note that a return value of <code>true</code> does not guarantee that
172 * a subsequent call to <code>getAdapter</code> with the same arguments
173 * will return a non-null result. If the factory's plug-in has not yet been
174 * loaded, or if the factory itself returns <code>null</code>, then
175 * <code>getAdapter</code> will still return <code>null</code>.
176 *
177 * @param adaptable the adaptable object being queried (usually an instance
178 * of <code>IAdaptable</code>)
179 * @param adapterTypeName the fully qualified class name of an adapter to
180 * look up
181 * @return <code>true</code> if there is an adapter factory that claims
182 * it can convert <code>adaptable</code> to an object of type <code>adapterType</code>,
183 * and <code>false</code> otherwise.
184 * @since 3.0
185 */
186 public bool hasAdapter(Object adaptable, String adapterTypeName);
187
188 /**
189 * Returns a status of an adapter factory registered that may be able
190 * to convert <code>adaptable</code> to an object of type <code>adapterTypeName</code>.
191 * <p>
192 * One of the following values can be returned:<ul>
193 * <li>{@link dwtx.core.runtime.IAdapterManager#NONE} if no applicable adapter factory was found;</li>
194 * <li>{@link dwtx.core.runtime.IAdapterManager#NOT_LOADED} if an adapter factory was found, but has not been loaded;</li>
195 * <li>{@link dwtx.core.runtime.IAdapterManager#LOADED} if an adapter factory was found, and it is loaded.</li>
196 * </ul></p>
197 * @param adaptable the adaptable object being queried (usually an instance
198 * of <code>IAdaptable</code>)
199 * @param adapterTypeName the fully qualified class name of an adapter to
200 * look up
201 * @return a status of the adapter
202 * @since dwtx.equinox.common 3.3
203 */
204 public int queryAdapter(Object adaptable, String adapterTypeName);
205
206 /**
207 * Returns an object that is an instance of the given class name associated
208 * with the given object. Returns <code>null</code> if no such object can
209 * be found.
210 * <p>
211 * Note that unlike the <code>getAdapter</code> methods, this method
212 * will cause the plug-in that contributes the adapter factory to be loaded
213 * if necessary. As such, this method should be used judiciously, in order
214 * to avoid unnecessary plug-in activations. Most clients should avoid
215 * activation by using <code>getAdapter</code> instead.
216 *
217 * @param adaptable the adaptable object being queried (usually an instance
218 * of <code>IAdaptable</code>)
219 * @param adapterTypeName the fully qualified name of the type of adapter to look up
220 * @return an object castable to the given adapter type, or <code>null</code>
221 * if the given adaptable object does not have an available adapter of the
222 * given type
223 * @since 3.0
224 */
225 public Object loadAdapter(Object adaptable, String adapterTypeName);
226
227 /**
228 * Registers the given adapter factory as extending objects of the given
229 * type.
230 * <p>
231 * If the type being extended is a class, the given factory's adapters are
232 * available on instances of that class and any of its subclasses. If it is
233 * an interface, the adapters are available to all classes that directly or
234 * indirectly implement that interface.
235 * </p>
236 *
237 * @param factory the adapter factory
238 * @param adaptable the type being extended
239 * @see #unregisterAdapters(IAdapterFactory)
240 * @see #unregisterAdapters(IAdapterFactory, Class)
241 */
242 public void registerAdapters(IAdapterFactory factory, ClassInfo adaptable);
243
244 /**
245 * Removes the given adapter factory completely from the list of registered
246 * factories. Equivalent to calling <code>unregisterAdapters(IAdapterFactory,Class)</code>
247 * on all classes against which it had been explicitly registered. Does
248 * nothing if the given factory is not currently registered.
249 *
250 * @param factory the adapter factory to remove
251 * @see #registerAdapters(IAdapterFactory, Class)
252 */
253 public void unregisterAdapters(IAdapterFactory factory);
254
255 /**
256 * Removes the given adapter factory from the list of factories registered
257 * as extending the given class. Does nothing if the given factory and type
258 * combination is not registered.
259 *
260 * @param factory the adapter factory to remove
261 * @param adaptable one of the types against which the given factory is
262 * registered
263 * @see #registerAdapters(IAdapterFactory, Class)
264 */
265 public void unregisterAdapters(IAdapterFactory factory, ClassInfo adaptable);
266 }