You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2015/10/27 13:35:59 UTC
svn commit: r1710797 - in
/sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider:
JCRQueryProvider.java ProviderContext.java QueryProvider.java
ResolveContext.java ResolverContext.java ResourceContext.java
ResourceProvider.java
Author: cziegeler
Date: Tue Oct 27 12:35:59 2015
New Revision: 1710797
URL: http://svn.apache.org/viewvc?rev=1710797&view=rev
Log:
SLING-5201 : Improve resource provider resolving
Added:
sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResolverContext.java (with props)
sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResourceContext.java
- copied, changed from r1710792, sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResolveContext.java
Removed:
sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResolveContext.java
Modified:
sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/JCRQueryProvider.java
sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ProviderContext.java
sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/QueryProvider.java
sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResourceProvider.java
Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/JCRQueryProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/JCRQueryProvider.java?rev=1710797&r1=1710796&r2=1710797&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/JCRQueryProvider.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/JCRQueryProvider.java Tue Oct 27 12:35:59 2015
@@ -42,7 +42,7 @@ public interface JCRQueryProvider<T> {
/**
* The supported languages of the resource provider.
*/
- String[] getSupportedLanguages(@Nonnull ResolveContext<T> ctx);
+ String[] getSupportedLanguages(@Nonnull ResolverContext<T> ctx);
/**
* Searches for resources using the given query formulated in the given
@@ -68,7 +68,7 @@ public interface JCRQueryProvider<T> {
* @throws IllegalStateException if this resource provider has already been
* closed.
*/
- Iterator<Resource> findResources(@Nonnull ResolveContext<T> ctx, String query, String language);
+ Iterator<Resource> findResources(@Nonnull ResolverContext<T> ctx, String query, String language);
/**
* Queries the storage using the given query formulated in the given
@@ -97,5 +97,5 @@ public interface JCRQueryProvider<T> {
* @throws IllegalStateException if this resource provider has already been
* closed.
*/
- Iterator<ValueMap> queryResources(@Nonnull ResolveContext<T> ctx, String query, String language);
+ Iterator<ValueMap> queryResources(@Nonnull ResolverContext<T> ctx, String query, String language);
}
Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ProviderContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ProviderContext.java?rev=1710797&r1=1710796&r2=1710797&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ProviderContext.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ProviderContext.java Tue Oct 27 12:35:59 2015
@@ -20,6 +20,7 @@ package org.apache.sling.spi.resource.pr
import java.util.Set;
+import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import aQute.bnd.annotation.ProviderType;
@@ -42,4 +43,12 @@ public interface ProviderContext {
*/
Set<String> getExcludedPaths();
+ /**
+ * Return the parent resource provider.
+ * If the parent should be used for resolving, a context created with
+ * {@link ResourceContext#getParentResolveContext()} should be passed to that
+ * instance.
+ * @return The parent provider or {@code null} if there is no parent.
+ */
+ @CheckForNull ResourceProvider<?> getParentResourceProvider();
}
Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/QueryProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/QueryProvider.java?rev=1710797&r1=1710796&r2=1710797&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/QueryProvider.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/QueryProvider.java Tue Oct 27 12:35:59 2015
@@ -40,7 +40,7 @@ public interface QueryProvider <T> {
* @param qi The query instructions
* @return A query result or {@code null}.
*/
- @CheckForNull QueryResult find(@Nonnull ResolveContext<T> ctx,
+ @CheckForNull QueryResult find(@Nonnull ResolverContext<T> ctx,
@Nonnull Query q,
@Nonnull QueryInstructions qi);
}
Added: sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResolverContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResolverContext.java?rev=1710797&view=auto
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResolverContext.java (added)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResolverContext.java Tue Oct 27 12:35:59 2015
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.spi.resource.provider;
+
+import java.util.Map;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+import org.apache.sling.api.resource.ResourceResolver;
+
+import aQute.bnd.annotation.ProviderType;
+
+/**
+ * The resolve context is passed to most of the methods of the {@link ResourceProvider}
+ * to provide additional context information for the provider.
+ *
+ * If the provider requires authentication, the object returned by {@link ResourceProvider#authenticate(Map)}
+ * is returned in {@link #getProviderState()}.
+ */
+@ProviderType
+public interface ResolverContext<T> {
+
+ /**
+ * Get the current resource resolver.
+ * @return The resource resolver.
+ */
+ @Nonnull ResourceResolver getResourceResolver();
+
+ /**
+ * This is the object returned by {@link ResourceProvider#authenticate(Map)}
+ * @return The data object or {@code null}
+ */
+ @CheckForNull T getProviderState();
+
+ /**
+ * Return a resolve context for the parent resource provider.
+ * @return A resolve context or {@code null} if there is no parent.
+ * @see #getParentResourceProvider()
+ */
+ @CheckForNull ResolverContext<?> getParentResolveContext();
+}
Propchange: sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResolverContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResolverContext.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Copied: sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResourceContext.java (from r1710792, sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResolveContext.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResourceContext.java?p2=sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResourceContext.java&p1=sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResolveContext.java&r1=1710792&r2=1710797&rev=1710797&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResolveContext.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResourceContext.java Tue Oct 27 12:35:59 2015
@@ -21,27 +21,14 @@ package org.apache.sling.spi.resource.pr
import java.util.Map;
import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
-
-import org.apache.sling.api.resource.ResourceResolver;
import aQute.bnd.annotation.ProviderType;
/**
- * The resolve context is passed to most of the methods of the {@link ResourceProvider}
- * to provide additional context information for the provider.
- *
- * If the provider requires authentication, the object returned by {@link ResourceProvider#authenticate(Map)}
- * is returned in {@link #getProviderState()}.
+ * The resource context provides additional information for resource resolving.
*/
@ProviderType
-public interface ResolveContext<T> {
-
- /**
- * Get the current resource resolver.
- * @return The resource resolver.
- */
- @Nonnull ResourceResolver getResourceResolver();
+public interface ResourceContext {
/**
* Return optional parameters for resolving the resource.
@@ -52,24 +39,13 @@ public interface ResolveContext<T> {
@CheckForNull Map<String, String> getResolveParameters();
/**
- * This is the object returned by {@link ResourceProvider#authenticate(Map)}
- * @return The data object or {@code null}
+ * "Empty" instance, not providing any additional information.
*/
- @CheckForNull T getProviderState();
+ ResourceContext EMPTY_CONTEXT = new ResourceContext() {
- /**
- * Return a resolve context for the parent resource provider.
- * @return A resolve context or {@code null} if there is no parent.
- * @see #getParentResourceProvider()
- */
- @CheckForNull ResolveContext<?> getParentResolveContext();
-
- /**
- * Return the parent resource provider.
- * If the parent should be used for resolving, a context created with
- * {@link #getParentResolveContext()} should be passed to that
- * instance.
- * @return The parent provider or {@code null} if there is no parent.
- */
- @CheckForNull ResourceProvider<?> getParentResourceProvider();
+ @Override
+ public Map<String, String> getResolveParameters() {
+ return null;
+ }
+ };
}
Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResourceProvider.java?rev=1710797&r1=1710796&r2=1710797&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResourceProvider.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/spi/resource/provider/ResourceProvider.java Tue Oct 27 12:35:59 2015
@@ -70,15 +70,15 @@ import aQute.bnd.annotation.ConsumerType
* cases, the resource resolver calls {@link #authenticate(Map)} and on
* successful authentication the provider returns a state object for
* the current user. This object is passed into the provider with
- * every method through {@link ResolveContext#getProviderState()}.
+ * every method through {@link ResourceContext#getProviderState()}.
* If a provider requires authentication, the {@link #logout(Object)} method
* is called, when the resource resolver is closed. If the provider
* does not set this service property or sets it to {@link #AUTHENTICATE_NO}
* the {@link #authenticate(Map)} and {@link #logout(Object)} method
- * are never called and therefore {@link ResolveContext#getProviderState()}
+ * are never called and therefore {@link ResourceContext#getProviderState()}
* will return {@code null}.
* <p>
- * Each method gets the {@link ResolveContext} which gives access to
+ * Each method gets the {@link ResourceContext} which gives access to
* further functionality.
* <p>
* TODO - query
@@ -151,8 +151,8 @@ public abstract class ResourceProvider<T
/**
* A modifiable resource provider is capable of creating, changing and deleting resources.
- * This means the methods {@link #create(ResolveContext, String, Map)},
- * {@link #delete(ResolveContext, Resource)} and adapting a resource to a modifiable
+ * This means the methods {@link #create(ResourceContext, String, Map)},
+ * {@link #delete(ResourceContext, Resource)} and adapting a resource to a modifiable
* value map is supported.
* If this flag is set to {@code false}, the resource resolver does not take this
* provider into account for modifications and modification operations to this provider
@@ -172,7 +172,7 @@ public abstract class ResourceProvider<T
public static final String PROPERTY_ADAPTABLE = "provider.adaptable";
/**
- * If this flag is set to {@code true}, the resource resolver will call {@link #refresh(ResolveContext)}
+ * If this flag is set to {@code true}, the resource resolver will call {@link #refresh(ResourceContext)}
* when it's refreshed itself.
*/
public static final String PROPERTY_REFRESHABLE = "provider.refreshable";
@@ -265,7 +265,7 @@ public abstract class ResourceProvider<T
* <p>
* Returns a provider context object if authentication is successful. The
* context object is passed to the resource provider in all messages through
- * the {@link ResolveContext}. A valid implementation might return {@code null}
+ * the {@link ResourceContext}. A valid implementation might return {@code null}
* as the context information.
* <p>
* If authentication fails a {@code LoginException} must be thrown.
@@ -320,11 +320,11 @@ public abstract class ResourceProvider<T
/**
* The provider is updated to reflect the latest state.
* Resources which have changes pending are not discarded.
- * {@link #revert(ResolveContext)} can be called to discard changes.
+ * {@link #revert(ResourceContext)} can be called to discard changes.
*
- * @param ctx The {@link ResolveContext} to which the returned {@link Resource} is attached.
+ * @param ctx The {@link ResourceContext} to which the returned {@link Resource} is attached.
*/
- public void refresh(final @Nonnull ResolveContext<T> ctx) {
+ public void refresh(final @Nonnull ResolverContext<T> ctx) {
// nothing to do here
}
@@ -335,12 +335,12 @@ public abstract class ResourceProvider<T
* This method will never throw an exception
* even after the resource provider has been closed
*
- * @param ctx The {@link ResolveContext} to which the returned {@link Resource} is attached.
+ * @param ctx The {@link ResourceContext} to which the returned {@link Resource} is attached.
* @return <code>true</code> if the resource provider has not been closed
* yet and is still active.. Once the resource provider has been closed
* or is not active anymore, this method returns <code>false</code>.
*/
- public boolean isLive(final @Nonnull ResolveContext<T> ctx) {
+ public boolean isLive(final @Nonnull ResolverContext<T> ctx) {
return true;
}
@@ -354,19 +354,19 @@ public abstract class ResourceProvider<T
* depending on the full path of resource resolution passed into the
* resource resolver.
*
- * @param ctx The {@link ResolveContext} to which the returned {@link Resource} is attached.
+ * @param ctx The {@link ResourceContext} to which the returned {@link Resource} is attached.
* @param child The child resource.
* @return <code>null</code> if this provider does not have a resource for
* the parent.
* @throws org.apache.sling.api.SlingException
* may be thrown in case of any problem creating the <code>Resource</code> instance.
*/
- public @CheckForNull Resource getParent(final @Nonnull ResolveContext<T> ctx, final @Nonnull Resource child) {
+ public @CheckForNull Resource getParent(final @Nonnull ResolverContext<T> ctx, final @Nonnull Resource child) {
final String parentPath = ResourceUtil.getParent(child.getPath());
if (parentPath == null) {
return null;
}
- return this.getResource(ctx, parentPath, null);
+ return this.getResource(ctx, parentPath, ResourceContext.EMPTY_CONTEXT, null);
}
/**
@@ -383,14 +383,16 @@ public abstract class ResourceProvider<T
* @param resourceResolver
* The {@link ResourceResolver} to which the returned {@link Resource} is attached.
* @param path The full path of the resource.
+ * @param resourceContext Additional information for resolving teh resource
* @param parent Optional parent resource
* @return <code>null</code> If this provider does not have a resource for
* the path.
* @throws org.apache.sling.api.SlingException
* may be thrown in case of any problem creating the <code>Resource</code> instance.
*/
- public abstract @CheckForNull Resource getResource(@Nonnull final ResolveContext<T> ctx,
+ public abstract @CheckForNull Resource getResource(@Nonnull final ResolverContext<T> ctx,
@Nonnull final String path,
+ @Nonnull final ResourceContext resourceContext,
@CheckForNull final Resource parent);
/**
@@ -413,7 +415,7 @@ public abstract class ResourceProvider<T
* As with {@link #getResource(ResourceResolver, String)} the returned Resource objects must
* not be cached objects.
*
- * @param ctx The {@link ResolveContext} to which the returned {@link Resource} is attached.
+ * @param ctx The {@link ResourceContext} to which the returned {@link Resource} is attached.
* @param parent
* The {@link Resource Resource} whose children are requested.
* @return An <code>Iterator</code> of {@link Resource} objects or <code>null</code> if the resource
@@ -423,18 +425,18 @@ public abstract class ResourceProvider<T
* @throws SlingException
* If any error occurs acquiring the child resource iterator.
*/
- public abstract @CheckForNull Iterator<Resource> listChildren(final @Nonnull ResolveContext<T> ctx, final @Nonnull Resource parent);
+ public abstract @CheckForNull Iterator<Resource> listChildren(final @Nonnull ResolverContext<T> ctx, final @Nonnull Resource parent);
/**
* Returns a collection of attribute names whose value can be retrieved
* calling the {@link #getAttribute(ResourceResolver, String)} method.
*
- * @param ctx The {@link ResolveContext} to which the returned {@link Resource} is attached.
+ * @param ctx The {@link ResourceContext} to which the returned {@link Resource} is attached.
* @return A collection of attribute names or <code>null</code>
* @throws IllegalStateException if this resource provider has already been
* closed.
*/
- public Collection<String> getAttributeNames(final @Nonnull ResolveContext<T> ctx) {
+ public Collection<String> getAttributeNames(final @Nonnull ResolverContext<T> ctx) {
return null;
}
@@ -443,7 +445,7 @@ public abstract class ResourceProvider<T
* if the attribute is not set or not visible (as e.g. security
* sensitive attributes).
*
- * @param ctx The {@link ResolveContext} to which the returned {@link Resource} is attached.
+ * @param ctx The {@link ResourceContext} to which the returned {@link Resource} is attached.
* @param name
* The name of the attribute to access
* @return The value of the attribute or <code>null</code> if the attribute
@@ -451,7 +453,7 @@ public abstract class ResourceProvider<T
* @throws IllegalStateException
* if this resource provider has already been closed.
*/
- public Object getAttribute(final @Nonnull ResolveContext<T> ctx, final @Nonnull String name) {
+ public Object getAttribute(final @Nonnull ResolverContext<T> ctx, final @Nonnull String name) {
return null;
}
@@ -463,14 +465,14 @@ public abstract class ResourceProvider<T
* A resource provider should value {@link ResourceResolver#PROPERTY_RESOURCE_TYPE}
* to set the resource type of a resource.
*
- * @param ctx The {@link ResolveContext} to which the returned {@link Resource} is attached.
+ * @param ctx The {@link ResourceContext} to which the returned {@link Resource} is attached.
* @param path The resource path.
* @param properties Optional properties
* @return The new resource.
*
* @throws PersistenceException If anything fails
*/
- public Resource create(final @Nonnull ResolveContext<T> ctx, final String path, final Map<String, Object> properties)
+ public Resource create(final @Nonnull ResolverContext<T> ctx, final String path, final Map<String, Object> properties)
throws PersistenceException {
throw new PersistenceException("create is not supported.");
}
@@ -480,12 +482,12 @@ public abstract class ResourceProvider<T
* This change is kept in the transient space of this provider
* until {@link #commit(ResourceResolver)} is called.
*
- * @param ctx The {@link ResolveContext} to which the returned {@link Resource} is attached.
+ * @param ctx The {@link ResourceContext} to which the returned {@link Resource} is attached.
* @param resource The resource to delete.
*
* @throws PersistenceException If anything fails
*/
- public void delete(final @Nonnull ResolveContext<T> ctx, final @Nonnull Resource resource)
+ public void delete(final @Nonnull ResolverContext<T> ctx, final @Nonnull Resource resource)
throws PersistenceException {
throw new PersistenceException("delete is not supported.");
}
@@ -493,20 +495,20 @@ public abstract class ResourceProvider<T
/**
* Revert all transient changes: create, delete and updates.
*
- * @param ctx The {@link ResolveContext} to which the returned {@link Resource} is attached.
+ * @param ctx The {@link ResourceContext} to which the returned {@link Resource} is attached.
*/
- public void revert(final @Nonnull ResolveContext<T> ctx) {
+ public void revert(final @Nonnull ResolverContext<T> ctx) {
// nothing to do here
}
/**
* Commit all transient changes: create, delete and updates
*
- * @param ctx The {@link ResolveContext} to which the returned {@link Resource} is attached.
+ * @param ctx The {@link ResourceContext} to which the returned {@link Resource} is attached.
*
* @throws PersistenceException If anything fails
*/
- public void commit(final @Nonnull ResolveContext<T> ctx)
+ public void commit(final @Nonnull ResolverContext<T> ctx)
throws PersistenceException {
// nothing to do here
}
@@ -514,9 +516,9 @@ public abstract class ResourceProvider<T
/**
* Are there any transient changes?
*
- * @param ctx The {@link ResolveContext} to which the returned {@link Resource} is attached.
+ * @param ctx The {@link ResourceContext} to which the returned {@link Resource} is attached.
*/
- public boolean hasChanges(final @Nonnull ResolveContext<T> ctx) {
+ public boolean hasChanges(final @Nonnull ResolverContext<T> ctx) {
return false;
}
@@ -549,12 +551,12 @@ public abstract class ResourceProvider<T
* well as their behaviour with respect to returning newly created or not
* instance on each call.
*
- * @param ctx The {@link ResolveContext}.
+ * @param ctx The {@link ResourceContext}.
* @param type The generic type to which this resource is adapted to.
* @return The adapter target or {@code null} if the provider cannot
* be adapt to the requested type.
*/
- public @CheckForNull <AdapterType> AdapterType adaptTo(final @Nonnull ResolveContext<T> ctx,
+ public @CheckForNull <AdapterType> AdapterType adaptTo(final @Nonnull ResolverContext<T> ctx,
final @Nonnull Class<AdapterType> type) {
return null;
}
@@ -577,7 +579,7 @@ public abstract class ResourceProvider<T
* @throws PersistenceException If an error occurs.
* @return {@code true} if the provider can perform the copy
*/
- public boolean copy(final @Nonnull ResolveContext<T> ctx,
+ public boolean copy(final @Nonnull ResolverContext<T> ctx,
final String srcAbsPath,
final String destAbsPath) throws PersistenceException {
return false;
@@ -602,7 +604,7 @@ public abstract class ResourceProvider<T
* @return {@code true} if the provider can perform the move
*/
- public boolean move(final @Nonnull ResolveContext<T> ctx,
+ public boolean move(final @Nonnull ResolverContext<T> ctx,
final String srcAbsPath,
final String destAbsPath) throws PersistenceException {
return false;