Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
LowerLayerProtocol |
|
| 1.0;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 "LowerLayerProtocol.java". Description: | |
10 | "Represents a particular "lower layer protocol" over which HL7 messages can be | |
11 | sent" | |
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.InputStream; | |
32 | import java.io.OutputStream; | |
33 | import java.nio.charset.Charset; | |
34 | ||
35 | import org.slf4j.Logger; | |
36 | import org.slf4j.LoggerFactory; | |
37 | ||
38 | /** | |
39 | * Represents a particular "lower layer protocol" over which HL7 messages can be | |
40 | * sent. An example is the "minimal lower layer protocol" defines in the HL7 | |
41 | * implementation guide (appendix C) - this is implemented by the class | |
42 | * MinLowerLayerProtocol. Implementations should call the static method | |
43 | * <code>logCharacterReceived()</code> when a character is read from a remote system. | |
44 | * This method may or may not log receipt, as configured (see docs for this method). | |
45 | * | |
46 | * @author Bryan Tripp | |
47 | */ | |
48 | 5715 | public abstract class LowerLayerProtocol { |
49 | ||
50 | 5 | private static final Logger log = LoggerFactory.getLogger(LowerLayerProtocol.class); |
51 | protected Charset charset; | |
52 | ||
53 | /** | |
54 | * Returns a particular implementation of LowerLayerProtocol. | |
55 | * | |
56 | * @deprecated as there is now the choice between {@link MinLowerLayerProtocol} | |
57 | * and {@link ExtendedMinLowerLayerProtocol}. | |
58 | */ | |
59 | public static LowerLayerProtocol makeLLP() { | |
60 | 0 | return new MinLowerLayerProtocol(); |
61 | } | |
62 | ||
63 | /** | |
64 | * Returns a particular implementation of LowerLayerProtocol | |
65 | * @param respectMSH18 | |
66 | * @return LowerLayerProtocol implementation | |
67 | */ | |
68 | public static LowerLayerProtocol makeLLP(boolean respectMSH18) { | |
69 | 35 | return new MinLowerLayerProtocol(respectMSH18); |
70 | } | |
71 | ||
72 | /** | |
73 | * Returns an HL7Reader that implements message reading according to | |
74 | * this protocol. | |
75 | */ | |
76 | public abstract HL7Reader getReader(InputStream in) throws LLPException; | |
77 | ||
78 | /** | |
79 | * Returns an HL7Writer that implements message writing according to | |
80 | * this protocol. | |
81 | */ | |
82 | public abstract HL7Writer getWriter(OutputStream out) throws LLPException; | |
83 | ||
84 | /** | |
85 | * <p> | |
86 | * Logs the fact that a character has been received, if configured to do so. | |
87 | * </p> | |
88 | * <p> | |
89 | * This logging is enabled by configuring the underlying log system to allow | |
90 | * the logger named "<code>ca.uhn.hl7v2.llp.LowerLayerProtocol</code>" to log | |
91 | * events at a level of "trace". | |
92 | * </p> | |
93 | */ | |
94 | public static void logCharacterReceived(int c) { | |
95 | 301936 | log.trace("Char received: {} ({})", c, (char) c); |
96 | 301936 | } |
97 | ||
98 | /** | |
99 | * Provides a charset to use for character encoding | |
100 | * @param theCharset The charset to use | |
101 | * @since 1.3 | |
102 | */ | |
103 | public void setCharset(Charset theCharset) { | |
104 | 0 | charset = theCharset; |
105 | 0 | } |
106 | ||
107 | /** | |
108 | * Provides a charset to use for character encoding | |
109 | * @param charsetName The name of the charset to use | |
110 | * @since 2.1 | |
111 | */ | |
112 | public void setCharset(String charsetName) { | |
113 | 5 | charset = Charset.forName(charsetName); |
114 | 5 | } |
115 | } | |
116 |