You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2006/05/19 12:33:36 UTC

svn commit: r407765 - in /cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader: AbstractClassLoaderFactory.java ClassLoaderConfiguration.java

Author: cziegeler
Date: Fri May 19 03:33:35 2006
New Revision: 407765

URL: http://svn.apache.org/viewvc?rev=407765&view=rev
Log:
Start moving awaw from dependencies to Avalon

Added:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderConfiguration.java   (with props)
Modified:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/AbstractClassLoaderFactory.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=407765&r1=407764&r2=407765&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 03:33:35 2006
@@ -81,64 +81,93 @@
     /**
      * @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 List urlList = new ArrayList();
-        Configuration[] children = config.getChildren();
+    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++) {
-            Configuration child = children[i];
-            String name = child.getName();
+            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, null);
+                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 {
-                // A class dir: simply add its URL
-                if ("class-dir".equals(name)) {
-                    src = resolver.resolveURI(child.getAttribute("src"));
-                    ensureIsDirectory(src, child.getLocation());
-                    urlList.add(new URL(src.getURI()));
-                
-                // A lib dir: scan for all jar and zip it contains
-                } else if ("lib-dir".equals(name)) {
-                    src = resolver.resolveURI(child.getAttribute("src"));
-                    ensureIsDirectory(src, child.getLocation());
-                    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));
-                        }
+                src = resolver.resolveURI(directory);
+                ensureIsDirectory(src, null);
+                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));
                     }
-                } else if (!"include-classes".equals(name) && !"exclude-classes".equals(name) ) {
-                    throw new ConfigurationException("Unexpected element " + name + " at " + child.getLocation());
                 }
-            } catch(ConfigurationException ce) {
-                throw ce;
-            } catch(Exception e) {
-                throw new ConfigurationException("Error loading " + name + " at " + child.getLocation(), e);
             } finally {
-                resolver.release(src);
-                src = null;                
+                this.resolver.release(src);
             }
         }
-        
+
         URL[] urls = (URL[])urlList.toArray(new URL[urlList.size()]);
-        int[][] includes = compilePatterns(config.getChildren("include-classes"));
-        int[][] excludes = compilePatterns(config.getChildren("exclude-classes"));
+        int[][] includes = compilePatterns(config.getIncludes());
+        int[][] excludes = compilePatterns(config.getExcludes());
         
         return this.createClassLoader(urls, includes, excludes, parent);
     }
 
     protected abstract ClassLoader createClassLoader(URL[] urls, int[][] includes, int[][] excludes, ClassLoader parent);
 
-    private int[][] compilePatterns(Configuration[] patternConfigs) throws ConfigurationException {
-        if (patternConfigs.length == 0) {
+    private int[][] compilePatterns(List patternConfigs) throws ConfigurationException {
+        if (patternConfigs.size() == 0) {
             return null;
         }
+        final int[][] patterns = new int[patternConfigs.size()][];
 
-        int[][] patterns = new int[patternConfigs.length][];
-
-        for (int i = 0; i < patternConfigs.length; i++) {
-            patterns[i] = WildcardHelper.compilePattern(patternConfigs[i].getAttribute("pattern"));
+        for (int i = 0; i < patternConfigs.size(); i++) {
+            patterns[i] = WildcardHelper.compilePattern((String)patternConfigs.get(i));
         }
 
         return patterns;

Added: 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=407765&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderConfiguration.java (added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/classloader/ClassLoaderConfiguration.java Fri May 19 03:33:35 2006
@@ -0,0 +1,65 @@
+/* 
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The configuration for a {@link ClassLoaderFactory}.
+ * @version $Id$
+ */
+public class ClassLoaderConfiguration {
+
+    protected final List includes = new ArrayList();
+    protected final List excludes = new ArrayList();
+    protected final List classDirectories = new ArrayList();
+    protected final List libDirectories = new ArrayList();
+
+    public void addInclude(String include) {
+        this.includes.add(include);
+    }
+
+    public void addExclude(String include) {
+        this.excludes.add(include);
+    }
+
+    public void addClassDirectory(String include) {
+        this.classDirectories.add(include);
+    }
+
+    public void addLibDirectory(String include) {
+        this.libDirectories.add(include);
+    }
+
+    public List getClassDirectories() {
+        return classDirectories;
+    }
+
+    public List getLibDirectories() {
+        return libDirectories;
+    }
+    
+    public List getExcludes() {
+        return excludes;
+    }
+    
+    public List getIncludes() {
+        return includes;
+    }
+
+}

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

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