001/* 002 * (C) Copyright 2006-2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * IBM Corporation - initial API and implementation 018 * Nuxeo - added generics in method signatures 019 */ 020package org.nuxeo.runtime.model; 021 022/** 023 * An interface for an adaptable object. 024 * <p> 025 * Adaptable objects can be dynamically extended to provide different interfaces (or "adapters"). Adapters are created 026 * by adapter factories, which are in turn managed by type by adapter managers. 027 * <p> 028 * For example, 029 * 030 * <pre> 031 * IAdaptable a = [some adaptable]; 032 * IFoo x = a.getAdapter(IFoo.class); 033 * if (x != null) 034 * [do IFoo things with x] 035 * </pre> 036 * <p> 037 * This interface can be used without OSGi running. 038 * <p> 039 * Clients may implement this interface, or obtain a default implementation of this interface by subclassing 040 * <code>PlatformObject</code>. 041 * 042 * @see AdapterFactory 043 * @see AdapterManager 044 * @see AdaptableObject 045 */ 046public interface Adaptable { 047 048 /** 049 * Returns an object which is an instance of the given class associated with this object. Returns <code>null</code> 050 * if no such object can be found. 051 * 052 * @param adapter the adapter class to look up 053 * @return a object castable to the given class, or <code>null</code> if this object does not have an adapter for 054 * the given class 055 */ 056 <T> T getAdapter(Class<T> adapter); 057 058}