Coverage Report - org.webmacro.PropertyException
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertyException
43%
7/16
16%
1/6
1.263
PropertyException$InvalidTypeException
0%
0/2
N/A
1.263
PropertyException$NoSuchMethodException
100%
5/5
N/A
1.263
PropertyException$NoSuchMethodWithArgumentsException
100%
5/5
N/A
1.263
PropertyException$NoSuchPropertyException
100%
5/5
N/A
1.263
PropertyException$NoSuchVariableException
100%
3/3
N/A
1.263
PropertyException$NullToStringException
100%
3/3
N/A
1.263
PropertyException$NullValueException
100%
3/3
N/A
1.263
PropertyException$RestrictedMethodException
0%
0/5
N/A
1.263
PropertyException$RestrictedPropertyException
0%
0/5
N/A
1.263
PropertyException$UndefinedVariableException
100%
10/10
50%
1/2
1.263
PropertyException$VoidValueException
40%
2/5
N/A
1.263
 
 1  
 /*
 2  
  * Copyright (C) 1998-2000 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;
 25  
 
 26  
 /**
 27  
  * A PropertyException indicates some failure to evaluate a
 28  
  * property in a context or against some other object. For
 29  
  * example, if you attempted to introspect for a value that
 30  
  * does not exist, or access a non-existant value in a context,
 31  
  * or access a protected or private field.<p>
 32  
  *
 33  
  * PropertyExceptions that make their way through one of the core
 34  
  * EvaluationExceptionHandlers have their context location set
 35  
  * (line and column numbers from template).
 36  
  *
 37  
  * @author Marcel Huijkman
 38  
  *
 39  
  * @version        27-07-2002
 40  
  */
 41  
 public class PropertyException extends ContextException
 42  
 {
 43  
         private static final long serialVersionUID = 1L;
 44  
 
 45  58
         private String _message = null;
 46  
 
 47  
     public PropertyException (String reason)
 48  
     {
 49  48
         super(reason);
 50  48
     }
 51  
 
 52  
     public PropertyException (String reason, Throwable e)
 53  
     {
 54  10
         super(reason, e);
 55  10
     }
 56  
 
 57  
     public PropertyException (String reason, Throwable e, String contextLocation)
 58  
     {
 59  0
         super(reason, e);
 60  0
         setContextLocation(contextLocation);
 61  0
     }
 62  
 
 63  
     public void setMessage (String message)
 64  
     {
 65  0
         _message = message;
 66  0
     }
 67  
 
 68  
     public String getMessage ()
 69  
     {
 70  96
         if (_message == null)
 71  
         {
 72  96
             return super.getMessage();
 73  
         }
 74  
         else
 75  
         {
 76  0
             String msg = _message;
 77  0
             if (getContextLocation() != null && msg != null)
 78  
             {
 79  0
                 msg += " at " + getContextLocation();
 80  
             }
 81  0
             return msg;
 82  
         }
 83  
     }
 84  
     // Subclasses
 85  
 
 86  
 
 87  
     /**
 88  
      * NoSuchVariableException indicates that a variable did not exist
 89  
      * in the context against which it was being evaluated.
 90  
      */
 91  
 
 92  
     public static class NoSuchVariableException extends PropertyException
 93  
     {
 94  
 
 95  
         /**
 96  
                  * 
 97  
                  */
 98  
                 private static final long serialVersionUID = 1L;
 99  
                 public String variableName;
 100  
 
 101  
         public NoSuchVariableException (String variableName)
 102  
         {
 103  1
             super("No such variable: $" + variableName);
 104  
 
 105  1
             this.variableName = variableName;
 106  1
         }
 107  
     }
 108  
 
 109  
 
 110  
     /**
 111  
      * NullStringException indicates that a variable exists but its
 112  
      * .toString() method returns null
 113  
      */
 114  
 
 115  
     public static class NullToStringException extends PropertyException
 116  
     {
 117  
 
 118  
         /**
 119  
                  * 
 120  
                  */
 121  
                 private static final long serialVersionUID = 1L;
 122  
                 public String variableName;
 123  
 
 124  
         public NullToStringException (String variableName)
 125  
         {
 126  2
             super(".toString() returns null: $" + variableName);
 127  
 
 128  2
             this.variableName = variableName;
 129  2
         }
 130  
     }
 131  
 
 132  
 
 133  
     /**
 134  
      * NullValueException indicates that a variable or property
 135  
      * exists, but evaluated to null in the context against which it
 136  
      * was being evaluated.
 137  
      */
 138  
     public static class NullValueException extends PropertyException
 139  
     {
 140  
 
 141  
         /**
 142  
                  * 
 143  
                  */
 144  
                 private static final long serialVersionUID = 1L;
 145  
                 public String variableName;
 146  
 
 147  
         public NullValueException (String variableName)
 148  
         {
 149  6
             super("Value is null: $" + variableName);
 150  6
             this.variableName = variableName;
 151  6
         }
 152  
     }
 153  
 
 154  
 
 155  
     /**
 156  
      * NoSuchMethodException indicates that the variable did not have
 157  
      * the requested method.
 158  
      */
 159  
     public static class NoSuchMethodException extends PropertyException
 160  
     {
 161  
 
 162  
         /**
 163  
                  * 
 164  
                  */
 165  
                 private static final long serialVersionUID = 1L;
 166  
                 public String methodName, className, variableName;
 167  
 
 168  
         public NoSuchMethodException (String methodName,
 169  
                                       String variableName,
 170  
                                       String className)
 171  
         {
 172  8
             super("No public method " + methodName + " on variable $"
 173  
                     + variableName + " of class " + className);
 174  8
             this.variableName = variableName;
 175  8
             this.className = className;
 176  8
             this.methodName = methodName;
 177  8
         }
 178  
     }
 179  
 
 180  
     /**
 181  
      * NoSuchMethodWithArgumentsException indicates that the variable did not have
 182  
      * the a method with the request name and argument list
 183  
      */
 184  
     public static class NoSuchMethodWithArgumentsException extends PropertyException
 185  
     {
 186  
 
 187  
         /**
 188  
                  * 
 189  
                  */
 190  
                 private static final long serialVersionUID = 1L;
 191  
                 public String methodName;
 192  
         public String className;
 193  
         public String arguments;
 194  
 
 195  
         public NoSuchMethodWithArgumentsException (String methodName,
 196  
                                                    String className,
 197  
                                                    String arguments)
 198  
         {
 199  6
             super("No public method " + methodName + "(" + arguments + ")"
 200  
                     + " in class " + className);
 201  6
             this.className = className;
 202  6
             this.methodName = methodName;
 203  6
             this.arguments = arguments;
 204  6
         }
 205  
     }
 206  
 
 207  
     /**
 208  
      * NoSuchPropertyException indicates that the variable did not have
 209  
      * the requested property.
 210  
      */
 211  
     public static class NoSuchPropertyException extends PropertyException
 212  
     {
 213  
 
 214  
         /**
 215  
                  * 
 216  
                  */
 217  
                 private static final long serialVersionUID = 1L;
 218  
                 String _propertyName;
 219  
         String _className;
 220  
         String _variableName;
 221  
 
 222  
         public NoSuchPropertyException (String propertyName,
 223  
                                         String variableName,
 224  
                                         String className)
 225  
         {
 226  7
             super("No public property " + propertyName + " on variable $"
 227  
                     + variableName + " of class " + className);
 228  7
             this._variableName = variableName;
 229  7
             this._className = className;
 230  7
             this._propertyName = propertyName;
 231  7
         }
 232  
     }
 233  
 
 234  
 
 235  
     /**
 236  
      * VoidValueException indicates that someone tried to use the return
 237  
      * value of a void method
 238  
      */
 239  
     public static class VoidValueException extends PropertyException
 240  
     {
 241  
 
 242  
         /**
 243  
                  * 
 244  
                  */
 245  
                 private static final long serialVersionUID = 1L;
 246  
                 String _variableName;
 247  
 
 248  
 
 249  
         public VoidValueException ()
 250  
         {
 251  3
             super("Attempt to use void value");
 252  3
         }
 253  
 
 254  
         public VoidValueException (String variableName)
 255  
         {
 256  0
             super("Variable $" + variableName + " has a void value ");
 257  0
             this._variableName = variableName;
 258  0
         }
 259  
     }
 260  
 
 261  
     /**
 262  
      * Exception thrown when a Variable isn't of the specified class type.
 263  
      */
 264  
     public static class InvalidTypeException extends PropertyException
 265  
     {
 266  
 
 267  
         /**
 268  
                  * 
 269  
                  */
 270  
                 private static final long serialVersionUID = 1L;
 271  
 
 272  
                 public InvalidTypeException (String variableName, Class clazz)
 273  
         {
 274  0
             super("$" + variableName + " is not a " + clazz.getName());
 275  0
         }
 276  
     }
 277  
 
 278  
 
 279  
     /**
 280  
      * RestrictedPropertyException indicates that the requested property may
 281  
      * not be invoked from a template due to security constraints
 282  
      */
 283  
     public static class RestrictedPropertyException extends PropertyException
 284  
     {
 285  
 
 286  
         /**
 287  
                  * 
 288  
                  */
 289  
                 private static final long serialVersionUID = 1L;
 290  
                 String _propertyName;
 291  
         String _className;
 292  
         String _variableName;
 293  
 
 294  
         public RestrictedPropertyException (String propertyName,
 295  
                                             String variableName,
 296  
                                             String className)
 297  
         {
 298  0
             super("The property " + propertyName + " on variable $"
 299  
                     + variableName + " of class " + className + " may not be accessed from a template.");
 300  0
             this._variableName = variableName;
 301  0
             this._className = className;
 302  0
             this._propertyName = propertyName;
 303  0
         }
 304  
     }
 305  
 
 306  
 
 307  
     /**
 308  
      * RestrictedMethodException indicates that the requested method may
 309  
      * not be invoked from a template due to security constraints
 310  
      */
 311  
     public static class RestrictedMethodException extends PropertyException
 312  
     {
 313  
 
 314  
         /**
 315  
                  * 
 316  
                  */
 317  
                 private static final long serialVersionUID = 1L;
 318  
                 String _propertyName;
 319  
         String _className;
 320  
         String _variableName;
 321  
 
 322  
         public RestrictedMethodException (String propertyName,
 323  
                                           String variableName,
 324  
                                           String className)
 325  
         {
 326  0
             super("The method " + propertyName + " on variable $"
 327  
                     + variableName + " of class " + className + " may not be accessed from a template.");
 328  0
             this._variableName = variableName;
 329  0
             this._className = className;
 330  0
             this._propertyName = propertyName;
 331  0
         }
 332  
     }
 333  
 
 334  
     /**
 335  
      * UndefinedVariableException indicates that the variable did not have
 336  
      * the requested method.
 337  
      */
 338  
     public static class UndefinedVariableException extends PropertyException
 339  
     {
 340  
 
 341  
         /**
 342  
                  * 
 343  
                  */
 344  
                 private static final long serialVersionUID = 1L;
 345  10
                 private String _msg = "Attempted to dereference an undefined variable.";
 346  
 
 347  
         public UndefinedVariableException ()
 348  
         {
 349  10
             super(null);
 350  10
         }
 351  
 
 352  
         /**
 353  
          * Overloaded to return the <code>reason</code> specified during construction
 354  
          * <b>plus</b> the context location, if any.
 355  
          */
 356  
         public String getMessage ()
 357  
         {
 358  20
             String msg = _msg;
 359  20
             String loc = getContextLocation();
 360  20
             if (loc != null)
 361  
             {
 362  20
                 msg += " at " + loc;
 363  
             }
 364  20
             return msg;
 365  
         }
 366  
 
 367  
         public void setMessage (String msg)
 368  
         {
 369  10
             _msg = msg;
 370  10
         }
 371  
     }
 372  
 
 373  
 }