1
2
3
4
5
6
7 package org.astrogrid.dataservice.queriers.status;
8
9 import java.io.PrintWriter;
10 import java.io.StringWriter;
11 import org.astrogrid.dataservice.queriers.QuerierPluginException;
12 import org.astrogrid.query.QueryException;
13 import org.astrogrid.query.QueryState;
14
15 public class QuerierError extends QuerierStatus implements QuerierClosed
16 {
17 Throwable cause;
18 String errorMsg;
19
20 public QuerierError(QuerierStatus previousStatus, String givenMessage, Throwable causeOfError) {
21 super(previousStatus, ERROR);
22 this.errorMsg = givenMessage;
23
24
25 if ((causeOfError != null) && (causeOfError.getCause() != null) && (
26 (causeOfError instanceof QuerierPluginException) ||
27 (causeOfError instanceof QueryException)
28 ))
29
30 {
31 addDetail(causeOfError.toString());
32 addDetail("Caused By: ");
33 causeOfError = causeOfError.getCause();
34 }
35
36 this.cause = causeOfError;
37 StringWriter sw = new StringWriter();
38 cause.printStackTrace(new PrintWriter(sw));
39 addDetail(sw.toString());
40 }
41
42 public QueryState getState() { return QueryState.ERROR; }
43
44 public Throwable getCause() {
45 return cause;
46 }
47
48 public String message() {
49 return errorMsg;
50 }
51
52 public String toString() {
53 return super.toString()+": "+cause.getMessage()+" ("+errorMsg+")";
54 }
55
56 /*** Returns true */
57 public boolean isFinished() { return true; }
58
59 }
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96