org.apache.sling.api.adapter
Class SlingAdaptable

java.lang.Object
  extended by org.apache.sling.api.adapter.SlingAdaptable
All Implemented Interfaces:
Adaptable
Direct Known Subclasses:
AbstractResource, SlingAdaptable

public abstract class SlingAdaptable
extends Object
implements Adaptable

The SlingAdaptable class is an (abstract) default implementation of the Adaptable interface. It just uses the default AdapterManager implemented to adapt itself to the requested type.

Extensions of this class may overwrite the adaptTo(Class) method using their own knowledge of adapters and may call this base class implementation to fall back to an extended adapters.

Since:
2.2

Constructor Summary
SlingAdaptable()
           
 
Method Summary
<AdapterType>
AdapterType
adaptTo(Class<AdapterType> type)
          Adapts the adaptable to another type.
static void setAdapterManager(AdapterManager adapterMgr)
          Set the adapter manager to be used by a synthetic resource.
static void unsetAdapterManager(AdapterManager adapterMgr)
          Unset an adapter manager previously set with setAdapterManager(AdapterManager).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SlingAdaptable

public SlingAdaptable()
Method Detail

setAdapterManager

public static void setAdapterManager(AdapterManager adapterMgr)
Set the adapter manager to be used by a synthetic resource. A bundle implementing the adapter manager can set the manager through this method. The set adapter manager will be used in the adaptTo(Class) method of a synthetic resource.

Parameters:
adapterMgr - The adapter manager.

unsetAdapterManager

public static void unsetAdapterManager(AdapterManager adapterMgr)
Unset an adapter manager previously set with setAdapterManager(AdapterManager). If this method is called with an AdapterManager different from the currently set one it has no effect.

Parameters:
adapterMgr - The adapter manager

adaptTo

public <AdapterType> AdapterType adaptTo(Class<AdapterType> type)
Description copied from interface: Adaptable
Adapts the adaptable to another type.

Specified by:
adaptTo in interface Adaptable
Type Parameters:
AdapterType - The generic type to which this resource is adapted to
Parameters:
type - The Class object of the target type, such as Node.class
Returns:
The adapter target or null if the resource cannot adapt to the requested type
See Also:
Adaptable.adaptTo(java.lang.Class)


Copyright © 2007-2011 The Apache Software Foundation. All Rights Reserved.