1 package ca.uhn.hl7v2.model;
2
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5
6 import ca.uhn.hl7v2.HL7Exception;
7 import ca.uhn.hl7v2.Version;
8 import ca.uhn.hl7v2.parser.ModelClassFactory;
9
10
11
12
13
14
15
16
17 @SuppressWarnings("serial")
18 public abstract class GenericMessage extends AbstractMessage {
19
20 private static final Logger log = LoggerFactory.getLogger(GenericMessage.class);
21
22
23
24
25
26
27 public GenericMessage(ModelClassFactory factory) {
28 super(factory);
29 try {
30 this.addNonstandardSegment("MSH");
31 } catch(HL7Exception e) {
32 String message = "Unexpected error adding GenericSegment to GenericMessage.";
33 log.error(message, e);
34 throw new Error(message);
35 }
36 }
37
38
39
40
41
42
43
44
45
46 @SuppressWarnings("unchecked")
47 public static Class<? extends Message> getGenericMessageClass(String version) {
48
49 Version v = Version.versionOf(version);
50 if (v != null) {
51 try {
52 String className = GenericMessage.class.getName() + "$" + v.name();
53 return (Class<? extends Message>)Class.forName(className);
54 } catch (ClassNotFoundException e) {
55
56
57 }
58 }
59
60 log.debug("Unknown version for generic type {}", version);
61 return UnknownVersion.class;
62 }
63
64
65 public static class UnknownVersion extends GenericMessage {
66 private static final long serialVersionUID = 4773366840392833956L;
67 public UnknownVersion(ModelClassFactory factory) {
68 super(factory);
69 }
70 public String getVersion() {
71 return Version.latestVersion().getVersion();
72 }
73
74 }
75
76 public static class V21 extends GenericMessage {
77 private static final long serialVersionUID = 4773366840392833956L;
78 public V21(ModelClassFactory factory) {
79 super(factory);
80 }
81 public String getVersion() { return Version.V21.getVersion(); }
82 }
83
84 public static class V22 extends GenericMessage {
85 private static final long serialVersionUID = 7124224621400437244L;
86 public V22(ModelClassFactory factory) {
87 super(factory);
88 }
89 public String getVersion() { return Version.V22.getVersion(); }
90 }
91
92 public static class V23 extends GenericMessage {
93 private static final long serialVersionUID = -8794048442253389190L;
94 public V23(ModelClassFactory factory) {
95 super(factory);
96 }
97 public String getVersion() { return Version.V23.getVersion(); }
98 }
99
100 public static class V231 extends GenericMessage {
101 private static final long serialVersionUID = 5979370667795858995L;
102 public V231(ModelClassFactory factory) {
103 super(factory);
104 }
105 public String getVersion() { return Version.V231.getVersion(); }
106 }
107
108 public static class V24 extends GenericMessage {
109 private static final long serialVersionUID = -4944772617600551061L;
110 public V24(ModelClassFactory factory) {
111 super(factory);
112 }
113 public String getVersion() { return Version.V24.getVersion(); }
114 }
115
116 public static class V25 extends GenericMessage {
117 private static final long serialVersionUID = 3937051332672967947L;
118 public V25(ModelClassFactory factory) {
119 super(factory);
120 }
121 public String getVersion() { return Version.V25.getVersion(); }
122 }
123
124 public static class V251 extends GenericMessage {
125 private static final long serialVersionUID = -767282165482145544L;
126 public V251(ModelClassFactory factory) {
127 super(factory);
128 }
129 public String getVersion() { return Version.V251.getVersion(); }
130 }
131
132 public static class V26 extends GenericMessage {
133 private static final long serialVersionUID = -1693277295151324396L;
134 public V26(ModelClassFactory factory) {
135 super(factory);
136 }
137 public String getVersion() { return Version.V26.getVersion(); }
138 }
139
140 public static class V27 extends GenericMessage {
141 private static final long serialVersionUID = -1693277295151324396L;
142 public V27(ModelClassFactory factory) {
143 super(factory);
144 }
145 public String getVersion() { return Version.V27.getVersion(); }
146 }
147
148 public static class V271 extends GenericMessage {
149 private static final long serialVersionUID = -1693277295151324396L;
150 public V271(ModelClassFactory factory) {
151 super(factory);
152 }
153 public String getVersion() { return Version.V271.getVersion(); }
154 }
155
156 public static class V28 extends GenericMessage {
157 private static final long serialVersionUID = -1693277295151324396L;
158 public V28(ModelClassFactory factory) {
159 super(factory);
160 }
161 public String getVersion() { return Version.V28.getVersion(); }
162 }
163
164 public static class V281 extends GenericMessage {
165 private static final long serialVersionUID = -1693277295151324396L;
166 public V281(ModelClassFactory factory) {
167 super(factory);
168 }
169 public String getVersion() { return Version.V281.getVersion(); }
170 }
171
172 }