KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tomcat > util > compat > Jdk14Compat


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.tomcat.util.compat;
18
19 import java.io.File JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.net.MalformedURLException JavaDoc;
22 import java.net.URL JavaDoc;
23
24 //import org.apache.commons.logging.Log;
25
//import org.apache.commons.logging.LogFactory;
26

27
28 /**
29  * See JdkCompat. This is an extension of that class for Jdk1.4 support.
30  *
31  * @author Tim Funk
32  * @author Remy Maucherat
33  */

34 public class Jdk14Compat extends JdkCompat {
35     // -------------------------------------------------------------- Constants
36

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

40     // ----------------------------------------------------------- Constructors
41
/**
42      * Default no-arg constructor
43      */

44     protected Jdk14Compat() {
45     }
46
47
48     // --------------------------------------------------------- Public Methods
49

50     /**
51      * Return the URI for the given file. Originally created for
52      * o.a.c.loader.WebappClassLoader
53      *
54      * @param file The file to wrap into URI
55      * @return A URI as a URL
56      * @throws MalformedURLException Doh ;)
57      */

58     public URL JavaDoc getURI(File JavaDoc file)
59         throws MalformedURLException JavaDoc {
60
61         File JavaDoc realFile = file;
62         try {
63             realFile = realFile.getCanonicalFile();
64         } catch (IOException JavaDoc e) {
65             // Ignore
66
}
67
68         return realFile.toURI().toURL();
69     }
70
71
72     /**
73      * Return the maximum amount of memory the JVM will attempt to use.
74      */

75     public long getMaxMemory() {
76         return Runtime.getRuntime().maxMemory();
77     }
78
79
80     /**
81      * Print out a partial servlet stack trace (truncating at the last
82      * occurrence of javax.servlet.).
83      */

84     public String JavaDoc getPartialServletStackTrace(Throwable JavaDoc t) {
85         StringBuffer JavaDoc trace = new StringBuffer JavaDoc();
86         trace.append(t.toString()).append('\n');
87         StackTraceElement JavaDoc[] elements = t.getStackTrace();
88         int pos = elements.length;
89         for (int i = 0; i < elements.length; i++) {
90             if ((elements[i].getClassName().startsWith
91                  ("org.apache.catalina.core.ApplicationFilterChain"))
92                 && (elements[i].getMethodName().equals("internalDoFilter"))) {
93                 pos = i;
94             }
95         }
96         for (int i = 0; i < pos; i++) {
97             if (!(elements[i].getClassName().startsWith
98                   ("org.apache.catalina.core."))) {
99                 trace.append('\t').append(elements[i].toString()).append('\n');
100             }
101         }
102         return trace.toString();
103     }
104
105     public String JavaDoc [] split(String JavaDoc path, String JavaDoc pat) {
106         return path.split(pat);
107     }
108
109
110     /**
111      * Chains the <tt>wrapped</tt> throwable to the <tt>wrapper</tt> throwable.
112      *
113      * @param wrapper The wrapper throwable
114      * @param wrapped The throwable to be wrapped
115      */

116     public void chainException(Throwable JavaDoc wrapper, Throwable JavaDoc wrapped) {
117         wrapper.initCause(wrapped);
118     }
119
120  }
121
Popular Tags