01: // You can redistribute this software and/or modify it under the terms of
02: // the Ozone Library License version 1 published by ozone-db.org.
03: //
04: // The original code and portions created by SMB are
05: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
06: //
07: // $Id: DxException.java,v 1.1 2001/12/18 10:31:30 per_nyfelt Exp $
08:
09: package org.ozoneDB.DxLib;
10:
11: import java.lang.reflect.*;
12: import java.io.*;
13:
14: /**
15: * Diese Klasse dient dazu, ein Java-Exception in einem Stream zu schreiben
16: * bzw. daraus zu lesen. Das ist z.B. fuer Socket-Verbindungen nuetzlich.
17: *
18: *
19: * @author <a href="http://www.softwarebuero.de/">SMB</a>
20: * @version $Revision: 1.1 $Date: 2001/12/18 10:31:30 $
21: */
22: public class DxException extends DxObject implements Externalizable {
23:
24: final static long serialVersionUID = 1L;
25:
26: Throwable exc;
27: String msg;
28:
29: public DxException() {
30: msg = new String();
31: }
32:
33: public DxException(Throwable e) {
34: exc = e;
35: msg = new String(e.toString());
36: }
37:
38: public Throwable toExc() {
39: return exc;
40: }
41:
42: public String toString() {
43: return msg;
44: }
45:
46: public void writeExternal(ObjectOutput out) throws IOException {
47: try {
48: if (exc != null) {
49: out.writeUTF(exc.getClass().getName());
50: } else {
51: out.writeUTF("null");
52: }
53: out.writeUTF(msg);
54: } catch (Exception e) {
55: throw new IOException(e.toString());
56: }
57: }
58:
59: public void readExternal(ObjectInput in) throws IOException {
60: try {
61: String e = in.readUTF();
62: msg = in.readUTF();
63: if (e.compareTo("null") != 0) {
64: Class[] classes = new Class[1];
65: classes[0] = e.getClass();
66: Constructor constr = Class.forName(e).getConstructor(
67: classes);
68: if (constr != null) {
69: Object[] args = new Object[1];
70: args[0] = msg;
71: System.out.println(args[0]);
72: exc = (Throwable) constr.newInstance(args);
73: }
74: }
75: } catch (Exception e) {
76: throw new IOException(e.toString());
77: }
78: }
79: }
|