View Javadoc
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 "EncodingRuleBuilder.java".  Description: 
10  "Rule Builder for EncodingRules." 
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.builder;
27  
28  import java.util.Collection;
29  import java.util.Collections;
30  import java.util.List;
31  import java.util.Set;
32  
33  import ca.uhn.hl7v2.Version;
34  import ca.uhn.hl7v2.validation.EncodingRule;
35  import ca.uhn.hl7v2.validation.Rule;
36  import ca.uhn.hl7v2.validation.impl.EncodingRuleBinding;
37  import ca.uhn.hl7v2.validation.impl.RuleBinding;
38  import ca.uhn.hl7v2.validation.impl.XMLSchemaRule;
39  
40  /**
41   * Rule builder for {@link EncodingRule}s.
42   * 
43   * @author Christian Ohr
44   */
45  @SuppressWarnings("serial")
46  public class EncodingRuleBuilder extends RuleTypeBuilder<EncodingRuleBuilder, EncodingRule> {
47  
48  	private final String encoding;
49  
50  	protected EncodingRuleBuilder(List<RuleBinding<? extends Rule<?>>> rules, Set<Version> versions,
51  			String encoding) {
52  		super(rules, versions);
53  		this.encoding = encoding;
54  	}
55  
56  	/**
57  	 * Adds {@link XMLSchemaRule} for the configured versions
58  	 * 
59  	 * @return this instance to build more rules
60  	 */
61  	public EncodingRuleBuilder xsd() {
62  		return test(prepareRule(new XMLSchemaRule()));
63  	}	
64  	
65  	// for tests only
66  	String getEncoding() {
67  		return encoding;
68  	}
69  
70  	@Override
71  	protected Collection<RuleBinding<EncodingRule>> getRuleBindings(EncodingRule rule,
72  			String version) {
73  		RuleBinding<EncodingRule> binding = new EncodingRuleBinding(version, encoding, rule);
74  		return activate(Collections.singletonList(binding));
75  	}
76  
77  }