SlingAdaptable Abstract Class

[vc_row][vc_column width=”2/3″][vc_column_text el_class=”documentation”]The org.apache.sling.adapter.SlingAdaptable abstract Java class is an implementation of the org.apache.sling.adapter.Adaptable interface. By convention, implementations of the Adaptable interface should pass the adaptable processing to the org.apache.sling.adapter.AdapterManager if the Adapter implementation cannot provide an adapted object. The SlingAdaptable provides an easy way to follow this convention. Classes that extend the SlingAdaptable class must override the adaptTo() method. If not able to adapt the original adaptable the class must call the super.adaptTo() method to allow the org.apache.sling.adapter.AdapterManager to process the adaptable.

Methods


adaptTo()

 AdapterType adaptTo(Class type);
Parameters

type: the Class to return as an adapter

Result

An object that is an instance of the class specified in the type parameter. If not able to adapt to the requested type, null is returned.

Note: AdapterType is not an interface or class. It is a type parameter for the generic type, such as the conventional symbols, E, K, N, T, V.

Examples

public class MyAdaptable extends SlingAdaptable {

	private String title;

	public MyAdaptable(String title) {
		this.title = title;
	}

	@Override
	@SuppressWarnings("unchecked")
	public  AdapterType adaptTo(Class type) {
        if (type == String.class) {
            return (AdapterType) this.title;
        }
        return super.adaptTo(type);
    }
}

For Additional Information

Sling Adapter Annotation

Adaptable

SlingAdapter JavaDoc

GitHub: class org.apache.sling.api.adapter.SlingAdaptable¬†[/vc_column_text][/vc_column][vc_column width=”1/3″][vc_widget_sidebar sidebar_id=”woocommerce”][/vc_column][/vc_row][vc_row][vc_column width=”1/2″][vc_column_text]Previous: AdapterFactory Interface[/vc_column_text][/vc_column][vc_column width=”1/2″][vc_column_text]

Next: Sling Adapter Annotations

[/vc_column_text][/vc_column][/vc_row]

No Comments on "SlingAdaptable Abstract Class"

Leave a Comment

Your email address will not be published. Required fields are marked *