##### Coverage Report - org.webmacro.engine.CrankyEvaluationExceptionHandler

Classes in this File | Line Coverage | Branch Coverage | Complexity
CrankyEvaluationExceptionHandler |
0% | 0/21
0% | 0/8
| 2.142857142857143;2.143

1 |  |
     /*
2 |  |
      * Copyright (C) 1998-2001 Semiotek Inc.  All Rights Reserved.
3 |  |
      *
4 |  |
      * Redistribution and use in source and binary forms, with or without
5 |  |
      * modification, are permitted under the terms of either of the following
6 |  |
      * Open Source licenses:
7 |  |
      *
8 |  |
      * The GNU General Public License, version 2, or any later version, as
9 |  |
      * published by the Free Software Foundation
10 |  |
      * (http://www.fsf.org/copyleft/gpl.html);
11 |  |
      *
12 |  |
      *  or
13 |  |
      *
14 |  |
      * The Semiotek Public License (http://webmacro.org/LICENSE.)
15 |  |
      *
16 |  |
      * This software is provided "as is", with NO WARRANTY, not even the
17 |  |
      * implied warranties of fitness to purpose, or merchantability. You
18 |  |
      * assume all risks and liabilities associated with its use.
19 |  |
      *
20 |  |
      * See www.webmacro.org for more information on the WebMacro project.
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 |  |
      * CrankyEvaluationExceptionHandler
35 |  |
      *
36 |  |
      * An implementation of EvaluationExceptionHandler which throws an exception
37 |  |
      * whenever it is called.  This will generally cause the exception to be
38 |  |
      * displayed to the user -- useful for debugging.
39 |  |
      *
40 |  |
      * @author Brian Goetz
41 |  |
      * @since 0.96
42 |  |
      */
43 |  |
44 |  |
     public class CrankyEvaluationExceptionHandler implements EvaluationExceptionHandler
45 |  |
     {
46 |  |
47 | 0 |
         static Logger _log =  LoggerFactory.getLogger(CrankyEvaluationExceptionHandler.class);
48 |  |
49 |  |
             public CrankyEvaluationExceptionHandler ()
50 | 0 |
         {
51 | 0 |
         }
52 |  |
53 |  |
         public CrankyEvaluationExceptionHandler (Broker b)
54 | 0 |
         {
55 | 0 |
             init(b, b.getSettings());
56 | 0 |
         }
57 |  |
58 |  |
         public void init (Broker b, Settings config)
59 |  |
         {
60 | 0 |
         }
61 |  |
62 |  |
         public void evaluate (Variable variable, Context context, Exception problem)
63 |  |
                 throws PropertyException
64 |  |
         {
65 |  |
66 |  |
             // if it's a PropertyException set the current context location
67 | 0 |
             if (problem instanceof PropertyException)
68 |  |
             {
69 | 0 |
                 ((PropertyException) problem)
70 |  |
                         .setContextLocation(context.getCurrentLocation());
71 |  |
             }
72 |  |
             else
73 |  |
             {
74 |  |
                 // else, wrap it
75 | 0 |
                 problem = new PropertyException("Error evaluating $"
76 |  |
                         + variable.getVariableName(),
77 |  |
                         problem,
78 |  |
                         context.getCurrentLocation());
79 |  |
             }
80 |  |
81 |  |
82 |  |
             // log it
83 | 0 |
             if (_log != null)
84 | 0 |
                 _log.warn("Error evaluating $" + variable.getVariableName(), problem);
85 |  |
86 |  |
87 |  |
             // and rethrow it
88 | 0 |
             throw (PropertyException) problem;
89 |  |
         }
90 |  |
91 |  |
         public String expand (Variable variable, Context context, Exception problem)
92 |  |
                 throws PropertyException
93 |  |
         {
94 |  |
95 |  |
             // if it's a PropertyException set the current context location
96 | 0 |
             if (problem instanceof PropertyException)
97 |  |
             {
98 | 0 |
                 ((PropertyException) problem)
99 |  |
                         .setContextLocation(context.getCurrentLocation());
100 |  |
             }
101 |  |
             else
102 |  |
             {
103 |  |
                 // else, wrap it
104 | 0 |
                 problem = new PropertyException("Error expanding $"
105 |  |
                         + variable.getVariableName(),
106 |  |
                         problem,
107 |  |
                         context.getCurrentLocation());
108 |  |
             }
109 |  |
110 |  |
111 |  |
             // log it
112 | 0 |
             if (_log != null)
113 | 0 |
                 _log.warn("Error expanding $" + variable.getVariableName(), problem);
114 |  |
115 |  |
116 |  |
             // and rethrow it
117 | 0 |
             throw (PropertyException) problem;
118 |  |
119 |  |
         }
120 |  |
121 |  |
122 |  |
         public String warningString (String warningText) throws PropertyException
123 |  |
         {
124 | 0 |
             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 |  |