KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > execution > EtlExecutorException


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package scriptella.execution;
17
18 import scriptella.configuration.Location;
19 import scriptella.core.EtlCancelledException;
20 import scriptella.core.ExceptionInterceptor;
21 import scriptella.expression.Expression;
22 import scriptella.spi.ProviderException;
23 import scriptella.util.StringUtils;
24
25 import java.io.PrintWriter JavaDoc;
26 import java.io.StringWriter JavaDoc;
27
28
29 /**
30  * Thrown on script execution failure
31  *
32  * @author Fyodor Kupolov
33  * @version 1.0
34  */

35 public class EtlExecutorException extends Exception JavaDoc {
36     private ProviderException lastProvider;
37     private Throwable JavaDoc lastExpression;
38     private Location lastElementLocation;
39     private String JavaDoc message;
40     private boolean cancelled;
41
42     public EtlExecutorException(Throwable JavaDoc cause) {
43         super(cause);
44
45         for (Throwable JavaDoc ex = cause; ex != null; ex = ex.getCause()) {
46             if (isExpression(ex)) {
47                 lastExpression = ex;
48             }
49
50             if (ex instanceof ProviderException) {
51                 ProviderException providerEx = (ProviderException) ex;
52                 lastProvider = providerEx;
53             }
54
55             if (ex instanceof ExceptionInterceptor.ExecutionException) {
56                 lastElementLocation = ((ExceptionInterceptor.ExecutionException) ex).getLocation();
57             }
58
59             if (ex instanceof EtlCancelledException || ex instanceof InterruptedException JavaDoc) {
60                 cancelled = true;
61             }
62         }
63
64         final StringWriter JavaDoc out = new StringWriter JavaDoc();
65         PrintWriter JavaDoc pw = new PrintWriter JavaDoc(out); //Use print writer to handle line separators
66
if ((lastProvider==null || lastElementLocation==null) && cause != null && cause.getMessage() != null) {
67             pw.println(cause.getMessage());
68         }
69         if (lastElementLocation != null) {
70             pw.print("Location: ");
71             pw.println(lastElementLocation);
72         }
73         if (lastProvider != null) {
74             pw.print(lastProvider.getProviderName() + " provider exception: ");
75             pw.println(lastProvider.getMessage());
76
77             if (lastProvider.getErrorStatement() != null) {
78                 pw.print("Error statement: ");
79                 pw.print(lastProvider.getErrorStatement());
80                 pw.println();
81             }
82             pw.println("Error codes: " + lastProvider.getErrorCodes());
83             Throwable JavaDoc nativeException = lastProvider.getNativeException();
84             if (nativeException != null) {
85                 pw.print("Driver exception: ");
86                 pw.print(nativeException.toString());
87                 pw.println();
88             }
89         }
90         if (lastExpression != null) {
91             pw.print("Expression exception: ");
92             pw.print(lastExpression.getMessage());
93             pw.println();
94         }
95         this.message = StringUtils.consoleFormat(out.toString());
96     }
97
98
99     public String JavaDoc getMessage() {
100         return message;
101     }
102
103     public ProviderException getLastProvider() {
104         return lastProvider;
105     }
106
107     public Throwable JavaDoc getLastExpression() {
108         return lastExpression;
109     }
110
111     public Location getLastElementLocation() {
112         return lastElementLocation;
113     }
114
115     public boolean isCancelled() {
116         return cancelled;
117     }
118
119     private static boolean isExpression(final Throwable JavaDoc cause) {
120         return cause instanceof Expression.ParseException ||
121                 cause instanceof Expression.EvaluationException;
122     }
123
124 }
125
Popular Tags