com.adobe.granite.resourceresolverhelper.ResourceResolverHelper Maven / Gradle / Ivy
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2011 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.granite.resourceresolverhelper;
import java.util.concurrent.Callable;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.annotation.versioning.ProviderType;
/**
* The ResourceResolverHelper
service provides access to a
* ResourceResolver
previously provided for the current thread.
*
* The implementation provides two contexts:
*
* - While handling a Servlet API request the default
*
ResourceResolver
provided is the one provided by the Sling
* Engine through the SlingHttpServletRequest
* - In a callstack opened by a call to the
* {@link #callWith(ResourceResolver, Callable)} method
*
*/
@ProviderType
public interface ResourceResolverHelper {
/**
* Returns the current ResourceResolver
for the current thread
* or null
if this method is called on a thread which is not
* handling a request or which is not in a call stack started with a call to
* the {@link #callWith(ResourceResolver, Callable)} method.
*
* ResourceResolver
instances must not be shared accross
* threads because they are not thread safe.
*/
ResourceResolver getResourceResolver();
/**
* Returns the current ResourceResolver
adapted to the selected
* type. If there is no curren ResourceResolver
or if the
* ResourceResolver
does not adapt to the desired type
* null
is returned.
*
* This method is equivalent to calling
* getResourceResolver().adaptTo(type)
.
*
* @param type The type to which the current ResourceResolver
* should be adapted.
* @return The ResourceResolver
adapted to the desired
* type
or null
*/
Type getResourceResolverAs(final Class type);
/**
* Calls the given callable
under the provides
* ResourceResolver
. Before calling the callable
* the resolver
is set as the current
* ResourceResolver
such that the
* {@link #getResourceResolver()} method returns the given
* ResourceResolver
.
*
* @param resolver The ResourceResolver
to set as the current
* ResourceResolver
before calling the
* callable
.
* @param callable The code to execute under the resolver
.
* @return The result from calling the callable
* @throws NullPointerException if callable
is
* null
.
* @throws Exception The exception thrown by the callable
is
* returned.
*/
Type callWith(final ResourceResolver resolver, final Callable callable) throws Exception;
}