Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 82973
Collapse All | Expand All

(-)src/org/eclipse/core/internal/runtime/AdapterManager.java (-4 / +25 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 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
Lines 7-19 Link Here
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     David Green - fix factories with non-standard class loading (bug 200068) 
10
 *     David Green - fix factories with non-standard class loading (bug 200068)
11
 * Martin Oberhuber (Wind River ) - [82973] add loadAdapter(Object,Class) API 
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.core.internal.runtime;
13
package org.eclipse.core.internal.runtime;
13
14
14
import java.util.*;
15
import java.util.*;
15
import org.eclipse.core.runtime.IAdapterFactory;
16
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.IAdapterManager;
17
17
18
/**
18
/**
19
 * This class is the standard implementation of <code>IAdapterManager</code>. It provides
19
 * This class is the standard implementation of <code>IAdapterManager</code>. It provides
Lines 344-349 Link Here
344
	}
344
	}
345
345
346
	/* (non-Javadoc)
346
	/* (non-Javadoc)
347
	 * @see org.eclipse.core.runtime.IAdapterManager#loadAdapter(java.lang.Object, java.lang.Class)
348
	 */
349
	public Object loadAdapter(Object adaptable, Class adapterType) {
350
		if (adaptable instanceof IAdaptable) {
351
			//ask the adaptable first
352
			IAdaptable a = (IAdaptable) adaptable;
353
			Object adapter = a.getAdapter(adapterType);
354
			if (adapter == null) {
355
				Object factoryResult = loadAdapter(adaptable, adapterType.getName());
356
				//ask the adaptable again, after loading adapter factory
357
				adapter = a.getAdapter(adapterType);
358
				if (adapter == null) {
359
					adapter = factoryResult;
360
				}
361
			}
362
			return adapter;
363
		}
364
		return loadAdapter(adaptable, adapterType.getName());
365
	}
366
367
	/* (non-Javadoc)
347
	 * @see org.eclipse.core.runtime.IAdapterManager#loadAdapter(java.lang.Object, java.lang.String)
368
	 * @see org.eclipse.core.runtime.IAdapterManager#loadAdapter(java.lang.Object, java.lang.String)
348
	 */
369
	 */
349
	public Object loadAdapter(Object adaptable, String adapterTypeName) {
370
	public Object loadAdapter(Object adaptable, String adapterTypeName) {
(-)src/org/eclipse/core/runtime/IAdapterManager.java (-1 / +30 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 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
Lines 7-12 Link Here
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 * Martin Oberhuber (Wind River ) - [82973] add loadAdapter(Object,Class) API 
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.core.runtime;
12
package org.eclipse.core.runtime;
12
13
Lines 198-203 Link Here
198
	public int queryAdapter(Object adaptable, String adapterTypeName);
199
	public int queryAdapter(Object adaptable, String adapterTypeName);
199
200
200
	/**
201
	/**
202
	 * Returns an object which is an instance of the given class associated
203
	 * with the given object. Returns <code>null</code> if no such object can
204
	 * be found.
205
	 * <p>
206
	 * Note that unlike the <code>getAdapter</code> methods, this method
207
	 * will cause the plug-in that contributes the adapter factory to be loaded
208
	 * if necessary. As such, this method should be used judiciously, in order
209
	 * to avoid unnecessary plug-in activations. Most clients should avoid
210
	 * activation by using <code>getAdapter</code> instead.
211
	 * <p>
212
	 * Unlike {link #loadAdapter(Object, String)}, this method first
213
	 * queries the adaptable object for an adapter, in case it is an
214
	 * instance of {link {@link IAdaptable}. Only if that query fails,
215
	 * the adapter manager mechnism is used to potentially load an adapter
216
	 * factory. Once the adapter factory is loaded, the object in question
217
	 * is again first queried before querying the adapter factory. 
218
	 * 
219
	 * @param adaptable the adaptable object being queried (usually an instance
220
	 * of <code>IAdaptable</code>)
221
	 * @param adapterType the type of adapter to look up
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
224
	 * given type
225
	 * @since 3.4
226
	 */
227
	public Object loadAdapter(Object adaptable, Class adapterType);
228
229
	/**
201
	 * Returns an object that is an instance of the given class name associated
230
	 * Returns an object that is an instance of the given class name associated
202
	 * with the given object. Returns <code>null</code> if no such object can
231
	 * with the given object. Returns <code>null</code> if no such object can
203
	 * be found.
232
	 * be found.

Return to bug 82973