KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > common > exceptions > driver > protocol > SerializableStackTraceElement


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2005 Emic Networks
4  * Contact: c-jdbc@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or any later
9  * version.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19  *
20  * Initial developer(s): Marc Herbert
21  * Contributor(s): ______________________.
22  */

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

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

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

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

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

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

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

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

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

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

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