1 21 22 package org.armedbear.lisp; 23 24 public class StreamError extends LispError 25 { 26 private final LispObject stream; 27 private final Throwable 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 message) 52 { 53 super(message); 54 this.stream = stream != null ? stream : NIL; 55 cause = null; 56 } 57 58 public StreamError(Stream stream, Throwable 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 getMessage() 85 { 86 if (cause != null) { 87 String message = cause.getMessage(); 88 if (message != null && message.length() > 0) 89 return message; 90 } 91 return "Stream error."; 92 } 93 94 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 e) { 104 return signal(new TypeError(arg, Symbol.STREAM_ERROR)); 105 } 106 } 107 }; 108 } 109 | Popular Tags |