KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > lisp > StreamError


1 /*
2  * StreamError.java
3  *
4  * Copyright (C) 2002-2004 Peter Graves
5  * $Id: StreamError.java,v 1.11 2004/03/05 16:02:23 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * 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 {
26     private final LispObject stream;
27     private final Throwable JavaDoc cause;
28
29     public StreamError(Stream stream)
30     {
31         this.stream = stream != null ? stream : NIL;
32         cause = null;
33     }
34
35     public StreamError(LispObject initArgs) throws ConditionThrowable
36     {
37         LispObject stream = NIL;
38         LispObject first, second;
39         while (initArgs != NIL) {
40             first = initArgs.car();
41             initArgs = initArgs.cdr();
42             second = initArgs.car();
43             initArgs = initArgs.cdr();
44             if (first == Keyword.STREAM)
45                 stream = second;
46         }
47         this.stream = stream;
48         cause = null;
49     }
50
51     public StreamError(Stream stream, String JavaDoc message)
52     {
53         super(message);
54         this.stream = stream != null ? stream : NIL;
55         cause = null;
56     }
57
58     public StreamError(Stream stream, Throwable JavaDoc cause)
59     {
60         super();
61         this.stream = stream != null ? stream : NIL;
62         this.cause = cause;
63     }
64
65     public LispObject typeOf()
66     {
67         return Symbol.STREAM_ERROR;
68     }
69
70     public LispClass classOf()
71     {
72         return BuiltInClass.STREAM_ERROR;
73     }
74
75     public LispObject typep(LispObject type) throws ConditionThrowable
76     {
77         if (type == Symbol.STREAM_ERROR)
78             return T;
79         if (type == BuiltInClass.STREAM_ERROR)
80             return T;
81         return super.typep(type);
82     }
83
84     public String JavaDoc getMessage()
85     {
86         if (cause != null) {
87             String JavaDoc message = cause.getMessage();
88             if (message != null && message.length() > 0)
89                 return message;
90         }
91         return "Stream error.";
92     }
93
94     // ### stream-error-stream
95
private static final Primitive1 STREAM_ERROR_STREAM =
96         new Primitive1("stream-error-stream", "condition")
97     {
98         public LispObject execute(LispObject arg) throws ConditionThrowable
99         {
100             try {
101                 return ((StreamError)arg).stream;
102             }
103             catch (ClassCastException JavaDoc e) {
104                 return signal(new TypeError(arg, Symbol.STREAM_ERROR));
105             }
106         }
107     };
108 }
109
Popular Tags