Coverage Report - pt.digitalis.dif.dem.objects.parameters.errors.ParameterError
 
Classes in this File Line Coverage Branch Coverage Complexity
ParameterError
0%
0/58
0%
0/4
1,095
 
 1  0
 /**
 2  
  * 2007, Digitalis Informatica. All rights reserved. Distribuicao e Gestao de Informatica, Lda. Estrada de Paco de Arcos
 3  
  * num.9 - Piso -1 2780-666 Paco de Arcos Telefone: (351) 21 4408990 Fax: (351) 21 4408999 http://www.digitalis.pt
 4  
  */
 5  
 package pt.digitalis.dif.dem.objects.parameters.errors;
 6  
 
 7  
 import java.util.ArrayList;
 8  
 import java.util.List;
 9  
 
 10  
 import pt.digitalis.dif.dem.objects.parameters.constraints.IParameterConstraint;
 11  
 import pt.digitalis.dif.dem.objects.parameters.constraints.ParameterConstraintResult;
 12  
 import pt.digitalis.dif.dem.objects.parameters.rules.IParameterRule;
 13  
 import pt.digitalis.dif.dem.objects.parameters.validators.IParameterValidator;
 14  
 import pt.digitalis.dif.utils.ObjectFormatter;
 15  
 
 16  
 /**
 17  
  * Defines a type that represents an error on a parameter.
 18  
  * 
 19  
  * @author Rodrigo Gonçalves <a href="mailto:rgoncalves@digitalis.pt">rgoncalves@digitalis.pt</a><br/>
 20  
  * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a>
 21  
  */
 22  
 public class ParameterError {
 23  
 
 24  
     /** The constraint that caused the error */
 25  
     private IParameterConstraint constraint;
 26  
 
 27  
     /** The parameter error IDs */
 28  0
     private List<String> errorIDs = new ArrayList<String>();
 29  
 
 30  
     /** The type of the error */
 31  
     private ParameterErrorType errorType;
 32  
 
 33  
     /** The generated exception if it is the case */
 34  
     private Exception exception;
 35  
 
 36  
     /** Always report these errors */
 37  0
     private boolean forceShowError = false;
 38  
 
 39  
     /** The id of the error. ID of the constrain/validator or key that identifies the other kind of error */
 40  
     private String id;
 41  
 
 42  
     /**
 43  
      * The message that describes the error
 44  
      */
 45  
     private String message;
 46  
 
 47  
     /** The rule that caused the error */
 48  
     private IParameterRule<?> rule;
 49  
 
 50  
     /** The validator that caused the error */
 51  
     private IParameterValidator validator;
 52  
 
 53  
     /**
 54  
      * Constructor
 55  
      */
 56  
     public ParameterError()
 57  
     {
 58  0
         super();
 59  0
     }
 60  
 
 61  
     /**
 62  
      * Constructor
 63  
      * 
 64  
      * @param constraintId
 65  
      *            The constraint Id
 66  
      * @param constraintResult
 67  
      *            The constraint result
 68  
      */
 69  0
     public ParameterError(String constraintId, ParameterConstraintResult constraintResult)
 70  
     {
 71  0
         if (constraintResult.getLanguage() != null)
 72  
         {
 73  0
             this.message = constraintResult.getConstraint().validationErrorMessage(constraintResult.getLanguage());
 74  
         }
 75  
         else
 76  
         {
 77  0
             this.message = constraintResult.getConstraint().validationErrorMessage();
 78  
         }
 79  
 
 80  0
         this.errorType = ParameterErrorType.CONSTRAINT;
 81  0
         this.id = constraintId;
 82  0
         this.constraint = constraintResult.getConstraint();
 83  0
         this.validator = null;
 84  0
         if (constraintResult.getErrorIDs() != null)
 85  
         {
 86  0
             this.errorIDs.addAll(constraintResult.getErrorIDs());
 87  
         }
 88  0
     }
 89  
 
 90  
     /**
 91  
      * Constructor.
 92  
      * 
 93  
      * @param message
 94  
      *            the error message.
 95  
      * @param errorType
 96  
      *            the error type
 97  
      */
 98  0
     public ParameterError(String message, ParameterErrorType errorType)
 99  
     {
 100  0
         this.message = message;
 101  0
         this.errorType = errorType;
 102  0
         this.id = null;
 103  0
         this.constraint = null;
 104  0
         this.validator = null;
 105  0
     }
 106  
 
 107  
     /**
 108  
      * Inspector for the error constraint.
 109  
      * 
 110  
      * @return the constraint the constraint
 111  
      */
 112  
     public IParameterConstraint getConstraint()
 113  
     {
 114  0
         return constraint;
 115  
     }
 116  
 
 117  
     /**
 118  
      * Inspector for the 'errorIDs' attribute.
 119  
      * 
 120  
      * @return the errorIDs value
 121  
      */
 122  
     public List<String> getErrorIDs()
 123  
     {
 124  0
         return errorIDs;
 125  
     }
 126  
 
 127  
     /**
 128  
      * Inspector for the error type.
 129  
      * 
 130  
      * @return the errorType the error type
 131  
      */
 132  
     public ParameterErrorType getErrorType()
 133  
     {
 134  0
         return errorType;
 135  
     }
 136  
 
 137  
     /**
 138  
      * Inspector for the error exception.
 139  
      * 
 140  
      * @return the exception the error exception
 141  
      */
 142  
     public Exception getException()
 143  
     {
 144  0
         return exception;
 145  
     }
 146  
 
 147  
     /**
 148  
      * Inspector for the error ID.
 149  
      * 
 150  
      * @return the id the error ID.
 151  
      */
 152  
     public String getId()
 153  
     {
 154  0
         return id;
 155  
     }
 156  
 
 157  
     /**
 158  
      * Inspector for the error message.
 159  
      * 
 160  
      * @return the message the error message
 161  
      */
 162  
     public String getMessage()
 163  
     {
 164  0
         return message;
 165  
     }
 166  
 
 167  
     /**
 168  
      * Inspector for the 'rule' attribute.
 169  
      * 
 170  
      * @return the rule value
 171  
      */
 172  
     public IParameterRule<?> getRule()
 173  
     {
 174  0
         return rule;
 175  
     }
 176  
 
 177  
     /**
 178  
      * Inspector for the validator.
 179  
      * 
 180  
      * @return the validator
 181  
      */
 182  
     public IParameterValidator getValidator()
 183  
     {
 184  0
         return validator;
 185  
     }
 186  
 
 187  
     /**
 188  
      * Inspector for the 'forceShowError' attribute.
 189  
      * 
 190  
      * @return the forceShowError value
 191  
      */
 192  
     public boolean isForceShowError()
 193  
     {
 194  0
         return forceShowError;
 195  
     }
 196  
 
 197  
     /**
 198  
      * Modifier for the constraint.
 199  
      * 
 200  
      * @param id
 201  
      *            the id of the constraint
 202  
      * @param constraint
 203  
      *            the constraint to set
 204  
      */
 205  
     public void setConstraint(String id, IParameterConstraint constraint)
 206  
     {
 207  0
         this.id = id;
 208  0
         this.constraint = constraint;
 209  0
     }
 210  
 
 211  
     /**
 212  
      * Modifier for the 'errorIDs' attribute.
 213  
      * 
 214  
      * @param errorIDs
 215  
      *            the new errorIDs value to set
 216  
      */
 217  
     public void setErrorIDs(List<String> errorIDs)
 218  
     {
 219  0
         this.errorIDs = errorIDs;
 220  0
     }
 221  
 
 222  
     /**
 223  
      * Modifier for the exception.
 224  
      * 
 225  
      * @param exception
 226  
      *            the exception to set
 227  
      */
 228  
     public void setException(Exception exception)
 229  
     {
 230  0
         this.exception = exception;
 231  0
     }
 232  
 
 233  
     /**
 234  
      * Modifier for the 'forceShowError' attribute.
 235  
      * 
 236  
      * @param forceShowError
 237  
      *            the new forceShowError value to set
 238  
      */
 239  
     public void setForceShowError(boolean forceShowError)
 240  
     {
 241  0
         this.forceShowError = forceShowError;
 242  0
     }
 243  
 
 244  
     /**
 245  
      * Inspector for the error ID.
 246  
      * 
 247  
      * @param newID
 248  
      *            the new ID.
 249  
      */
 250  
     public void setId(String newID)
 251  
     {
 252  0
         this.id = newID;
 253  0
     }
 254  
 
 255  
     /**
 256  
      * Modifier for the 'message' attribute.
 257  
      * 
 258  
      * @param message
 259  
      *            the new message value to set
 260  
      */
 261  
     public void setMessage(String message)
 262  
     {
 263  0
         this.message = message;
 264  0
     }
 265  
 
 266  
     /**
 267  
      * Modifier for the 'rule' attribute.
 268  
      * 
 269  
      * @param rule
 270  
      *            the new rule value to set
 271  
      */
 272  
     public void setRule(IParameterRule<?> rule)
 273  
     {
 274  0
         this.rule = rule;
 275  0
     }
 276  
 
 277  
     /**
 278  
      * Modifier for the validator.
 279  
      * 
 280  
      * @param id
 281  
      *            the id of the validator
 282  
      * @param validator
 283  
      *            the validator to set
 284  
      */
 285  
     public void setValidator(String id, IParameterValidator validator)
 286  
     {
 287  0
         this.id = id;
 288  0
         this.validator = validator;
 289  0
     }
 290  
 
 291  
     /**
 292  
      * @see java.lang.Object#toString()
 293  
      */
 294  
     @Override
 295  
     public String toString()
 296  
     {
 297  0
         ObjectFormatter formatter = new ObjectFormatter();
 298  0
         formatter.addItem("Message", message);
 299  0
         formatter.addItem("Error Type", errorType);
 300  0
         formatter.addItemIfNotNull("ID", id);
 301  0
         formatter.addItemIfNotNull("Constraint", constraint);
 302  0
         formatter.addItemIfNotNull("Validator", validator);
 303  0
         formatter.addItemIfNotNull("Exception", exception);
 304  
 
 305  0
         return formatter.getFormatedObject();
 306  
     }
 307  
 }