sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r931058 - /sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java
Date Tue, 06 Apr 2010 09:09:30 GMT
Author: cziegeler
Date: Tue Apr  6 09:09:30 2010
New Revision: 931058

URL: http://svn.apache.org/viewvc?rev=931058&view=rev
Log:
SLING-1473 : Resolve script resource lazy

Modified:
    sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java

Modified: sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java?rev=931058&r1=931057&r2=931058&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java
(original)
+++ sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java
Tue Apr  6 09:09:30 2010
@@ -143,11 +143,8 @@ class DefaultSlingScript implements Slin
             // if we don't have a request resolver we directly return the script resource
             return scriptResource;
         }
-        Resource rsrc = resolver.getResource(this.scriptName);
-        if ( rsrc == null ) {
-            rsrc = new SyntheticResource(resolver, this.scriptName, this.scriptResource.getResourceType());
-        }
-        return rsrc;
+        return new LazyScriptResource(this.scriptName,
+                this.scriptResource.getResourceType(), resolver);
     }
 
     /**
@@ -669,4 +666,77 @@ class DefaultSlingScript implements Slin
         }
 
     }
+
+    /**
+     * This is a lazy implementation of the script resource which
+     * just returns the path, resource type and resource resolver directly.
+     */
+    private static final class LazyScriptResource implements Resource {
+
+        private final String path;
+
+        private final String resourceType;
+
+        private final ResourceResolver resolver;
+
+        private Resource delegatee;
+
+        public LazyScriptResource(final String path, final String resourceType, final ResourceResolver
resolver) {
+            this.path = path;
+            this.resourceType = resourceType;
+            this.resolver = resolver;
+        }
+
+        /**
+         * @see org.apache.sling.api.resource.Resource#getPath()
+         */
+        public String getPath() {
+            return this.path;
+        }
+
+        /**
+         * @see org.apache.sling.api.resource.Resource#getResourceType()
+         */
+        public String getResourceType() {
+            return this.resourceType;
+        }
+
+        /**
+         * @see org.apache.sling.api.resource.Resource#getResourceResolver()
+         */
+        public ResourceResolver getResourceResolver() {
+            return this.resolver;
+        }
+
+        private Resource getResource() {
+            if ( this.delegatee == null ) {
+                this.delegatee = this.resolver.getResource(this.path);
+                if ( this.delegatee == null ) {
+                    this.delegatee = new SyntheticResource(resolver, this.path, this.resourceType);
+                }
+            }
+            return this.delegatee;
+        }
+
+        /**
+         * @see org.apache.sling.api.resource.Resource#getResourceMetadata()
+         */
+        public ResourceMetadata getResourceMetadata() {
+            return this.getResource().getResourceMetadata();
+        }
+
+        /**
+         * @see org.apache.sling.api.resource.Resource#getResourceSuperType()
+         */
+        public String getResourceSuperType() {
+            return this.getResource().getResourceSuperType();
+        }
+
+        /**
+         * @see org.apache.sling.api.adapter.Adaptable#adaptTo(java.lang.Class)
+         */
+        public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+            return this.getResource().adaptTo(type);
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message