Skip to content

Instantly share code, notes, and snippets.

@yupadhyay
Created October 29, 2014 21:11
Show Gist options
  • Save yupadhyay/66a75634148454328a13 to your computer and use it in GitHub Desktop.
Save yupadhyay/66a75634148454328a13 to your computer and use it in GitHub Desktop.
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