Created
October 29, 2014 21:11
-
-
Save yupadhyay/66a75634148454328a13 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.sling.adapter.SlingAdaptable; | |
import org.apache.sling.api.resource.Resource; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import javax.jcr.Node; | |
public abstract class MyCustomClass extends SlingAdaptable { | |
protected static final Logger log = LoggerFactory.getLogger(MyCustomClass.class); | |
/** | |
* {@inheritDoc} | |
*/ | |
@SuppressWarnings("unchecked") | |
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { | |
if (type == Resource.class) { | |
return (AdapterType) resource; | |
} else if (type == Node.class) { | |
return (AdapterType) resource.adaptTo(Node.class); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment