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 "MinLowerLayerProtocol.java".  Description: 
10  "Implements the "Minimal Lower Layer Protocol" from the HL7 Implementation 
11    Guide, Appendix C" 
12  
13  The Initial Developer of the Original Code is University Health Network. Copyright (C) 
14  2001.  All Rights Reserved. 
15  
16  Contributor(s): ______________________________________. 
17  
18  Alternatively, the contents of this file may be used under the terms of the 
19  GNU General Public License (the "GPL"), in which case the provisions of the GPL are 
20  applicable instead of those above.  If you wish to allow use of your version of this 
21  file only under the terms of the GPL and not to allow others to use your version 
22  of this file under the MPL, indicate your decision by deleting  the provisions above 
23  and replace  them with the notice and other provisions required by the GPL License.  
24  If you do not delete the provisions above, a recipient may use your version of 
25  this file under either the MPL or the GPL. 
26  
27  */
28  
29  package ca.uhn.hl7v2.llp;
30  
31  import java.io.*;
32  import java.nio.charset.Charset;
33  
34  /**
35   * Implements the "Minimal Lower Layer Protocol" from the HL7 Implementation 
36   * Guide, Appendix C.  In other words, provides a reader and a writer that can be 
37   * used to communicate with a server that uses the minimal LLP.
38   * 
39   * @see MinLLPReader
40   * @see MinLLPWriter 
41   * @author Bryan Tripp
42   */
43  public class MinLowerLayerProtocol extends LowerLayerProtocol {
44  
45  	private Charset charset;
46  
47      /** 
48       * Creates new MinLowerLayerProtocol 
49       */
50      public MinLowerLayerProtocol() {
51      }
52      
53      /**
54       * Creates an HL7Reader that implements message reading according to 
55       * this protocol.  
56       */
57      public HL7Reader getReader(InputStream in) throws LLPException {
58          try {
59          	if (charset != null) {
60          		return new MinLLPReader(in, charset);
61          	} else {
62          		return new MinLLPReader(in);
63          	}
64          } catch (IOException e) {
65              throw new LLPException("Can't create MinLLPReader with the given input stream: " + e.getMessage(), e);
66          }
67      }
68      
69      /**
70       * Creates an HL7Writer that implements message writing according to 
71       * this protocol.  
72       */
73      public HL7Writer getWriter(OutputStream out) throws LLPException {
74          try {
75          	if (charset != null) {
76          		return new MinLLPWriter(out, charset);
77          	} else {
78          		return new MinLLPWriter(out);
79          	}
80          } catch (IOException e) {
81              throw new LLPException("Can't create MinLLPWriter with the given output stream: " + e.getMessage(), e);
82          }
83      }
84      
85      /**
86       * Provides a charset to use for character encoding
87       * @param theCharset The charset to use
88       * @since 1.3
89       */
90  	public void setCharset(Charset theCharset) {
91  		charset = theCharset;
92  	}
93  
94      /**
95       * Provides a charset to use for character encoding
96       * @param charsetName The name of the charset to use
97       * @since 2.1
98       */
99  	public void setCharset(String charsetName) {
100 		charset = Charset.forName(charsetName);
101 	}
102 
103 }