| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| RuleBinding |
|
| 1.1;1.1 |
| 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 "RuleBinding.java". Description: | |
| 10 | "An association between a type of item to be validated (eg a datatype or message) and a validation Rule." | |
| 11 | ||
| 12 | The Initial Developer of the Original Code is University Health Network. Copyright (C) | |
| 13 | 2004. 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.impl; | |
| 27 | ||
| 28 | import java.io.Serializable; | |
| 29 | ||
| 30 | import ca.uhn.hl7v2.validation.Rule; | |
| 31 | ||
| 32 | /** | |
| 33 | * An association between a type of item to be validated (eg a datatype or | |
| 34 | * message) and a validation <code>Rule</code>. | |
| 35 | * | |
| 36 | * @author Bryan Tripp | |
| 37 | * @author James Agnew | |
| 38 | * @author Christian Ohr | |
| 39 | * */ | |
| 40 | public class RuleBinding<T extends Rule<?>> implements Serializable { | |
| 41 | ||
| 42 | private static final long serialVersionUID = 1L; | |
| 43 | ||
| 44 | private boolean myActiveFlag; | |
| 45 | private String myVersion; | |
| 46 | private String myScope; | |
| 47 | private T myRule; | |
| 48 | ||
| 49 | /** | |
| 50 | * Active by default. | |
| 51 | * | |
| 52 | * @param theVersion | |
| 53 | * see {@link #getVersion()} | |
| 54 | * @param theScope | |
| 55 | * see {@link #getScope()} | |
| 56 | * @param theRule | |
| 57 | * see {@link #getRule()} | |
| 58 | */ | |
| 59 | 174410 | public RuleBinding(String theVersion, String theScope, T theRule) { |
| 60 | 174410 | myActiveFlag = true; |
| 61 | 174410 | myVersion = theVersion; |
| 62 | 174410 | myScope = theScope; |
| 63 | 174410 | myRule = theRule; |
| 64 | 174410 | } |
| 65 | ||
| 66 | /** | |
| 67 | * @return true if the binding is currently active | |
| 68 | */ | |
| 69 | public boolean getActive() { | |
| 70 | 238412 | return myActiveFlag; |
| 71 | } | |
| 72 | ||
| 73 | /** | |
| 74 | * @param isActive | |
| 75 | * true if the binding is currently active | |
| 76 | */ | |
| 77 | public void setActive(boolean isActive) { | |
| 78 | 174305 | myActiveFlag = isActive; |
| 79 | 174305 | } |
| 80 | ||
| 81 | /** | |
| 82 | * @return the version to which the binding applies (* means all versions) | |
| 83 | */ | |
| 84 | public String getVersion() { | |
| 85 | 238447 | return myVersion; |
| 86 | } | |
| 87 | ||
| 88 | /** | |
| 89 | * @return the scope of item types to which the rule applies. For | |
| 90 | * <code>MessageRule</code>s this is the message type and trigger | |
| 91 | * event, separated by a ^ (either value may be *, meaning any). For | |
| 92 | * <code>PrimitiveTypeRule</code>s this is the datatype name (* | |
| 93 | * means any). For <code>EncodingRule</code>s this is the encoding | |
| 94 | * name (again, * means any). | |
| 95 | */ | |
| 96 | public String getScope() { | |
| 97 | 101322 | return myScope; |
| 98 | } | |
| 99 | ||
| 100 | /** | |
| 101 | * @return a <code>Rule</code> that applies to the associated version and | |
| 102 | * scope | |
| 103 | */ | |
| 104 | public T getRule() { | |
| 105 | 10058 | return myRule; |
| 106 | } | |
| 107 | ||
| 108 | /** | |
| 109 | * @param theVersion | |
| 110 | * an HL7 version | |
| 111 | * @return true if this binding applies to the given version (ie | |
| 112 | * getVersion() matches or is *) | |
| 113 | */ | |
| 114 | public boolean appliesToVersion(String theVersion) { | |
| 115 | 238442 | return applies(getVersion(), theVersion); |
| 116 | } | |
| 117 | ||
| 118 | /** | |
| 119 | * @param theType | |
| 120 | * an item description to be checked against getScope() | |
| 121 | * @return true if the given type is within scope, ie if it matches | |
| 122 | * getScope() or getScope() is * | |
| 123 | */ | |
| 124 | public boolean appliesToScope(String theType) { | |
| 125 | 101317 | return applies(getScope(), theType); |
| 126 | } | |
| 127 | ||
| 128 | /** | |
| 129 | * An abstraction of appliesToVersion() and appliesToScope(). Compares two values | |
| 130 | * and returns true if they are equal or if the binding data is "*" | |
| 131 | */ | |
| 132 | protected static boolean applies(String theBindingData, String theItemData) { | |
| 133 | 344958 | return (theBindingData.equals(theItemData) || theBindingData.equals("*")); |
| 134 | } | |
| 135 | ||
| 136 | @Override | |
| 137 | public String toString() { | |
| 138 | 0 | return myRule.toString() + " for " + myScope + " in version " + myVersion; |
| 139 | } | |
| 140 | ||
| 141 | ||
| 142 | } |