cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r407834 - in /cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon: components/classloader/ core/container/spring/
Date Fri, 19 May 2006 16:00:42 GMT
Author: cziegeler
Date: Fri May 19 09:00:40 2006
New Revision: 407834

URL: http://svn.apache.org/viewvc?rev=407834&view=rev
Log:
ClassLoaderFactory depends only on servlet api

Added:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderUtils.java
  (with props)
Modified:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/AbstractClassLoaderFactory.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderConfiguration.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderFactory.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoader.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoaderFactory.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoader.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoaderFactory.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/AbstractClassLoaderFactory.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/AbstractClassLoaderFactory.java?rev=407834&r1=407833&r2=407834&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/AbstractClassLoaderFactory.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/AbstractClassLoaderFactory.java
Fri May 19 09:00:40 2006
@@ -27,17 +27,6 @@
 
 import javax.servlet.ServletContext;
 
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-import org.apache.avalon.framework.thread.ThreadSafe;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceResolver;
-import org.apache.excalibur.source.TraversableSource;
-
 /**
  * Abstract implementation of {@link ClassLoaderFactory}. It accepts both class directory
and jar
  * directory configurations.
@@ -55,109 +44,11 @@
  *   <exclude-classes pattern="org.apache.cocoon.transformation.**"/>
  * &/lt;classpath>
  * </pre>
+ * @version $Id$
+ * @since 2.2
  */
 public abstract class AbstractClassLoaderFactory
-    implements ClassLoaderFactory,
-               Serviceable,
-               ThreadSafe,
-               Disposable {
-
-    protected ServiceManager manager;
-    protected SourceResolver resolver;
-
-    /**
-     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
-     */
-    public void service(ServiceManager manager) throws ServiceException {
-        this.manager = manager;
-        this.resolver = (SourceResolver)manager.lookup(SourceResolver.ROLE);
-    }
-
-    private void ensureIsDirectory(Source src) throws Exception {
-        if (!src.exists()) {
-            throw new Exception(src.getURI() + " doesn't exist");
-        } else if (!(src instanceof TraversableSource) || !((TraversableSource)src).isCollection())
{
-            throw new Exception(src.getURI() + " is not a directory");
-        }
-    }
-
-    /**
-     * @see org.apache.cocoon.components.classloader.ClassLoaderFactory#createClassLoader(java.lang.ClassLoader,
org.apache.avalon.framework.configuration.Configuration)
-     */
-    public ClassLoader createClassLoader(ClassLoader parent, Configuration config)
-    throws ConfigurationException {
-        final ClassLoaderConfiguration configBean = new ClassLoaderConfiguration();
-        final Configuration[] children = config.getChildren();
-        for (int i = 0; i < children.length; i++) {
-            final Configuration child = children[i];
-            final String name = child.getName();
-            if ("class-dir".equals(name)) {
-                configBean.addClassDirectory(child.getAttribute("src"));
-            } else if ("lib-dir".equals(name)) {
-                configBean.addLibDirectory(child.getAttribute("src"));
-            } else if ("include-classes".equals(name)) {
-                configBean.addInclude(child.getAttribute("pattern"));
-            } else if ("exclude-classes".equals(name)) {
-                configBean.addExclude(child.getAttribute("pattern"));
-            } else {
-                throw new ConfigurationException("Unexpected element " + name + " at " +
child.getLocation());
-            }
-        }
-        try {
-            return this.createClassLoader(parent, configBean);
-        } catch(ConfigurationException ce) {
-            throw ce;
-        } catch(Exception e) {
-            throw new ConfigurationException("Error creating class loader.", e);
-        }
-    }
-
-    protected ClassLoader createClassLoader(ClassLoader parent, ClassLoaderConfiguration
config)
-    throws Exception {
-        final List urlList = new ArrayList();
-        Iterator i;
-        // process class directories
-        i = config.getClassDirectories().iterator();
-        while ( i.hasNext() ) {
-            // A class dir: simply add its URL
-            final String directory = (String)i.next();
-            Source src = null;
-            try {
-                src = resolver.resolveURI(directory);
-                ensureIsDirectory(src);
-                urlList.add(new URL(src.getURI()));
-            } finally {
-                this.resolver.release(src);
-            }
-        }
-
-        // process lib directories
-        i = config.getLibDirectories().iterator();
-        while ( i.hasNext() ) {
-            // A lib dir: scan for all jar and zip it contains
-            final String directory = (String)i.next();
-            Source src = null;
-            try {
-                src = resolver.resolveURI(directory);
-                ensureIsDirectory(src);
-                Iterator iter = ((TraversableSource)src).getChildren().iterator();
-                while (iter.hasNext()) {
-                    Source childSrc = (Source)iter.next();
-                    String childURI = childSrc.getURI();
-                    resolver.release(childSrc);
-                    if (childURI.endsWith(".jar") || childURI.endsWith(".zip")) {
-                        urlList.add(new URL(childURI));
-                    }
-                }
-            } finally {
-                this.resolver.release(src);
-            }
-        }
-
-        URL[] urls = (URL[])urlList.toArray(new URL[urlList.size()]);
-        
-        return this.createClassLoader(urls, config.getIncludes(), config.getExcludes(), parent);
-    }
+    implements ClassLoaderFactory {
 
     protected URL getUrl(ServletContext servletContext, String rootPath, String path) 
     throws MalformedURLException {
@@ -193,10 +84,10 @@
         return rootPath + path;        
     }
 
-    protected ClassLoader createClassLoader(ClassLoader              parent,
-                                            ClassLoaderConfiguration config,
-                                            ServletContext           servletContext,
-                                            String                   rootPath)
+    public ClassLoader createClassLoader(ClassLoader              parent,
+                                         ClassLoaderConfiguration config,
+                                         ServletContext           servletContext,
+                                         String                   rootPath)
     throws Exception {
         if ( rootPath == null ) {
             rootPath = "/";
@@ -267,14 +158,4 @@
         }
     }
 
-    /**
-     * @see org.apache.avalon.framework.activity.Disposable#dispose()
-     */
-    public void dispose() {
-        if ( this.manager != null ) {
-            this.manager.release(this.resolver);
-            this.resolver = null;
-            this.manager = null;
-        }
-    }
 }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderConfiguration.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderConfiguration.java?rev=407834&r1=407833&r2=407834&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderConfiguration.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderConfiguration.java
Fri May 19 09:00:40 2006
@@ -22,6 +22,7 @@
 /**
  * The configuration for a {@link ClassLoaderFactory}.
  * @version $Id$
+ * @since 2.2
  */
 public class ClassLoaderConfiguration {
 

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderFactory.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderFactory.java?rev=407834&r1=407833&r2=407834&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderFactory.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderFactory.java
Fri May 19 09:00:40 2006
@@ -16,18 +16,22 @@
  */
 package org.apache.cocoon.components.classloader;
 
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
+import javax.servlet.ServletContext;
 
 /**
  * A <code>ClassLoader</code> factory, setting up the classpath given a
  * &lt;classpath&gt; configuration.
  *
  * @version $Id$
+ * @since 2.2
  */
 public interface ClassLoaderFactory {
 
     final static String ROLE = ClassLoaderFactory.class.getName();
-    
-    ClassLoader createClassLoader(ClassLoader parent, Configuration config) throws ConfigurationException;
+
+    ClassLoader createClassLoader(ClassLoader              parent,
+                                  ClassLoaderConfiguration config,
+                                  ServletContext           servletContext,
+                                  String                   rootPath)
+    throws Exception;
 }

Added: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderUtils.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderUtils.java?rev=407834&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderUtils.java
(added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderUtils.java
Fri May 19 09:00:40 2006
@@ -0,0 +1,50 @@
+/* 
+ * Copyright 2006 The Apache Software Foundation
+ * Licensed  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.cocoon.components.classloader;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+
+/**
+ * Utility class for converting Avalon based Configuration into a {@link ClassLoaderConfiguration}.
+ * @version $Id$
+ * @since 2.2
+ */
+public abstract class ClassLoaderUtils {
+
+    public static ClassLoaderConfiguration createConfiguration(Configuration config)
+    throws ConfigurationException {
+        final ClassLoaderConfiguration configBean = new ClassLoaderConfiguration();
+        final Configuration[] children = config.getChildren();
+        for (int i = 0; i < children.length; i++) {
+            final Configuration child = children[i];
+            final String name = child.getName();
+            if ("class-dir".equals(name)) {
+                configBean.addClassDirectory(child.getAttribute("src"));
+            } else if ("lib-dir".equals(name)) {
+                configBean.addLibDirectory(child.getAttribute("src"));
+            } else if ("include-classes".equals(name)) {
+                configBean.addInclude(child.getAttribute("pattern"));
+            } else if ("exclude-classes".equals(name)) {
+                configBean.addExclude(child.getAttribute("pattern"));
+            } else {
+                throw new ConfigurationException("Unexpected element " + name + " at " +
child.getLocation());
+            }
+        }
+        return configBean;
+    }
+}

Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderUtils.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoader.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoader.java?rev=407834&r1=407833&r2=407834&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoader.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoader.java
Fri May 19 09:00:40 2006
@@ -30,6 +30,7 @@
  * before it checks its parent. In addition it can be configured with includes and excludes.
  *
  * @version $Id$
+ * @since 2.2
  */
 public class DefaultClassLoader extends URLClassLoader {
 

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoaderFactory.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoaderFactory.java?rev=407834&r1=407833&r2=407834&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoaderFactory.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/DefaultClassLoaderFactory.java
Fri May 19 09:00:40 2006
@@ -22,6 +22,7 @@
 /**
  * @see AbstractClassLoaderFactory
  * @version $Id$
+ * @since 2.2
  */
 public class DefaultClassLoaderFactory
     extends AbstractClassLoaderFactory {

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoader.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoader.java?rev=407834&r1=407833&r2=407834&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoader.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoader.java
Fri May 19 09:00:40 2006
@@ -24,6 +24,7 @@
 
 /**
  * @version $Id$
+ * @since 2.2
  */
 public class ReloadingClassLoader extends DefaultClassLoader {
 

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoaderFactory.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoaderFactory.java?rev=407834&r1=407833&r2=407834&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoaderFactory.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ReloadingClassLoaderFactory.java
Fri May 19 09:00:40 2006
@@ -22,6 +22,7 @@
 /**
  * @see AbstractClassLoaderFactory
  * @version $Id$
+ * @since 2.2
  */
 public class ReloadingClassLoaderFactory extends AbstractClassLoaderFactory {
 

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java?rev=407834&r1=407833&r2=407834&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryFactoryImpl.java
Fri May 19 09:00:40 2006
@@ -20,7 +20,9 @@
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.cocoon.ProcessingUtil;
 import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.components.classloader.ClassLoaderConfiguration;
 import org.apache.cocoon.components.classloader.ClassLoaderFactory;
+import org.apache.cocoon.components.classloader.ClassLoaderUtils;
 import org.apache.cocoon.core.Settings;
 import org.apache.cocoon.environment.Request;
 import org.apache.excalibur.source.SourceResolver;
@@ -48,7 +50,7 @@
     }
 
     public ClassLoader createClassLoader(Context sitemapContext,
-                                            Configuration config)
+                                         Configuration config)
     throws Exception {
         // we don't create a new class loader if there is no new configuration
         if ( config == null ) {
@@ -60,9 +62,12 @@
                 ClassLoaderFactory.ROLE);
 
         // Create a new classloader
+        ClassLoaderConfiguration configBean = ClassLoaderUtils.createConfiguration(config);
         ClassLoaderFactory clFactory = (ClassLoaderFactory)parentFactory.getBean(factoryRole);
         return clFactory.createClassLoader(Thread.currentThread().getContextClassLoader(),
-                                           config);
+                                           configBean,
+                                           null,
+                                           null);
     }
 
     /**



Mime
View raw message