01: /*
02: * StreamError.java
03: *
04: * Copyright (C) 2002-2004 Peter Graves
05: * $Id: StreamError.java,v 1.11 2004/03/05 16:02:23 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.lisp;
23:
24: public class StreamError extends LispError {
25: private final LispObject stream;
26: private final Throwable cause;
27:
28: public StreamError(Stream stream) {
29: this .stream = stream != null ? stream : NIL;
30: cause = null;
31: }
32:
33: public StreamError(LispObject initArgs) throws ConditionThrowable {
34: LispObject stream = NIL;
35: LispObject first, second;
36: while (initArgs != NIL) {
37: first = initArgs.car();
38: initArgs = initArgs.cdr();
39: second = initArgs.car();
40: initArgs = initArgs.cdr();
41: if (first == Keyword.STREAM)
42: stream = second;
43: }
44: this .stream = stream;
45: cause = null;
46: }
47:
48: public StreamError(Stream stream, String message) {
49: super (message);
50: this .stream = stream != null ? stream : NIL;
51: cause = null;
52: }
53:
54: public StreamError(Stream stream, Throwable cause) {
55: super ();
56: this .stream = stream != null ? stream : NIL;
57: this .cause = cause;
58: }
59:
60: public LispObject typeOf() {
61: return Symbol.STREAM_ERROR;
62: }
63:
64: public LispClass classOf() {
65: return BuiltInClass.STREAM_ERROR;
66: }
67:
68: public LispObject typep(LispObject type) throws ConditionThrowable {
69: if (type == Symbol.STREAM_ERROR)
70: return T;
71: if (type == BuiltInClass.STREAM_ERROR)
72: return T;
73: return super .typep(type);
74: }
75:
76: public String getMessage() {
77: if (cause != null) {
78: String message = cause.getMessage();
79: if (message != null && message.length() > 0)
80: return message;
81: }
82: return "Stream error.";
83: }
84:
85: // ### stream-error-stream
86: private static final Primitive1 STREAM_ERROR_STREAM = new Primitive1(
87: "stream-error-stream", "condition") {
88: public LispObject execute(LispObject arg)
89: throws ConditionThrowable {
90: try {
91: return ((StreamError) arg).stream;
92: } catch (ClassCastException e) {
93: return signal(new TypeError(arg, Symbol.STREAM_ERROR));
94: }
95: }
96: };
97: }
|