sylvain     02/03/20 03:00:06

  Modified:    src/java/org/apache/cocoon/servlet CocoonServlet.java
                        ParanoidClassLoader.java
  Log:
  - ParanoidClassLoader is now really paranoid
  - reflect the move of cocoon.xconf to WEB-INF
  - make the servlet more robust against missing parameters
  
  Revision  Changes    Path
  1.18      +17 -9     
xml-cocoon2/src/java/org/apache/cocoon/servlet/CocoonServlet.java
  
  Index: CocoonServlet.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/servlet/CocoonServlet.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- CocoonServlet.java        17 Mar 2002 18:00:36 -0000      1.17
  +++ CocoonServlet.java        20 Mar 2002 11:00:06 -0000      1.18
  @@ -118,7 +118,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Berin Loritsch</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Leo Sutic</a>
  - * @version CVS $Id: CocoonServlet.java,v 1.17 2002/03/17 18:00:36 vgritsenko Exp $
  + * @version CVS $Id: CocoonServlet.java,v 1.18 2002/03/20 11:00:06 sylvain Exp $
    */
   public class CocoonServlet extends HttpServlet {
   
  @@ -376,8 +376,9 @@
   
           requestFactoryClass = conf.getInitParameter("request-factory");
           if (requestFactoryClass == null) {
  +            requestFactoryClass = 
"org.apache.cocoon.components.request.MaybeUploadRequestFactoryImpl";
               if (log.isDebugEnabled()) {
  -                log.debug("request-factory was not set - defaulting to null.");
  +                log.debug("request-factory was not set - defaulting to " + 
requestFactoryClass);
               }
           }
   
  @@ -789,9 +790,9 @@
   
           if (configFileName == null) {
               if (log.isWarnEnabled()) {
  -                log.warn("Servlet initialization argument 'configurations' not 
specified, attempting to use '/cocoon.xconf'");
  +                log.warn("Servlet initialization argument 'configurations' not 
specified, attempting to use '/WEB-INF/cocoon.xconf'");
               }
  -            usedFileName = "/cocoon.xconf";
  +            usedFileName = "/WEB-INF/cocoon.xconf";
           } else {
               usedFileName = configFileName;
           }
  @@ -800,14 +801,21 @@
               log.debug("Using configuration file: " + usedFileName);
           }
   
  +        URL result;
           try {
  -            return this.servletContext.getResource(usedFileName);
  +            result = this.servletContext.getResource(usedFileName);
           } catch (Exception mue) {
  -            if (log.isErrorEnabled()) {
  -                log.error("Servlet initialization argument 'configurations' not 
found at " + usedFileName, mue);
  -            }
  -            throw new ServletException("Servlet initialization argument 
'configurations' not found at " + usedFileName);
  +            String msg = "Init parameter 'configurations' is invalid : " + 
usedFileName;
  +            log.error(msg, mue);
  +            throw new ServletException(msg, mue);
  +        }
  +        
  +        if (result == null) {
  +            String msg = "Init parameter 'configuration' doesn't name an existing 
resource : " + usedFileName;
  +            log.error(msg);
  +            throw new ServletException(msg);
           }
  +        return result;
       }
   
       /**
  
  
  
  1.5       +51 -33    
xml-cocoon2/src/java/org/apache/cocoon/servlet/ParanoidClassLoader.java
  
  Index: ParanoidClassLoader.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/servlet/ParanoidClassLoader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ParanoidClassLoader.java  22 Feb 2002 07:03:55 -0000      1.4
  +++ ParanoidClassLoader.java  20 Mar 2002 11:00:06 -0000      1.5
  @@ -50,19 +50,22 @@
   */
   package org.apache.cocoon.servlet;
   
  -import java.io.File;
   import java.io.IOException;
  +import java.io.File;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.net.URLClassLoader;
   import java.net.URLStreamHandlerFactory;
  +import java.util.Enumeration;
  +import java.util.NoSuchElementException;
   
   /**
    * The <code>ParanoidClassLoader</code> reverses the search order for
    * classes.  It checks this classloader before it checks its parent.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Berin Loritsch</a>
  - * @version CVS $Id: ParanoidClassLoader.java,v 1.4 2002/02/22 07:03:55 cziegeler 
Exp $
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Sylvain Wallez</a>
  + * @version CVS $Id: ParanoidClassLoader.java,v 1.5 2002/03/20 11:00:06 sylvain Exp 
$
    */
   
   public class ParanoidClassLoader extends URLClassLoader {
  @@ -133,39 +136,39 @@
        * <code>ClassLoader</code> spec.  We use it to work around
        * inconsistent class loaders from third party vendors.
        *
  -     * @param name of class
  -     * @throws ClassNotFoundException
  -     */
  -    public final Class loadClass(final String name) throws ClassNotFoundException {
  -        Class resource = null;
  -
  -        try {
  -            resource = super.loadClass(name);
  -        } catch (ClassNotFoundException t) {
  -            if (this.parent != null) {
  -                this.parent.loadClass(name);
  -            } else {
  -                throw t;
  +     * @param     name the name of the class
  +     * @param     resolve if <code>true</code> then resolve the class
  +     * @return    the resulting <code>Class</code> object
  +     * @exception ClassNotFoundException if the class could not be found
  +     */
  +    public final Class loadClass(String name, boolean resolve)
  +      throws ClassNotFoundException
  +    {
  +        // First check if it's already loaded
  +        Class clazz = findLoadedClass(name);
  +        
  +        if (clazz == null) {
  +            
  +            try {
  +                clazz = findClass(name);
  +            } catch (ClassNotFoundException cnfe) {
  +                if (this.parent != null) {
  +                     // Ask to parent ClassLoader (can also throw a CNFE).
  +                    clazz = this.parent.loadClass(name);
  +                } else {
  +                    // Propagate exception
  +                    throw cnfe;
  +                }
               }
           }
  -
  -        return resource;
  -    }
  -
  -    /**
  -     * Adds a new directory of class files.
  -     *
  -     * @param file for jar or directory
  -     * @throws IOException
  -     */
  -    public final void addDirectory(File file) throws IOException {
  -        try {
  -            this.addURL(file.getCanonicalFile().toURL());
  -        } catch (MalformedURLException mue) {
  -            throw new IOException("Could not add repository");
  +        
  +        if (resolve) {
  +            resolveClass(clazz);
           }
  +        
  +        return clazz;
       }
  -
  +    
       /**
        * Gets a resource from this <code>ClassLoader</class>.  If the
        * resource does not exist in this one, we check the parent.
  @@ -176,12 +179,27 @@
        * @param name of resource
        */
       public final URL getResource(final String name) {
  -        URL resource = super.getResource(name);
   
  -        if (this.parent != null && resource == null) {
  +        URL resource = findResource(name);
  +
  +        if (resource == null && this.parent != null) {
               resource = this.parent.getResource(name);
           }
   
           return resource;
  +    }
  +
  +    /**
  +     * Adds a new directory of class files.
  +     *
  +     * @param file for jar or directory
  +     * @throws IOException
  +     */
  +    public final void addDirectory(File file) throws IOException {
  +        try {
  +            this.addURL(file.getCanonicalFile().toURL());
  +        } catch (MalformedURLException mue) {
  +            throw new IOException("Could not add repository");
  +        }
       }
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to