Author: fmeschbe
Date: Thu Feb 7 01:33:49 2008
New Revision: 619321
URL: http://svn.apache.org/viewvc?rev=619321&view=rev
Log:
SLING-228 Add ResourceWrapper and SyntheticResource classes to the Sling API
Added:
incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java
incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java
Added:
incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java?rev=619321&view=auto
==============================================================================
---
incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java
(added)
+++
incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java
Thu Feb 7 01:33:49 2008
@@ -0,0 +1,67 @@
+/*
+ * 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;
+
+/**
+ * The <code>ResourceWrapper</code> is a wrapper for any <code>Resource</code>
+ * delegating all method calls to the wrapped resource by default. Extensions
of
+ * this class may overwrite any method to return different values as
+ * appropriate.
+ */
+public class ResourceWrapper implements Resource {
+
+ // the wrapped resource
+ private final Resource resource;
+
+ /**
+ * Creates a new wrapper instance delegating all method calls to the given
+ * <code>resource</code>.
+ */
+ public ResourceWrapper(Resource resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Returns the <code>Resource</code> wrapped by this instance.
+ */
+ public Resource getResource() {
+ return resource;
+ }
+
+ public String getPath() {
+ return resource.getPath();
+ }
+
+ public ResourceMetadata getResourceMetadata() {
+ return resource.getResourceMetadata();
+ }
+
+ public ResourceProvider getResourceProvider() {
+ return resource.getResourceProvider();
+ }
+
+ public String getResourceType() {
+ return resource.getResourceType();
+ }
+
+ public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+ return resource.adaptTo(type);
+ }
+
+}
Added:
incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java?rev=619321&view=auto
==============================================================================
---
incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java
(added)
+++
incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java
Thu Feb 7 01:33:49 2008
@@ -0,0 +1,84 @@
+/*
+ * 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 org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceProvider;
+
+/**
+ * The <code>SyntheticResource</code> class is a simple implementation of the
+ * <code>Resource</code> interface which may be used to provide a resource
+ * object which has no actual resource data.
+ */
+public class SyntheticResource implements Resource {
+
+ /** The path of the synthetic resource */
+ private final String path;
+
+ /** The type this synthetic resource assumes */
+ private final String resourceType;
+
+ /** The metadat of this resource just containig the resource path */
+ private final ResourceMetadata resourceMetadata;
+
+ /**
+ * Creates a synthetic resource with the given <code>path</code> and
+ * <code>resourceType</code>.
+ */
+ public SyntheticResource(String path, String resourceType) {
+ this.path = path;
+ this.resourceType = resourceType;
+ this.resourceMetadata = new ResourceMetadata();
+ this.resourceMetadata.put(ResourceMetadata.RESOLUTION_PATH, path);
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public String getResourceType() {
+ return resourceType;
+ }
+
+ /**
+ * Returns a resource metadata object containing just the path of this
+ * resource as the [EMAIL PROTECTED] ResourceMetadata#RESOLUTION_PATH}
property.
+ */
+ public ResourceMetadata getResourceMetadata() {
+ return resourceMetadata;
+ }
+
+ /**
+ * Returns <code>null</code> because synthetic resources have no actual
+ * data and are not provided by any [EMAIL PROTECTED] ResourceProvider}.
+ */
+ public ResourceProvider getResourceProvider() {
+ return null;
+ }
+
+ /**
+ * Returns <code>null</code> because synthetic resources have no actual
+ * data and thus may not adapt to anything else.
+ */
+ public <Type> Type adaptTo(Class<Type> type) {
+ return null;
+ }
+
+}