Coverage Report - ca.uhn.hl7v2.validation.AbstractValidationExceptionHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractValidationExceptionHandler
84%
11/13
62%
5/8
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  
 import ca.uhn.hl7v2.Severity;
 31  
 
 32  
 /**
 33  
  * Abstract base class of a ValidationExceptionHandler that supports a validation subject. Concrete
 34  
  * implementations should inherit from this class.
 35  
  * 
 36  
  * @author Christian Ohr
 37  
  */
 38  
 public abstract class AbstractValidationExceptionHandler<R> extends HapiContextSupport implements
 39  
         ValidationExceptionHandler<R> {
 40  
 
 41  
     private Object subject;
 42  
 
 43  
     /**
 44  
      * @param context Hapi Context
 45  
      */
 46  
     public AbstractValidationExceptionHandler(HapiContext context) {
 47  37
         super(context);
 48  37
     }
 49  
 
 50  
     public void onExceptions(ValidationException... exceptions) {
 51  13
         for (ValidationException ve : exceptions) {
 52  8
             if (ve.getSeverity() == Severity.ERROR) error(ve);
 53  8
             if (ve.getSeverity() == Severity.WARNING) warning(ve);
 54  8
             if (ve.getSeverity() == Severity.ERROR) info(ve);
 55  
         }
 56  5
     }
 57  
 
 58  
     /**
 59  
      * Called on ValidationExceptions with error severity
 60  
      * @param exception ValidationException
 61  
      */
 62  0
     public void error(final ValidationException exception) {}
 63  
 
 64  
     /**
 65  
      * Called on ValidationExceptions with warning severity
 66  
      * @param exception ValidationException
 67  
      */
 68  0
     public void warning(final ValidationException exception) {}
 69  
 
 70  
     /**
 71  
      * Called on ValidationExceptions with info severity
 72  
      * @param exception ValidationException
 73  
      */
 74  1
     public void info(final ValidationException exception) {}
 75  
 
 76  
     /**
 77  
      * Sets the object that is the target of validation. This is helpful
 78  
      * to be called to give this handler e.g. access to the original
 79  
      * message that has been validated.
 80  
      *
 81  
      * @param subject subject to be validated
 82  
      */
 83  
     public void setValidationSubject(Object subject) {
 84  31
         this.subject = subject;
 85  31
     }
 86  
 
 87  
     /**
 88  
      * @return the validation subject
 89  
      */
 90  
     public Object getValidationSubject() {
 91  4
         return subject;
 92  
     }
 93  
 
 94  
 }