KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > management > data > jdk > StackTraceElementFormat


1 /**
2 * Copyright (c) 2004-2005 jManage.org
3 *
4 * This is a free software; you can redistribute it and/or
5 * modify it under the terms of the license at
6 * http://www.jmanage.org.
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */

14 package org.jmanage.core.management.data.jdk;
15
16 import org.jmanage.core.management.data.DataFormat;
17
18 import javax.management.openmbean.CompositeData JavaDoc;
19
20 /**
21  * Formatter for java.lang.StackTraceElement. It recieved CompositeData
22  * representation of StackTraceElement. Returns a string like:
23  * <br/><br/>
24  * <i>java.lang.Thread.sleep(Native Method)</i>
25  * <i>JConsoleTest.main(JConsoleTest.java:13)</i>
26  * <p>
27  * Date: Dec 9, 2005
28  * @author Rakesh Kalra
29  */

30 public class StackTraceElementFormat implements DataFormat {
31
32     public String JavaDoc format(Object JavaDoc data) {
33         CompositeData JavaDoc[] compositeData = (CompositeData JavaDoc[])data;
34         StringBuffer JavaDoc stackTrace = new StringBuffer JavaDoc();
35         for(int i=0; i<compositeData.length; i++){
36             if(i > 0)
37                 stackTrace.append("\n");
38             stackTrace.append(format(compositeData[i]));
39         }
40         return stackTrace.toString();
41     }
42
43     private String JavaDoc format(CompositeData JavaDoc compositeData){
44         StringBuffer JavaDoc stackTraceElement = new StringBuffer JavaDoc(" ");
45         stackTraceElement.append((String JavaDoc)compositeData.get("className"));
46         stackTraceElement.append('.');
47         stackTraceElement.append(compositeData.get("methodName"));
48         stackTraceElement.append('(');
49         Boolean JavaDoc nativeMethod = (Boolean JavaDoc)compositeData.get("nativeMethod");
50         if(!nativeMethod.booleanValue()){
51             stackTraceElement.append(compositeData.get("fileName"));
52             stackTraceElement.append(':');
53             stackTraceElement.append(compositeData.get("lineNumber"));
54         }else{
55             stackTraceElement.append("Native Method");
56         }
57         stackTraceElement.append(')');
58         return stackTraceElement.toString();
59     }
60 }
61
Popular Tags