FileDocCategorySizeDatePackage
JdkCompat.javaAPI DocGlassfish v2 API7139Fri May 04 22:33:14 BST 2007org.apache.tomcat.util.compat

JdkCompat

public class JdkCompat extends Object
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

Fields Summary
static final String
JAVA14_SUPPORT
class providing java2 support
public static final String
JAVA_1_0
public static final String
JAVA_1_1
public static final String
JAVA_1_2
public static final String
JAVA_1_3
public static final String
JAVA_1_4
static String
javaVersion
static boolean
java2
static boolean
java14
static JdkCompat
jdkCompat
Constructors Summary
protected JdkCompat()
Default no-arg constructor

    
Methods Summary
public static java.lang.StringgetJavaVersion()
Return java version as a string


               
        
        return javaVersion;
    
public static org.apache.tomcat.util.compat.JdkCompatgetJdkCompat()
Get a compatibiliy helper class.

        return jdkCompat;
    
public longgetMaxMemory()
Return the maximum amount of memory the JVM will attempt to use.

        return (-1L);
    
public java.lang.StringgetPartialServletStackTrace(java.lang.Throwable t)
Print out a partial servlet stack trace (truncating at the last occurrence of javax.servlet.).

        StringWriter stackTrace = new StringWriter();
        t.printStackTrace(new PrintWriter(stackTrace));
        String st = stackTrace.toString();
        int i = st.lastIndexOf
            ("org.apache.catalina.core.ApplicationFilterChain.internalDoFilter");
        if (i > -1) {
            return st.substring(0, i - 4);
        } else {
            return st;
        }
    
public java.net.URLgetURI(java.io.File file)
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


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

        return realFile.toURL();
    
private static voidinit()

    
     
        init();
    
        try {
            javaVersion = JAVA_1_0;
            Class.forName("java.lang.Void");
            javaVersion = JAVA_1_1;
            Class.forName("java.lang.ThreadLocal");
            java2=true;
            javaVersion = JAVA_1_2;
            Class.forName("java.lang.StrictMath");
            javaVersion = JAVA_1_3;
            Class.forName("java.lang.CharSequence");
            javaVersion = JAVA_1_4;
            java14=true;
        } catch (ClassNotFoundException cnfe) {
            // swallow as we've hit the max class version that we have
        }
        if( java14 ) {
            try {
                Class c=Class.forName(JAVA14_SUPPORT);
                jdkCompat=(JdkCompat)c.newInstance();
            } catch( Exception ex ) {
                jdkCompat=new JdkCompat();
            }
        } else {
            jdkCompat=new JdkCompat();
            // Install jar handler if none installed
        }
    
public static booleanisJava14()

        return java14;
    
public static booleanisJava2()

        return java2;
    
public java.lang.String[]split(java.lang.String path, java.lang.String pat)
Splits a string into it's components.

param
path String to split
param
pat Pattern to split at
return
the components of the path

        Vector comps = new Vector();
        int pos = path.indexOf(pat);
        int start = 0;
        while( pos >= 0 ) {
            if(pos > start ) {
                String comp = path.substring(start,pos);
                comps.add(comp);
            }
            start = pos + pat.length();
            pos = path.indexOf(pat,start);
        }
        if( start < path.length()) {
            comps.add(path.substring(start));
        }
        String [] result = new String[comps.size()];
        for(int i=0; i < comps.size(); i++) {
            result[i] = (String)comps.elementAt(i);
        }
        return result;