Coverage Report - ca.uhn.hl7v2.parser.MessagePointer
 
Classes in this File Line Coverage Branch Coverage Complexity
MessagePointer
0%
0/27
0%
0/12
2.5
 
 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 "MessagePointer.java".  Description: 
 10  
 "A MessagePointer is used when parsing traditionally encoded HL7 messages" 
 11  
 
 12  
 The Initial Developer of the Original Code is University Health Network. Copyright (C) 
 13  
 2001.  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  
 */
 27  
 
 28  
 /*
 29  
  * Created on October 15, 2001, 4:17 PM
 30  
  */
 31  
 
 32  
 package ca.uhn.hl7v2.parser;
 33  
 
 34  
 import ca.uhn.hl7v2.HL7Exception;
 35  
 import ca.uhn.hl7v2.model.Group;
 36  
 import ca.uhn.hl7v2.model.Message;
 37  
 
 38  
 /**
 39  
  * A MessagePointer is used when parsing traditionally encoded HL7 messages. 
 40  
  * This is similar to a GroupPointer except that there is only one underlying 
 41  
  * instance of the Message, and it has no parent.  
 42  
  *
 43  
  * @deprecated PipeParser now uses MessageIterator
 44  
  * @see GroupPointer   
 45  
  * @author Bryan Tripp (bryan_tripp@sourceforge.net)
 46  
  */
 47  
 public class MessagePointer {
 48  
 
 49  
     private PipeParser parser;
 50  
     private EncodingCharacters encodingChars;
 51  
     private Pointer[] children;
 52  
     private Message message;
 53  0
     private int childAtWhichToStart = 0;
 54  
 
 55  
     /** 
 56  
      * Creates new GroupPointer 
 57  
      */
 58  0
     public MessagePointer(PipeParser parser, Message message, EncodingCharacters encodingChars) throws HL7Exception {
 59  0
         this.parser = parser;
 60  0
         this.message = message;
 61  0
         this.encodingChars = encodingChars;
 62  0
         makeChildren();
 63  0
     }
 64  
 
 65  
     /**
 66  
      * Parses the given String, which must contain a single traditionally encoded 
 67  
      * message segment, by forwarding it to child GroupPointers and SegmentPointers  
 68  
      * until one of them succeeds.  
 69  
      */
 70  
     public int setSegment(String segment) throws HL7Exception {
 71  0
         int status = tryToFillChildren(segment);
 72  0
         return status;
 73  
     }
 74  
 
 75  
     private int tryToFillChildren(String segment) throws HL7Exception {
 76  0
         int status = Pointer.FILL_FAILED_WRONG_SEGMENT;
 77  0
         int c = 0;
 78  
         //loop through children ... 
 79  
         //note: can't just stop if FILL_FAILED_FULL b/c have to check all nesting levels 
 80  0
         while (status != Pointer.FILL_OK && c < this.children.length) {
 81  0
             boolean correctOrder = (c >= childAtWhichToStart ? true : false);
 82  0
             status = children[c++].setSegment(segment, correctOrder);
 83  0
         }
 84  0
         if (status == Pointer.FILL_OK)
 85  0
             childAtWhichToStart = c - 1;
 86  0
         return status;
 87  
     }
 88  
 
 89  
     /** 
 90  
      * Creates a new, empty repetition of the underlying Group and sets up 
 91  
      * Pointers to it's components.  
 92  
      * @thows HL7Exception if there is already 1 rep and group is non-repeating
 93  
      */
 94  
     private void makeChildren() throws HL7Exception {
 95  
 
 96  
         //set up pointers for children ... 
 97  0
         String[] childNames = message.getNames();
 98  0
         this.children = new Pointer[childNames.length];
 99  0
         for (int i = 0; i < childNames.length; i++) {
 100  
             Pointer p;
 101  
             //make new SegmentPointer or GroupPointer depending on whether child is a Group ... 
 102  0
             Class<?> childClass = message.getClass(childNames[i]);
 103  0
             if (Group.class.isAssignableFrom(childClass)) {
 104  0
                 p = new GroupPointer(this.parser, message, i, this.encodingChars);
 105  
             }
 106  
             else {
 107  0
                 p = new SegmentPointer(this.parser, message, i, encodingChars);
 108  
             }
 109  
 
 110  0
             this.children[i] = p;
 111  
         }
 112  
 
 113  0
     }
 114  
 
 115  
 }