Here is an attempt at a JdkCompat implementation. There are 2 classes, JdkCompat which is the base support class and Jdk14Compat which extends JdkCompat.

The patch is in JdkCompat.txt for WebappClassloader and build.xml. I manually edited the patch file to eliminate all the extra edits my text editor makes with respect to whitespace changes.

Everyone will call JdkCompat.getJdkCompat() to get a JdkCompat instance. When JdkCompat is statically initialized, it determines which implementation to load. Currently, it performs a check on System.getProperty("java.version"). If the property starts with 1.4 then the Jdk14Compat class is loaded. Otherwise, the default JdkCompat will be loaded.

So, this has the side effect that when jdk1.5(and beyond) comes out - this will load the wrong version of the class. Should I ignore that issue for now or create a better comparison?


-Tim

Costin Manolache wrote:
Tim Funk wrote:

To get functionality like jdkCompat (and looking at tomcat3), it looks
like something similar to the following would need added to the existing
jakarta-tomcat-catalina/catalina/build.xml:
------------------------------------------
  <exclude name="org/apache/catalina/util/compat/JdkCompat14.java"
           unless="jdk.1.4.present"/>
------------------------------------------
Where would jdkCompat live with respect to package name? Does it belong
in catalina? (org.apache.catalina.util.compat.ClassXXX)

I would place it in j-t-c/util, even in o.a.tomcat.util.compat ( but with a
different name than jkd11compat class in 3.3 ).

This kind of code is very common.
/*
 * $Header:   $
 * $Revision:   $
 * $Date:  $
 * ====================================================================
 *
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 1999 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution, if
 *    any, must include the following acknowlegement:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowlegement may appear in the software itself,
 *    if and wherever such third-party acknowlegements normally appear.
 *
 * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
 *    Foundation" must not be used to endorse or promote products derived
 *    from this software without prior written permission. For written
 *    permission, please contact [EMAIL PROTECTED]
 *
 * 5. Products derived from this software may not be called "Apache"
 *    nor may "Apache" appear in their names without prior written
 *    permission of the Apache Group.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 *
 * [Additional notices, if required by prior licensing conditions]
 *
 */

package org.apache.catalina.util;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.net.MalformedURLException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 *  See JdkCompat. This is an extension of that class for Jdk1.4 support.
 *
 *  @author Tim Funk
 */
public class Jdk14Compat extends JdkCompat {
    // -------------------------------------------------------------- Constants

    // ------------------------------------------------------- Static Variables
    static Log logger = LogFactory.getLog(Jdk14Compat.class);

    // ----------------------------------------------------------- Constructors
    /**
     *  Default no-arg constructor
     */
    protected Jdk14Compat() {
    }


    // --------------------------------------------------------- Public Methods

    /**
     *  Return the URI for the given file. Originally created for
     *  o.a.c.loader.WebappClassLoader
     *
     *  @param File to wrap into URI
     *  @return A URI as a URL
     */
    public URL getURI(File file)
        throws MalformedURLException {

        File realFile = file;
        try {
            realFile = realFile.getCanonicalFile();
        } catch (IOException e) {
            // Ignore
        }

        return realFile.toURI().toURL();
    }


 }
/*
 * $Header:   $
 * $Revision:   $
 * $Date:  $
 * ====================================================================
 *
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 1999 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution, if
 *    any, must include the following acknowlegement:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowlegement may appear in the software itself,
 *    if and wherever such third-party acknowlegements normally appear.
 *
 * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
 *    Foundation" must not be used to endorse or promote products derived
 *    from this software without prior written permission. For written
 *    permission, please contact [EMAIL PROTECTED]
 *
 * 5. Products derived from this software may not be called "Apache"
 *    nor may "Apache" appear in their names without prior written
 *    permission of the Apache Group.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 *
 * [Additional notices, if required by prior licensing conditions]
 *
 */

package org.apache.catalina.util;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.MalformedURLException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *  General-purpose utility to provide backward-compatibility and JDK
 *  independence. This allow use of JDK1.3 ( or higher ) facilities if
 *  available, while maintaining the code compatible with older VMs.
 *
 *  The goal is to make backward-compatiblity reasonably easy.
 *
 *  The base class supports JDK1.3 behavior.
 *
 *  @author Tim Funk
 */
public class JdkCompat {
    // -------------------------------------------------------------- Constants
    public static final String JDK14_CLASS = "org.apache.catalina.util.Jdk14Compat";

    // ------------------------------------------------------- Static Variables
    /**
     *  The static instance holder.
     */
    static JdkCompat jdkCompat;

    /**
     *  Commons logger wrapper
     */
    static Log logger = LogFactory.getLog(JdkCompat.class);

    static {
        try {
            String version   = System.getProperty("java.version");
            if (version.startsWith("1.4")) {
                jdkCompat = (JdkCompat)Class.forName(JDK14_CLASS).newInstance();
            } else {
                jdkCompat = new JdkCompat();
            }
        } catch (ClassNotFoundException cnfe) {
            jdkCompat = new JdkCompat();
        } catch(Throwable e) {
            logger.error("O crap - I don't know what just happened!",e);
        }
    }




    // ----------------------------------------------------------- Constructors
    /**
     *  Default no-arg constructor
     */
    protected JdkCompat() {
    }


    // --------------------------------------------------------- Public Methods
    /**
     * Get a compatibiliy helper class.
     */
    public static JdkCompat getJdkCompat() {
        return jdkCompat;
    }

    /**
     *  Return the URI for the given file. Originally created for
     *  o.a.c.loader.WebappClassLoader
     *
     *  @param File to wrap into URI
     *  @return A URI as a URL
     */
    public URL getURI(File file)
        throws MalformedURLException {

        File realFile = file;
        try {
            realFile = realFile.getCanonicalFile();
        } catch (IOException e) {
            // Ignore
        }

        return realFile.toURL();
    }


 }
Index: catalina/build.xml
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-catalina/catalina/build.xml,v
retrieving revision 1.38
diff -u -r1.38 build.xml
--- catalina/build.xml  16 Jan 2003 22:42:09 -0000      1.38
+++ catalina/build.xml  4 Feb 2003 02:03:57 -0000
@@ -627,6 +627,9 @@
       <exclude name="org/apache/naming/factory/MailSessionFactory.java"/>
       <exclude name="org/apache/naming/factory/SendMailFactory.java"/>
       <exclude name="org/apache/catalina/launcher/**"/>
+
+      <exclude name="org/apache/catalina/util/Jdk14Compat.java"
+               unless="jdk.1.4.present"/>
     </javac>
 
     <!-- Copy static resource files -->
@@ -678,6 +681,8 @@
        unless="compile.jmx"/>
       <exclude name="org/apache/catalina/launcher/**"
        unless="compile.launcher"/>
+      <exclude name="org/apache/catalina/util/Jdk14Compat.java"
+               unless="jdk.1.4.present"/>
     </javac>
 
     <!-- Copy static resource files -->
Index: catalina/src/share/org/apache/catalina/loader/WebappClassLoader.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/loader/WebappClassLoader.java,v
retrieving revision 1.13
diff -u -r1.13 WebappClassLoader.java
--- catalina/src/share/org/apache/catalina/loader/WebappClassLoader.java        13 Nov 
2002 00:36:25 -0000      1.13
+++ catalina/src/share/org/apache/catalina/loader/WebappClassLoader.java        4 Feb 
+2003 02:04:02 -0000
@@ -102,6 +102,8 @@
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleListener;
 
+import org.apache.catalina.util.JdkCompat;
+
 import org.apache.naming.JndiPermission;
 import org.apache.naming.resources.ResourceAttributes;
 import org.apache.naming.resources.Resource;
@@ -1948,14 +1950,7 @@
     protected URL getURI(File file)
         throws MalformedURLException {
 
-        File realFile = file;
-        try {
-            realFile = realFile.getCanonicalFile();
-        } catch (IOException e) {
-            // Ignore
-        }
-        return realFile.toURI().toURL();
-
+        return JdkCompat.getJdkCompat().getURI(file);
     }
 
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to