001/*
002 * Copyright (c) 2006-2012 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     IBM Corporation - initial API and implementation
011 *     Nuxeo - added generics in method signatures
012 */
013package org.nuxeo.runtime.model;
014
015/**
016 * An interface for an adaptable object.
017 * <p>
018 * Adaptable objects can be dynamically extended to provide different interfaces (or "adapters"). Adapters are created
019 * by adapter factories, which are in turn managed by type by adapter managers.
020 * <p>
021 * For example,
022 *
023 * <pre>
024 *     IAdaptable a = [some adaptable];
025 *     IFoo x = a.getAdapter(IFoo.class);
026 *     if (x != null)
027 *         [do IFoo things with x]
028 * </pre>
029 * <p>
030 * This interface can be used without OSGi running.
031 * <p>
032 * Clients may implement this interface, or obtain a default implementation of this interface by subclassing
033 * <code>PlatformObject</code>.
034 *
035 * @see AdapterFactory
036 * @see AdapterManager
037 * @see AdaptableObject
038 */
039public interface Adaptable {
040
041    /**
042     * Returns an object which is an instance of the given class associated with this object. Returns <code>null</code>
043     * if no such object can be found.
044     *
045     * @param adapter the adapter class to look up
046     * @return a object castable to the given class, or <code>null</code> if this object does not have an adapter for
047     *         the given class
048     */
049    <T> T getAdapter(Class<T> adapter);
050
051}