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 2008/08/20 10:30:08 UTC

svn commit: r687286 - /incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java

Author: cziegeler
Date: Wed Aug 20 01:30:07 2008
New Revision: 687286

URL: http://svn.apache.org/viewvc?rev=687286&view=rev
Log:
SLING-622 : Correctly bind/unbind repository classloader provider.

Modified:
    incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java

Modified: incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java?rev=687286&r1=687285&r2=687286&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java (original)
+++ incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java Wed Aug 20 01:30:07 2008
@@ -101,8 +101,12 @@
 
     private ServletConfig servletConfig;
 
+    private RepositoryClassLoaderProvider repoCLProvider;
+
     public static final String SCRIPT_TYPE = "jsp";
 
+    private static final String CLASSLOADER_NAME = "admin";
+
     public JspScriptEngineFactory() {
         setExtensions(SCRIPT_TYPE);
     }
@@ -248,23 +252,51 @@
         }
     }
 
-    protected void bindRepositoryClassLoaderProvider(
-            RepositoryClassLoaderProvider repositoryClassLoaderProvider) {
+    /**
+     * Bind the class load provider.
+     * @param repositoryClassLoaderProvider the new provider
+     */
+    protected void bindRepositoryClassLoaderProvider(RepositoryClassLoaderProvider rclp) {
+        if ( this.jspClassLoader != null ) {
+            this.ungetClassLoader();
+        }
+        this.getClassLoader(rclp);
+    }
+
+    /**
+     * Unbind the class loader provider.
+     * @param repositoryClassLoaderProvider the old provider
+     */
+    protected void unbindRepositoryClassLoaderProvider(RepositoryClassLoaderProvider rclp) {
+        if ( this.repoCLProvider == rclp ) {
+            this.ungetClassLoader();
+        }
+    }
+
+    /**
+     * Get the class loader
+     */
+    private void getClassLoader(RepositoryClassLoaderProvider rclp) {
         try {
-            jspClassLoader = repositoryClassLoaderProvider.getClassLoader("admin");
+            this.repoCLProvider = rclp;
+            this.jspClassLoader = rclp.getClassLoader(CLASSLOADER_NAME);
         } catch (RepositoryException re) {
             log.error("Cannot get JSP class loader", re);
         }
     }
 
-    protected void unbindRepositoryClassLoaderProvider(
-            RepositoryClassLoaderProvider repositoryClassLoaderProvider) {
-        if (jspClassLoader != null) {
-            repositoryClassLoaderProvider.ungetClassLoader(jspClassLoader);
-            jspClassLoader = null;
+    /**
+     * Unget the class loader
+     */
+    private void ungetClassLoader() {
+        if ( this.repoCLProvider != null ) {
+            if ( this.jspClassLoader != null ) {
+                this.repoCLProvider.ungetClassLoader(this.jspClassLoader);
+                this.jspClassLoader = null;
+            }
+            this.repoCLProvider = null;
         }
     }
-
     // ---------- Internal -----------------------------------------------------
 
     private class JspScriptEngine extends AbstractSlingScriptEngine {