1 /* 2 * To change this template, choose Tools | Templates 3 * and open the template in the editor. 4 */ 5 6 package ca.uhn.hl7v2.model; 7 8 import ca.uhn.hl7v2.HL7Exception; 9 import ca.uhn.hl7v2.Location; 10 11 /** 12 * A MessageVisitor can be used to traverse a message structure. Everytime a 13 * message element is found, the corresponding visitable method is called. If 14 * a method returns <code>true</code>, the visiting process is continued, 15 * otherwise abandoned. 16 * <p> 17 * A MessageVisitor should usually only be called by 18 * {@link Visitable#accept(MessageVisitor, Location)}. 19 * </p> 20 */ 21 public interface MessageVisitor { 22 23 /** 24 * Enters a message 25 * @param message message 26 * @return true if the visitor shall descend into the nested structures 27 * @throws HL7Exception if an error occurred while visiting 28 */ 29 boolean start(Message message) throws HL7Exception; 30 31 /** 32 * Leaves a message 33 * @param message message 34 * @return true if the visitor shall descend into the nested structures 35 * @throws HL7Exception if an error occurred while visiting 36 */ 37 boolean end(Message message) throws HL7Exception; 38 39 /** 40 * Enters a group (or message) 41 * @param group group 42 * @param location Location object describing the location within the message 43 * @return true if the visitor shall descend into the nested structures 44 * @throws HL7Exception if an error occurred while visiting 45 */ 46 boolean start(Group group, Location location) throws HL7Exception; 47 48 /** 49 * Leaves a group (or message) 50 * @param group group 51 * @param location Location object describing the location within the message 52 * @return true if the visitor shall continue visiting the parent structure 53 * @throws HL7Exception if an error occurred while visiting 54 */ 55 boolean end(Group group, Location location) throws HL7Exception; 56 57 /** 58 * Enters a segment 59 * @param segment segment 60 * @param location Location object describing the location within the message 61 * @return true if the visitor shall descend into the nested structures 62 * @throws HL7Exception if an error occurred while visiting 63 */ 64 boolean start(Segment segment, Location location) throws HL7Exception; 65 66 /** 67 * Leaves a segment 68 * @param segment segment 69 * @param location Location object describing the location within the message 70 * @return true if the visitor shall continue visiting the parent structure 71 * @throws HL7Exception if an error occurred while visiting 72 */ 73 boolean end(Segment segment, Location location) throws HL7Exception; 74 75 /** 76 * Enters a field. Note that a field is *not* a physical part of the HAPI 77 * model class hierarchy; it merely encapsulates all repetitions of a specific 78 * field along with its substructures. 79 * 80 * @param field field 81 * @param location Location object describing the location within the message 82 * @return true if the visitor shall descend into the nested structures 83 * @throws HL7Exception if an error occurred while visiting 84 */ 85 boolean start(Field field, Location location) throws HL7Exception; 86 87 /** 88 * Leaves a field. Note that a field is *not* a physical part of the HAPI 89 * model class hierarchy; it merely encapsulates all repetitions of a specific 90 * field along with its substructures. 91 * 92 * @param field field 93 * @param location Location object describing the location within the message 94 * @return true if the visitor shall continue visiting the parent structure 95 * @throws HL7Exception if an error occurred while visiting 96 */ 97 boolean end(Field field, Location location) throws HL7Exception; 98 99 /** 100 * Enters a composite 101 * @param type composite 102 * @param location Location object describing the location within the message 103 * @return true if the visitor shall descend into the nested structures 104 * @throws HL7Exception if an error occurred while visiting 105 */ 106 boolean start(Composite type, Location location) throws HL7Exception; 107 108 /** 109 * Leaves a composite 110 * @param type composite 111 * @param location Location object describing the location within the message 112 * @return true if the visitor shall continue visiting the parent structure 113 * @throws HL7Exception if an error occurred while visiting 114 */ 115 boolean end(Composite type, Location location) throws HL7Exception; 116 117 /** 118 * Visits a primitive 119 * @param type primitive 120 * @param location Location object describing the location within the message 121 * @return true if the visitor shall descend into the nested structures 122 * @throws HL7Exception if an error occurred while visiting 123 */ 124 boolean visit(Primitive type, Location location) throws HL7Exception; 125 126 }