Coverage Report - ca.uhn.hl7v2.validation.AbstractValidationExceptionHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractValidationExceptionHandler
62%
10/16
66%
4/6
1.571
AbstractValidationExceptionHandler$1
100%
1/1
N/A
1.571
 
 1  
 /**
 2  
 The contents of this file are subject to the Mozilla Public License Version 1.1 
 3  
 (the "License"); you may not use this file except in compliance with the License. 
 4  
 You may obtain a copy of the License at http://www.mozilla.org/MPL/ 
 5  
 Software distributed under the License is distributed on an "AS IS" basis, 
 6  
 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 
 7  
 specific language governing rights and limitations under the License. 
 8  
 
 9  
 The Original Code is "AbstractValidationExceptionHandler.java".  Description: 
 10  
 "Abstract implementation of a ValidationExceptionHandler." 
 11  
 
 12  
 The Initial Developer of the Original Code is University Health Network. Copyright (C) 
 13  
 2012.  All Rights Reserved. 
 14  
 
 15  
 Contributor(s): ______________________________________. 
 16  
 
 17  
 Alternatively, the contents of this file may be used under the terms of the 
 18  
 GNU General Public License (the "GPL"), in which case the provisions of the GPL are 
 19  
 applicable instead of those above.  If you wish to allow use of your version of this 
 20  
 file only under the terms of the GPL and not to allow others to use your version 
 21  
 of this file under the MPL, indicate your decision by deleting  the provisions above 
 22  
 and replace  them with the notice and other provisions required by the GPL License.  
 23  
 If you do not delete the provisions above, a recipient may use your version of 
 24  
 this file under either the MPL or the GPL. 
 25  
  */
 26  
 package ca.uhn.hl7v2.validation;
 27  
 
 28  
 import ca.uhn.hl7v2.HapiContext;
 29  
 import ca.uhn.hl7v2.HapiContextSupport;
 30  
 
 31  
 /**
 32  
  * Abstract base class of a ValidationExceptionHandler that supports a validation subject. Concrete
 33  
  * implementations should inherit from this class.
 34  
  * 
 35  
  * @author Christian Ohr
 36  
  */
 37  
 public abstract class AbstractValidationExceptionHandler<R> extends HapiContextSupport implements
 38  
         ValidationExceptionHandler<R> {
 39  
 
 40  
     private Object subject;
 41  
 
 42  
     /**
 43  
      * @param context Hapi Context
 44  
      */
 45  
     public AbstractValidationExceptionHandler(HapiContext context) {
 46  235
         super(context);
 47  235
     }
 48  
 
 49  
     public void onExceptions(ValidationException... exceptions) {
 50  95
         for (ValidationException ve : exceptions) {
 51  5
                 switch (ve.getSeverity()) {
 52  
                         case ERROR:
 53  60
                                 error(ve);
 54  60
                                 break;
 55  
                         case INFO:
 56  0
                                 info(ve);
 57  0
                                 break;
 58  
                         case WARNING:
 59  0
                                 warning(ve);
 60  
                                 break;
 61  
                 }
 62  
         }
 63  35
     }
 64  
 
 65  
     /**
 66  
      * Called on ValidationExceptions with error severity
 67  
      * @param exception ValidationException
 68  
      */
 69  0
     public void error(final ValidationException exception) {}
 70  
 
 71  
     /**
 72  
      * Called on ValidationExceptions with warning severity
 73  
      * @param exception ValidationException
 74  
      */
 75  0
     public void warning(final ValidationException exception) {}
 76  
 
 77  
     /**
 78  
      * Called on ValidationExceptions with info severity
 79  
      * @param exception ValidationException
 80  
      */
 81  0
     public void info(final ValidationException exception) {}
 82  
 
 83  
     /**
 84  
      * Sets the object that is the target of validation. This is helpful
 85  
      * to be called to give this handler e.g. access to the original
 86  
      * message that has been validated.
 87  
      *
 88  
      * @param subject subject to be validated
 89  
      */
 90  
     public void setValidationSubject(Object subject) {
 91  195
         this.subject = subject;
 92  195
     }
 93  
 
 94  
     /**
 95  
      * @return the validation subject
 96  
      */
 97  
     public Object getValidationSubject() {
 98  55
         return subject;
 99  
     }
 100  
 
 101  
 }