You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/01/04 17:33:56 UTC
svn commit: r608907 - in
/incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api:
adapter/ resource/
Author: fmeschbe
Date: Fri Jan 4 08:33:55 2008
New Revision: 608907
URL: http://svn.apache.org/viewvc?rev=608907&view=rev
Log:
First steps towards a Prototype of "Everything is a Resource"
Added:
incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter/
incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter/Adaptable.java
incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/ResourceProvider.java
Modified:
incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/NonExistingResource.java
incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/Resource.java
incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
Added: incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter/Adaptable.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter/Adaptable.java?rev=608907&view=auto
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter/Adaptable.java (added)
+++ incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/adapter/Adaptable.java Fri Jan 4 08:33:55 2008
@@ -0,0 +1,35 @@
+/*
+ * 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.api.adapter;
+
+public interface Adaptable {
+
+ /**
+ * Adapts the adaptable to another type.
+ *
+ * @param <AdapterType> The generic type to which this resource is adapted
+ * to
+ * @param type The Class object of the target type, such as
+ * <code>Node.class</code>
+ * @return The adapter target or <code>null</code> if the resource cannot
+ * adapt to the requested type
+ */
+ <AdapterType> AdapterType adaptTo(Class<AdapterType> type);
+
+}
Modified: incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/NonExistingResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/NonExistingResource.java?rev=608907&r1=608906&r2=608907&view=diff
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/NonExistingResource.java (original)
+++ incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/NonExistingResource.java Fri Jan 4 08:33:55 2008
@@ -46,6 +46,11 @@
return resourceMetadata;
}
+ public ResourceProvider getResourceProvider() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
/**
* Returns <code>null</code> because a non-existing resource cannot adapt
* to anything.
Modified: incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/Resource.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/Resource.java?rev=608907&r1=608906&r2=608907&view=diff
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/Resource.java (original)
+++ incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/Resource.java Fri Jan 4 08:33:55 2008
@@ -16,8 +16,10 @@
*/
package org.apache.sling.api.resource;
+import org.apache.sling.api.adapter.Adaptable;
+
/** Resources are pieces of content on which Sling acts */
-public interface Resource {
+public interface Resource extends Adaptable {
/**
* The special resource type for resource instances representing nonexisting
@@ -59,6 +61,11 @@
* @see ResourceMetadata
*/
ResourceMetadata getResourceMetadata();
+
+ /**
+ * Returns the ResourceProvider from which this resource has been retrieved.
+ */
+ ResourceProvider getResourceProvider();
/**
* Adapts this resource to another type. A JCR based resource might support
Added: incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/ResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/ResourceProvider.java?rev=608907&view=auto
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/ResourceProvider.java (added)
+++ incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/ResourceProvider.java Fri Jan 4 08:33:55 2008
@@ -0,0 +1,90 @@
+/*
+ * 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.api.resource;
+
+import java.util.Iterator;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.sling.api.SlingException;
+
+/**
+ * API for providers of resources. Used by the {@link ResourceResolver} to
+ * transparently access resources from different locations such as a JCR
+ * repository (the default) or OSGi bundles.
+ * <p>
+ * This interface is intended to be implemented by providers of Resource
+ * instances on behalf of the {@link ResourceResolver}. It is not intended to
+ * be used by client applications directly.
+ */
+public interface ResourceProvider {
+
+ /**
+ * The name of the service registration property containing the root paths
+ * of the resources provided by this provider (value is "provider.roots").
+ */
+ static final String ROOTS = "provider.roots";
+
+ /**
+ * Returns a resource from this resource provider or <code>null</code> if
+ * the resource provider cannot find it. The path should have one of the
+ * {@link #getRoots()} strings as its prefix.
+ * <p>
+ * This method is called to resolve a resource for the given request. The
+ * properties of the request, such as request parameters, may be use to
+ * parametrize the resource resolution. An example of such parametrization
+ * is support for a JSR-311 style resource provider to support the
+ * parametrized URL patterns.
+ *
+ * @throws Exception may be thrown in case of any problem creating the
+ * <code>Resource</code> instance.
+ */
+ Resource getResource(/* ResourceResolver resourceResolver, */
+ HttpServletRequest request, String path) throws SlingException;
+
+ /**
+ * Returns a resource from this resource provider or <code>null</code> if
+ * the resource provider cannot find it. The path should have one of the
+ * {@link #getRoots()} strings as its prefix.
+ *
+ * @throws Exception may be thrown in case of any problem creating the
+ * <code>Resource</code> instance.
+ */
+ Resource getResource(/* ResourceResolver ResourceResolver, */ String path)
+ throws SlingException;
+
+ /**
+ * Returns an <code>Iterator</code> of {@link Resource} objects loaded
+ * from the children of the given <code>Resource</code>.
+ * <p>
+ * This method is only called for resource providers whose root path list
+ * contains an entry which is a prefix for the path of the parent resource.
+ *
+ * @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 provider has no children for
+ * the given resource.
+ * @throws NullPointerException If <code>parent</code> is
+ * <code>null</code>.
+ * @throws SlingException If any error occurs acquiring the child resource
+ * iterator.
+ */
+ Iterator<Resource> listChildren(Resource parent) throws SlingException;
+
+}
Modified: incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java?rev=608907&r1=608906&r2=608907&view=diff
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java (original)
+++ incubator/sling/whiteboard/fmeschbe/resource/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java Fri Jan 4 08:33:55 2008
@@ -24,6 +24,7 @@
import javax.servlet.http.HttpServletRequest;
import org.apache.sling.api.SlingException;
+import org.apache.sling.api.adapter.Adaptable;
/**
* The <code>ResourceResolver</code> defines the service API which may be used
@@ -32,7 +33,7 @@
* {@link org.apache.sling.api.SlingHttpServletRequest#getResourceResolver()}
* method.
*/
-public interface ResourceResolver {
+public interface ResourceResolver extends Adaptable {
/**
* Resolves the resource from the given <code>HttpServletRequest</code>.
@@ -44,7 +45,7 @@
* {@link Resource#getURI() resource URI} set to the request URI.
* {@link Resource#adaptTo(Class) object} returns <code>null</code> for
* all classes.
- *
+ *
* @param request The http servlet request object used to resolve the
* resource for.
* @return The {@link Resource} for the request.
@@ -60,7 +61,7 @@
* a Java Content Repository, the path could be a
* <code>javax.jcr.Item</code> path from which the resource object is
* loaded.
- *
+ *
* @param path The absolute path to the resource object to be loaded. The
* path may contain relative path specifiers like <code>.</code>
* (current location) and <code>..</code> (parent location),
@@ -86,7 +87,7 @@
* a Java Content Repository, the path could be a
* <code>javax.jcr.Item</code> path from which the resource object is
* loaded.
- *
+ *
* @param base The base {@link Resource} against which a relative path
* argument given by <code>path</code> is resolved. This
* parameter may be <code>null</code> if the <code>path</code>
@@ -118,7 +119,7 @@
* reading content from a Java Content Repository, the children could be the
* {@link Resource} objects loaded from child items of the <code>Item</code>
* of the given <code>Resource</code>.
- *
+ *
* @param parent The {@link Resource Resource} whose children are requested.
* If <code>null</code> the children of this request's Resource
* are returned.
@@ -140,7 +141,7 @@
* create a JCR <code>Query</code> through the <code>QueryManager</code>.
* The result returned is then based on the <code>NodeIterator</code>
* provided by the query result.
- *
+ *
* @param query The query string to use to find the resources.
* @param language The language in which the query is formulated.
* @return An <code>Iterator</code> of {@link Resource} objects matching
@@ -163,7 +164,7 @@
* the column name and the column value is the JCR <code>Value</code>
* object converted into the respective Java object, such as
* <code>Boolean</code> for a value of property type <em>Boolean</em>.
- *
+ *
* @param query The query string to use to find the resources.
* @param language The language in which the query is formulated.
* @return An <code>Iterator</code> of <code>Map</code> instances
@@ -177,7 +178,7 @@
* Adapts this resource resolver to another type. A JCR based resource
* resolver might support adapting to the JCR Session used by the resolver
* to access the JCR Repository.
- *
+ *
* @param <AdapterType> The generic type to which this resource is adapted
* to
* @param type The Class object of the target type, such as