001/**
002The contents of this file are subject to the Mozilla Public License Version 1.1 
003(the "License"); you may not use this file except in compliance with the License. 
004You may obtain a copy of the License at http://www.mozilla.org/MPL/ 
005Software distributed under the License is distributed on an "AS IS" basis, 
006WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 
007specific language governing rights and limitations under the License. 
008
009The Original Code is "Validator.java".  Description: 
010"Interface for validating messages." 
011
012The Initial Developer of the Original Code is University Health Network. Copyright (C) 
0132012.  All Rights Reserved. 
014
015Contributor(s): ______________________________________. 
016
017Alternatively, the contents of this file may be used under the terms of the 
018GNU General Public License (the "GPL"), in which case the provisions of the GPL are 
019applicable instead of those above.  If you wish to allow use of your version of this 
020file only under the terms of the GPL and not to allow others to use your version 
021of this file under the MPL, indicate your decision by deleting  the provisions above 
022and replace  them with the notice and other provisions required by the GPL License.  
023If you do not delete the provisions above, a recipient may use your version of 
024this file under either the MPL or the GPL. 
025 */
026
027package ca.uhn.hl7v2.validation;
028
029import ca.uhn.hl7v2.HL7Exception;
030import ca.uhn.hl7v2.model.Message;
031
032/**
033 * Interface to validates messages.
034 * 
035 * @author Bryan Tripp
036 * @author Christian Ohr
037 */
038public interface Validator<R> {
039
040        /**
041         * Validates a {@link Message}
042         * 
043         * @param message message to be validated
044         * @return <code>true</code> if message is valid
045         * @throws HL7Exception if an unexpected error occurs while validating
046         * @throws NullPointerException if the message is null
047         */
048        public R validate(Message message) throws HL7Exception;
049
050        /**
051         * 
052         * Validates a String representing an encoded message
053         * 
054         * @param message message to be validated
055         * @param isXML true if message is supposed to be XML
056         * @param version message version
057         * @return <code>true</code> if message is valid
058         * @throws HL7Exception if an unexpected error occurs while validating
059         * @throws NullPointerException if the message is null
060         */
061        public R validate(String message, boolean isXML, String version) throws HL7Exception;
062
063        /**
064         * Validates a {@link Message} using a custom {@link ValidationExceptionHandler}. The handler
065         * provides the possibility to react on the outcome of the validation process and its individual
066         * steps, e.g. collecting all validation, issues, aggregating them to a single issue, logging,
067         * throwing exceptions etc.
068         * <p>
069         * As the handler usually maintains state, a new instance is required for every validation call.
070         * 
071         * @param message message to be validated
072         * @param handler message validation handler
073         * @return <code>true</code> if message is valid
074         * @throws HL7Exception if an unexpected error occurs while validating
075         * @throws NullPointerException if the message or handler is <code>null</code>
076         */
077        public R validate(Message message, ValidationExceptionHandler<R> handler)
078                        throws HL7Exception;
079
080        /**
081         * 
082         * Validates a String representing an encoded message. As the handler usually maintains state, a
083         * new instance is required for every validation call.
084         * 
085         * @param message message to be validated
086         * @param isXML true if message is supposed to be XML
087         * @param version message version
088         * @param handler message validation handler
089         * @return <code>true</code> if message is valid
090         * @throws HL7Exception if an unexpected error occurs while validating
091         * @throws NullPointerException if the message or handler is <code>null</code>
092         */
093        public R validate(String message, boolean isXML, String version,
094                        ValidationExceptionHandler<R> handler) throws HL7Exception;
095
096}