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