KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > common > exceptions > driver > protocol > SerializableStackTraceElement


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2005 Emic Networks
4  * Contact: sequoia@continuent.org
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Initial developer(s): Marc Herbert
19  * Contributor(s): ______________________.
20  */

21
22 package org.continuent.sequoia.common.exceptions.driver.protocol;
23
24 import java.io.IOException JavaDoc;
25
26 import org.continuent.sequoia.common.stream.DriverBufferedInputStream;
27 import org.continuent.sequoia.common.stream.DriverBufferedOutputStream;
28
29 /**
30  * This class re-implements StackTraceElement of JDK 1.5, as a brute force
31  * workaround for the forgotten constructor in JDK 1.4.
32  *
33  * @author <a HREF="mailto:Marc.Herbert@emicnetworks.com">Marc Herbert</a>
34  * @version 1.0
35  */

36 public class SerializableStackTraceElement
37 {
38   private String JavaDoc declaringClass;
39   private String JavaDoc methodName;
40   private String JavaDoc fileName;
41   private int lineNumber;
42
43 // /**
44
// * This is the constructor forgotten in 1.4 (and available in 1.5)
45
// * the only reason why we exist.
46
// */
47
// private SerializableStackTraceElement(String declaringClass, String methodName,
48
// String fileName, int lineNumber)
49
// {
50
// this.declaringClass = declaringClass;
51
// this.methodName = methodName;
52
// this.fileName = fileName;
53
// this.lineNumber = lineNumber;
54
//
55
// }
56

57   /**
58    * Constructs/converts a standard StackTraceElement (non-serializable in 1.4)
59    * into a SerializableStackTraceElement.
60    *
61    * @param st the element to convert.
62    */

63   public SerializableStackTraceElement(StackTraceElement JavaDoc st)
64   {
65     this.declaringClass = st.getClassName();
66     this.methodName = st.getMethodName();
67     this.fileName = st.getFileName();
68     this.lineNumber = st.getLineNumber();
69   }
70
71   /**
72    * Deserializes a new <code>SerializableStackTraceElement</code> from the
73    * stream
74    *
75    * @param in the stream to read from
76    * @throws IOException stream error
77    */

78   public SerializableStackTraceElement(DriverBufferedInputStream in) throws IOException JavaDoc
79   {
80     declaringClass = in.readLongUTF();
81     methodName = in.readLongUTF();
82     fileName = in.readLongUTF();
83     lineNumber = in.readInt();
84   }
85
86   /**
87    * Serializes the object to the given stream.
88    *
89    * @param out the stream to send the object to
90    * @throws IOException stream error
91    */

92   public void sendToStream(DriverBufferedOutputStream out) throws IOException JavaDoc
93   {
94     out.writeLongUTF(declaringClass);
95     out.writeLongUTF(methodName);
96     out.writeLongUTF(fileName);
97     out.writeInt(lineNumber);
98
99   }
100
101   /**
102    *
103    * @see StackTraceElement#getLineNumber()
104    */

105   public int getLineNumber()
106   {
107     return lineNumber;
108   }
109
110   /**
111    *
112    * @see StackTraceElement#getClassName()
113    */

114   public String JavaDoc getClassName()
115   {
116     return declaringClass;
117   }
118
119   /**
120    *
121    * @see StackTraceElement#getMethodName()
122    */

123   public String JavaDoc getMethodName()
124   {
125     return methodName;
126   }
127
128   /**
129    *
130    * @see StackTraceElement#isNativeMethod()
131    */

132   public boolean isNativeMethod()
133   {
134     return lineNumber == -2;
135   }
136
137   /**
138    *
139    * @see StackTraceElement#toString()
140    */

141   public String JavaDoc toString()
142   {
143     return getClassName()
144         + "."
145         + methodName
146         + (isNativeMethod() ? "(Native Method)" : (fileName != null
147             && lineNumber >= 0
148             ? "(" + fileName + ":" + lineNumber + ")"
149             : (fileName != null ? "(" + fileName + ")" : "(Unknown Source)")));
150   }
151
152 }
153
Popular Tags