incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r794562 - in /sling/trunk/contrib/scripting/java: pom.xml src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java src/main/java/org/apache/sling/scripting/java/SlingIOProvider.java
Date Thu, 16 Jul 2009 07:18:18 GMT
Author: cziegeler
Date: Thu Jul 16 07:18:17 2009
New Revision: 794562

URL: http://svn.apache.org/viewvc?rev=794562&view=rev
Log:
SLING-1050 : Use dynamic class loader instead of dynamic import package.

Modified:
    sling/trunk/contrib/scripting/java/pom.xml
    sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java
    sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/SlingIOProvider.java

Modified: sling/trunk/contrib/scripting/java/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/pom.xml?rev=794562&r1=794561&r2=794562&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/java/pom.xml (original)
+++ sling/trunk/contrib/scripting/java/pom.xml Thu Jul 16 07:18:17 2009
@@ -60,7 +60,6 @@
                             org.apache.sling.scripting.java.jdt,
                             org.eclipse.jdt.*
                         </Private-Package>
-                        <DynamicImport-Package>*</DynamicImport-Package>
 
                         <ScriptEngine-Name>${pom.name}</ScriptEngine-Name>
                         <ScriptEngine-Version>${pom.version}</ScriptEngine-Version>
@@ -106,8 +105,8 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.jcr.classloader</artifactId>
-            <version>2.0.2-incubator</version>
+            <artifactId>org.apache.sling.commons.classloader</artifactId>
+            <version>0.9.0-SNAPSHOT</version>
         </dependency>
 
      <!-- We use the same eclipse jdt as the jsp bundle -->

Modified: sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java?rev=794562&r1=794561&r2=794562&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java
(original)
+++ sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java
Thu Jul 16 07:18:17 2009
@@ -20,7 +20,6 @@
 
 import java.io.Reader;
 
-import javax.jcr.RepositoryException;
 import javax.script.Bindings;
 import javax.script.ScriptContext;
 import javax.script.ScriptEngine;
@@ -34,8 +33,7 @@
 import org.apache.sling.api.scripting.SlingBindings;
 import org.apache.sling.api.scripting.SlingScript;
 import org.apache.sling.api.scripting.SlingScriptHelper;
-import org.apache.sling.jcr.api.SlingRepository;
-import org.apache.sling.jcr.classloader.RepositoryClassLoaderProvider;
+import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
 import org.apache.sling.scripting.api.AbstractScriptEngineFactory;
 import org.apache.sling.scripting.api.AbstractSlingScriptEngine;
 import org.osgi.service.component.ComponentContext;
@@ -60,18 +58,13 @@
  */
 public class JavaScriptEngineFactory extends AbstractScriptEngineFactory {
 
-    private static final String CLASSLOADER_NAME = "admin";
-
     /** default logger */
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    /** @scr.reference */
-    private SlingRepository repository;
-
     /**
      * @scr.reference
      */
-    private RepositoryClassLoaderProvider repoCLProvider;
+    private DynamicClassLoaderManager dynamicClassLoaderManager;
 
     /**
      * The class loader
@@ -127,7 +120,7 @@
      * @param componentContext
      */
     protected void activate(ComponentContext componentContext) {
-        this.ioProvider = new SlingIOProvider(repository);
+        this.ioProvider = new SlingIOProvider();
         this.servletCache = new ServletCache();
 
         this.javaServletContext = new JavaServletContext(ioProvider,
@@ -166,7 +159,7 @@
      */
     private void callServlet(Bindings bindings, SlingScriptHelper scriptHelper) {
 
-        ioProvider.setRequestResourceResolver(scriptHelper.getRequest().getResourceResolver());
+        ioProvider.setRequestResourceResolver(scriptHelper.getScript().getScriptResource().getResourceResolver());
         try {
             ServletWrapper servlet = getWrapperAdapter(scriptHelper);
             // create a SlingBindings object
@@ -206,7 +199,7 @@
      * Bind the class load provider.
      * @param repositoryClassLoaderProvider the new provider
      */
-    protected void bindRepositoryClassLoaderProvider(RepositoryClassLoaderProvider rclp)
{
+    protected void bindDynamicClassLoaderManager(DynamicClassLoaderManager rclp) {
         if ( this.javaClassLoader != null ) {
             this.ungetClassLoader();
         }
@@ -217,8 +210,8 @@
      * Unbind the class loader provider.
      * @param repositoryClassLoaderProvider the old provider
      */
-    protected void unbindRepositoryClassLoaderProvider(RepositoryClassLoaderProvider rclp)
{
-        if ( this.repoCLProvider == rclp ) {
+    protected void unbindDynamicClassLoaderManager(DynamicClassLoaderManager rclp) {
+        if ( this.dynamicClassLoaderManager == rclp ) {
             this.ungetClassLoader();
         }
     }
@@ -226,26 +219,17 @@
     /**
      * Get the class loader
      */
-    private void getClassLoader(RepositoryClassLoaderProvider rclp) {
-        try {
-            this.repoCLProvider = rclp;
-            this.javaClassLoader = rclp.getClassLoader(CLASSLOADER_NAME);
-        } catch (RepositoryException re) {
-            log.error("Cannot get Java class loader", re);
-        }
+    private void getClassLoader(DynamicClassLoaderManager rclp) {
+        this.dynamicClassLoaderManager = rclp;
+        this.javaClassLoader = rclp.getDynamicClassLoader();
     }
 
     /**
      * Unget the class loader
      */
     private void ungetClassLoader() {
-        if ( this.repoCLProvider != null ) {
-            if ( this.javaClassLoader != null ) {
-                this.repoCLProvider.ungetClassLoader(this.javaClassLoader);
-                this.javaClassLoader = null;
-            }
-            this.repoCLProvider = null;
-        }
+        this.dynamicClassLoaderManager = null;
+        this.javaClassLoader = null;
     }
     // ---------- Internal -----------------------------------------------------
 

Modified: sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/SlingIOProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/SlingIOProvider.java?rev=794562&r1=794561&r2=794562&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/SlingIOProvider.java
(original)
+++ sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/SlingIOProvider.java
Thu Jul 16 07:18:17 2009
@@ -38,7 +38,6 @@
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.jcr.api.SlingRepository;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,17 +49,10 @@
     /** default log */
     private static final Logger log = LoggerFactory.getLogger(SlingIOProvider.class);
 
-    private final SlingRepository repository;
-
     private ThreadLocal<ResourceResolver> requestResourceResolver;
 
-    // private session for write access
-    private ThreadLocal<Session> privateSession;
-
-    SlingIOProvider(SlingRepository repository) {
-        this.repository = repository;
+    SlingIOProvider() {
         this.requestResourceResolver = new ThreadLocal<ResourceResolver>();
-        this.privateSession = new ThreadLocal<Session>();
     }
 
     void setRequestResourceResolver(ResourceResolver resolver) {
@@ -69,15 +61,6 @@
 
     void resetRequestResourceResolver() {
         requestResourceResolver.remove();
-
-        // at the same time logout this thread's session
-        Session session = privateSession.get();
-        if (session != null) {
-            if (session.isLive()) {
-                session.logout();
-            }
-            privateSession.remove();
-        }
     }
 
     // ---------- IOProvider interface -----------------------------------------
@@ -210,13 +193,7 @@
     // ---------- internal -----------------------------------------------------
 
     private Session getPrivateSession() throws RepositoryException {
-        Session session = privateSession.get();
-        if (session == null) {
-            session = repository.loginAdministrative(null);
-            privateSession.set(session);
-        }
-
-        return session;
+        return requestResourceResolver.get().adaptTo(Session.class);
     }
 
     private static void checkNode(Node node, String path) {



Mime
View raw message