Package org.apache.sling.api.adapter
Class SlingAdaptable
- java.lang.Object
 - 
- org.apache.sling.api.adapter.SlingAdaptable
 
 
- 
- All Implemented Interfaces:
 Adaptable
- Direct Known Subclasses:
 AbstractResource,SlingAdaptable
public abstract class SlingAdaptable extends java.lang.Object implements Adaptable
TheSlingAdaptableclass is an (abstract) default implementation of theAdaptableinterface. It just uses the defaultAdapterManagerimplemented to adapt itself to the requested type.Extensions of this class may overwrite the
adaptTo(Class)method using their own knowledge of adapters and should call this base class implementation to fall back for other types.- Since:
 - 2.2 (Sling API Bundle 2.2.0)
 
 
- 
- 
Constructor Summary
Constructors Constructor Description SlingAdaptable() 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <AdapterType>
AdapterTypeadaptTo(java.lang.Class<AdapterType> type)Calls into the registeredAdapterManagerto adapt this object to the desiredtype.static voidsetAdapterManager(AdapterManager adapterMgr)Sets the globalAdapterManagerto be used by this class.static voidunsetAdapterManager(AdapterManager adapterMgr)Unsets the globalAdapterManager. 
 - 
 
- 
- 
Method Detail
- 
setAdapterManager
public static void setAdapterManager(AdapterManager adapterMgr)
Sets the globalAdapterManagerto be used by this class.This method is intended to only be called by the
AdapterManagerwanting to register itself for use. Currently only a single adapter manager is supported by this class.- Parameters:
 adapterMgr- TheAdapterManagerto be globally used.
 
- 
unsetAdapterManager
public static void unsetAdapterManager(AdapterManager adapterMgr)
Unsets the globalAdapterManager.This method is intended to only be called by the
AdapterManagerwanting to unregister itself. Currently only a single adapter manager is supported by this class.- Parameters:
 adapterMgr- TheAdapterManagerto be unset. If this is not the same as currently registered this method has no effect.
 
- 
adaptTo
public <AdapterType> AdapterType adaptTo(java.lang.Class<AdapterType> type)
Calls into the registeredAdapterManagerto adapt this object to the desiredtype.This method implements a cache of adapters to improve performance. That is repeated calls to this method with the same class will result in the same object to be returned.
- Specified by:
 adaptToin interfaceAdaptable- Type Parameters:
 AdapterType- The generic type to which this resource is adapted to- Parameters:
 type- The Class object of the target type, such asjavax.jcr.Node.classorjava.io.File.class- Returns:
 - The adapter target or 
nullif the resource cannot adapt to the requested type 
 
 - 
 
 -