1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
package org.webmacro.engine; |
25 | |
|
26 | |
import org.slf4j.Logger; |
27 | |
import org.slf4j.LoggerFactory; |
28 | |
import org.webmacro.Broker; |
29 | |
import org.webmacro.Context; |
30 | |
import org.webmacro.PropertyException; |
31 | |
import org.webmacro.util.Settings; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public class CrankyEvaluationExceptionHandler implements EvaluationExceptionHandler |
45 | |
{ |
46 | |
|
47 | 5 | static Logger _log = LoggerFactory.getLogger(CrankyEvaluationExceptionHandler.class); |
48 | |
|
49 | |
public CrankyEvaluationExceptionHandler () |
50 | 21 | { |
51 | 21 | } |
52 | |
|
53 | |
public CrankyEvaluationExceptionHandler (Broker b) |
54 | 26 | { |
55 | 26 | init(b, b.getSettings()); |
56 | 26 | } |
57 | |
|
58 | |
public void init (Broker b, Settings config) |
59 | |
{ |
60 | 26 | } |
61 | |
|
62 | |
public void evaluate (Variable variable, Context context, Exception problem) |
63 | |
throws PropertyException |
64 | |
{ |
65 | |
|
66 | |
|
67 | 6 | if (problem instanceof PropertyException) |
68 | |
{ |
69 | 6 | ((PropertyException) problem) |
70 | |
.setContextLocation(context.getCurrentLocation()); |
71 | |
} |
72 | |
else |
73 | |
{ |
74 | |
|
75 | 0 | problem = new PropertyException("Error evaluating $" |
76 | |
+ variable.getVariableName(), |
77 | |
problem, |
78 | |
context.getCurrentLocation()); |
79 | |
} |
80 | |
|
81 | |
|
82 | |
|
83 | 6 | if (_log != null) |
84 | 6 | _log.warn("Error evaluating $" + variable.getVariableName(), problem); |
85 | |
|
86 | |
|
87 | |
|
88 | 6 | throw (PropertyException) problem; |
89 | |
} |
90 | |
|
91 | |
public String expand (Variable variable, Context context, Exception problem) |
92 | |
throws PropertyException |
93 | |
{ |
94 | |
|
95 | |
|
96 | 13 | if (problem instanceof PropertyException) |
97 | |
{ |
98 | 13 | ((PropertyException) problem) |
99 | |
.setContextLocation(context.getCurrentLocation()); |
100 | |
} |
101 | |
else |
102 | |
{ |
103 | |
|
104 | 0 | problem = new PropertyException("Error expanding $" |
105 | |
+ variable.getVariableName(), |
106 | |
problem, |
107 | |
context.getCurrentLocation()); |
108 | |
} |
109 | |
|
110 | |
|
111 | |
|
112 | 13 | if (_log != null) |
113 | 13 | _log.warn("Error expanding $" + variable.getVariableName(), problem); |
114 | |
|
115 | |
|
116 | |
|
117 | 13 | throw (PropertyException) problem; |
118 | |
|
119 | |
} |
120 | |
|
121 | |
|
122 | |
public String warningString (String warningText) throws PropertyException |
123 | |
{ |
124 | 1 | throw new PropertyException("Evaluation warning: " + warningText); |
125 | |
} |
126 | |
|
127 | |
|
128 | |
public String errorString (String errorText) throws PropertyException |
129 | |
{ |
130 | 0 | throw new PropertyException("Evaluation error: " + errorText); |
131 | |
} |
132 | |
} |
133 | |
|