cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dani...@apache.org
Subject svn commit: r371688 - in /cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-impl/src: main/java/org/apache/cocoon/blocks/ test/java/org/apache/cocoon/blocks/ test/resources/org/apache/cocoon/blocks/test1/COB-INF/
Date Mon, 23 Jan 2006 22:25:25 GMT
Author: danielf
Date: Mon Jan 23 14:25:12 2006
New Revision: 371688

URL: http://svn.apache.org/viewcvs?rev=371688&view=rev
Log:
Added the blocks to the context class loader and a test case for it. It seemed to work when
executed within Eclipse. But no detailed tests yet. 

Modified:
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlocksManager.java
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/test/java/org/apache/cocoon/blocks/BlocksManagerTestCase.java
    cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/test/resources/org/apache/cocoon/blocks/test1/COB-INF/block-sitemap.xmap

Modified: cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlocksManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlocksManager.java?rev=371688&r1=371687&r2=371688&view=diff
==============================================================================
--- cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlocksManager.java
(original)
+++ cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlocksManager.java
Mon Jan 23 14:25:12 2006
@@ -16,8 +16,13 @@
 package org.apache.cocoon.blocks;
 
 import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 
 import javax.servlet.RequestDispatcher;
 import javax.servlet.Servlet;
@@ -58,7 +63,8 @@
     private Source wiringFile;
     private HashMap blocks = new HashMap();
     private HashMap mountedBlocks = new HashMap();
-    private Logger logger;    
+    private Logger logger;
+    private ClassLoader classLoader;
 
     public void init(ServletConfig servletConfig) throws ServletException {
         super.init(servletConfig);
@@ -95,6 +101,40 @@
         
         Configuration[] blockConfs = wiring.getChildren("block");
                 
+        // get all wired blocks and add their classed directory to the classloader
+        List urlList = new ArrayList();        
+        for (int i = 0; i < blockConfs.length; i++) {
+            Configuration blockConf = blockConfs[i];
+            String location = null;
+            try {
+                location = blockConf.getAttribute("location");
+            } catch (ConfigurationException e) {
+                throw new ServletException("Couldn't get location from the wiring file");
+            }
+            URL classesDir;
+            try {
+                classesDir = this.getServletContext().getResource(location);
+            } catch (MalformedURLException e) {
+                throw new ServletException("Couldn't get location of the classes of the block",
e);
+            }
+            if (classesDir != null) {
+                urlList.add(classesDir);
+                if(this.logger.isDebugEnabled()) {
+                    this.logger.debug("added " + classesDir.toString());
+                }
+            } else {
+                if(this.logger.isDebugEnabled()) {
+                    this.logger.debug("didn't add " + location);
+                }                
+            }
+        }
+        // setup the classloader using the current classloader as parent
+        ClassLoader parentClassloader = Thread.currentThread().getContextClassLoader();
+        URL[] urls = (URL[]) urlList.toArray(new URL[urlList.size()]);        
+        URLClassLoader classloader = new URLClassLoader(urls, parentClassloader);
+        Thread.currentThread().setContextClassLoader(classloader);
+        this.classLoader = Thread.currentThread().getContextClassLoader();
+            
         // Create and store all blocks
         for (int i = 0; i < blockConfs.length; i++) {
             Configuration blockConf = blockConfs[i];
@@ -161,6 +201,9 @@
             return;
         }
         
+        // set the blocks classloader for this thread
+        Thread.currentThread().setContextClassLoader(this.classLoader);        
+
         RequestDispatcher dispatcher = this.blocksContext.getRequestDispatcher(pathInfo);
         if (dispatcher == null)
             throw new ServletException("No block mounted at " + pathInfo);
@@ -193,7 +236,7 @@
     public boolean modifiedSince(long date) {
         return date < this.wiringFile.getLastModified();
     }
-    
+        
     /**
      * Utility function to ensure that the parts of the request URI not is null
      * and not ends with /

Modified: cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/test/java/org/apache/cocoon/blocks/BlocksManagerTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/test/java/org/apache/cocoon/blocks/BlocksManagerTestCase.java?rev=371688&r1=371687&r2=371688&view=diff
==============================================================================
--- cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/test/java/org/apache/cocoon/blocks/BlocksManagerTestCase.java
(original)
+++ cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/test/java/org/apache/cocoon/blocks/BlocksManagerTestCase.java
Mon Jan 23 14:25:12 2006
@@ -30,11 +30,11 @@
     public void testBlockSource3() throws Exception {
         pipeTest("/test1/test3", "test1/COB-INF/test.xml");
     }
-    /*
+
     public void testBlockSource4() throws Exception {
-        pipeTest("/test1/test4", "test1/COB-INF/classes/test.xml");
+        pipeTest("/test1/test4", "test1/META-INF/classes/test.xml");
     }
-    */
+
     public void testBlockSourceSub1() throws Exception {
         pipeTest("/test1/sub/test", "test1/COB-INF/sub/test.xml");
     }

Modified: cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/test/resources/org/apache/cocoon/blocks/test1/COB-INF/block-sitemap.xmap
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/test/resources/org/apache/cocoon/blocks/test1/COB-INF/block-sitemap.xmap?rev=371688&r1=371687&r2=371688&view=diff
==============================================================================
--- cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/test/resources/org/apache/cocoon/blocks/test1/COB-INF/block-sitemap.xmap
(original)
+++ cocoon/trunk/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/test/resources/org/apache/cocoon/blocks/test1/COB-INF/block-sitemap.xmap
Mon Jan 23 14:25:12 2006
@@ -19,12 +19,6 @@
 
 <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
 
-  <map:components>
-    <!--map:classpath>
-      <class-dir src="COB-INF/classes"/>
-    </map:classpath-->
-  </map:components>
-
   <map:pipelines>
     <map:pipeline>
 
@@ -44,7 +38,7 @@
       </map:match>
 
       <map:match pattern="test4">
-        <map:generate src="resource://test.xml"/>
+        <map:generate src="resource://META-INF/classes/test.xml"/>
         <map:serialize/>
       </map:match>
 



Mime
View raw message