Coverage Report - ca.uhn.hl7v2.model.GenericMessage
 
Classes in this File Line Coverage Branch Coverage Complexity
GenericMessage
68%
11/16
100%
2/2
1.25
GenericMessage$UnknownVersion
100%
3/3
N/A
1.25
GenericMessage$V21
0%
0/3
N/A
1.25
GenericMessage$V22
100%
3/3
N/A
1.25
GenericMessage$V23
100%
3/3
N/A
1.25
GenericMessage$V231
100%
3/3
N/A
1.25
GenericMessage$V24
100%
3/3
N/A
1.25
GenericMessage$V25
100%
3/3
N/A
1.25
GenericMessage$V251
100%
3/3
N/A
1.25
GenericMessage$V26
100%
3/3
N/A
1.25
 
 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  
  * A generic HL7 message, meant for parsing message with unrecognized structures
 12  
  * into a flat list of segments.
 13  
  * 
 14  
  * @author Bryan Tripp
 15  
  * @author Christian Ohr
 16  
  */
 17  
 @SuppressWarnings("serial")
 18  
 public abstract class GenericMessage extends AbstractMessage {
 19  
     
 20  1
         private static final Logger log = LoggerFactory.getLogger(GenericMessage.class);
 21  
         
 22  
     /** 
 23  
      * Creates a new instance of GenericMessage. 
 24  
      * 
 25  
      * @param factory class factory for contained structures 
 26  
      */
 27  
     public GenericMessage(ModelClassFactory factory) {
 28  144
         super(factory);
 29  
         try {
 30  144
             this.addNonstandardSegment("MSH");
 31  0
         } catch(HL7Exception e) {
 32  0
             String message = "Unexpected error adding GenericSegment to GenericMessage.";
 33  0
             log.error(message, e);
 34  0
             throw new Error(message); // TODO better throw RuntimeException
 35  144
         }        
 36  144
     }
 37  
     
 38  
     /**
 39  
      * Returns a subclass of GenericMessage corresponding to a certain version.  
 40  
      * This is needed so that version-specific segments can be added as the message
 41  
      * is parsed.
 42  
      *
 43  
      * @param version the HL7 version
 44  
      * @return the class of the generic message
 45  
      */
 46  
         @SuppressWarnings("unchecked")
 47  
         public static Class<? extends Message> getGenericMessageClass(String version) {
 48  
                 
 49  35
                 Version v = Version.versionOf(version);
 50  35
         if (v != null) {       
 51  
                 try {
 52  33
                         String className = GenericMessage.class.getName() + "$" + v.name();
 53  33
                         return (Class<? extends Message>)Class.forName(className);
 54  0
                 } catch (ClassNotFoundException e) {
 55  
                         // should not happen as long Version corresponds with the static
 56  
                         // subclasses of GenericMessage
 57  
                 }
 58  
         }
 59  
 
 60  2
         log.debug("Unknown version for generic type {}", version);
 61  2
         return UnknownVersion.class;
 62  
     }
 63  
 
 64  
 
 65  
     public static class UnknownVersion extends GenericMessage {
 66  
                 private static final long serialVersionUID = 4773366840392833956L;
 67  
 
 68  
                 public UnknownVersion(ModelClassFactory factory) {
 69  1
             super(factory);
 70  1
         }
 71  
         public String getVersion() {
 72  1
                 return Version.latestVersion().getVersion();
 73  
         }
 74  
 
 75  
     }
 76  
 
 77  
     public static class V21 extends GenericMessage {
 78  
                 private static final long serialVersionUID = 4773366840392833956L;
 79  
                 public V21(ModelClassFactory factory) {
 80  0
             super(factory);
 81  0
         }
 82  0
         public String getVersion() { return Version.V21.getVersion(); }
 83  
     }
 84  
     
 85  
     public static class V22 extends GenericMessage {
 86  
                 private static final long serialVersionUID = 7124224621400437244L;
 87  
                 public V22(ModelClassFactory factory) {
 88  11
             super(factory);
 89  11
         }
 90  232
         public String getVersion() { return Version.V22.getVersion(); }
 91  
     }
 92  
     
 93  
     public static class V23 extends GenericMessage {
 94  
                 private static final long serialVersionUID = -8794048442253389190L;
 95  
                 public V23(ModelClassFactory factory) {
 96  4
             super(factory);
 97  4
         }
 98  129
         public String getVersion() { return Version.V23.getVersion(); }
 99  
     }
 100  
     
 101  
     public static class V231 extends GenericMessage {
 102  
                 private static final long serialVersionUID = 5979370667795858995L;
 103  
                 public V231(ModelClassFactory factory) {
 104  4
             super(factory);
 105  4
         }
 106  128
         public String getVersion() { return Version.V231.getVersion(); }
 107  
     }
 108  
     
 109  
     public static class V24 extends GenericMessage {
 110  
                 private static final long serialVersionUID = -4944772617600551061L;
 111  
                 public V24(ModelClassFactory factory) {
 112  86
             super(factory);
 113  86
         }
 114  340
         public String getVersion() { return Version.V24.getVersion(); }
 115  
     }
 116  
     
 117  
     public static class V25 extends GenericMessage {
 118  
                 private static final long serialVersionUID = 3937051332672967947L;
 119  
                 public V25(ModelClassFactory factory) {
 120  30
             super(factory);
 121  30
         }
 122  382
         public String getVersion() { return Version.V25.getVersion(); }
 123  
     }
 124  
     
 125  
     public static class V251 extends GenericMessage {
 126  
                 private static final long serialVersionUID = -767282165482145544L;
 127  
                 public V251(ModelClassFactory factory) {
 128  2
             super(factory);
 129  2
         }
 130  59
         public String getVersion() { return Version.V251.getVersion(); }
 131  
     }
 132  
 
 133  
     public static class V26 extends GenericMessage {
 134  
                 private static final long serialVersionUID = -1693277295151324396L;
 135  
                 public V26(ModelClassFactory factory) {
 136  6
             super(factory);
 137  6
         }
 138  165
         public String getVersion() { return Version.V26.getVersion(); }
 139  
     }
 140  
 
 141  
 }