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 *******************************************************************************/ 11 package org.eclipse.core.runtime; 12 13 import org.eclipse.core.internal.runtime.AdapterManager; 14 15 /** 16 * An abstract superclass implementing the <code>IAdaptable</code> 17 * interface. <code>getAdapter</code> invocations are directed 18 * to the platform's adapter manager. 19 * <p> 20 * Note: In situations where it would be awkward to subclass this 21 * class, the same affect can be achieved simply by implementing 22 * the <code>IAdaptable</code> interface and explicitly forwarding 23 * the <code>getAdapter</code> request to the platform's 24 * adapter manager. The method would look like: 25 * <pre> 26 * public Object getAdapter(Class adapter) { 27 * return Platform.getAdapterManager().getAdapter(this, adapter); 28 * } 29 * </pre> 30 * </p><p> 31 * This class can be used without OSGi running. 32 * </p><p> 33 * Clients may subclass. 34 * </p> 35 * 36 * @see Platform#getAdapterManager() 37 * @see IAdaptable 38 */ 39 public abstract class PlatformObject implements IAdaptable { 40 /** 41 * Constructs a new platform object. 42 */ 43 public PlatformObject() { 44 super(); 45 } 46 47 /** 48 * Returns an object which is an instance of the given class 49 * associated with this object. Returns <code>null</code> if 50 * no such object can be found. 51 * <p> 52 * This implementation of the method declared by <code>IAdaptable</code> 53 * passes the request along to the platform's adapter manager; roughly 54 * <code>Platform.getAdapterManager().getAdapter(this, adapter)</code>. 55 * Subclasses may override this method (however, if they do so, they 56 * should invoke the method on their superclass to ensure that the 57 * Platform's adapter manager is consulted). 58 * </p> 59 * 60 * @param adapter the class to adapt to 61 * @return the adapted object or <code>null</code> 62 * @see IAdaptable#getAdapter(Class) 63 * @see Platform#getAdapterManager() 64 */ 65 public Object getAdapter(Class adapter) { 66 return AdapterManager.getDefault().getAdapter(this, adapter); 67 } 68 } 69