| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
package ca.uhn.hl7v2.model; |
| 28 | |
|
| 29 | |
import ca.uhn.hl7v2.HL7Exception; |
| 30 | |
import ca.uhn.hl7v2.Location; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
public final class MessageVisitors { |
| 36 | |
|
| 37 | 0 | private MessageVisitors() {} |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
public static <T extends MessageVisitor> T visit(Visitable visitable, T visitor) throws HL7Exception { |
| 48 | 10 | visitable.accept(visitor, new Location()); |
| 49 | 10 | return visitor; |
| 50 | |
} |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
public static <T extends MessageVisitor> StructuresVisitor<T> visitStructures(T visitor) { |
| 58 | 0 | return new StructuresVisitor<T>(visitor); |
| 59 | |
} |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
public static <T extends MessageVisitor> PopulatedVisitor<T> visitPopulatedElements(T visitor) { |
| 70 | 5 | return new PopulatedVisitor<T>(visitor); |
| 71 | |
} |
| 72 | |
|
| 73 | |
|
| 74 | |
public final static class StructuresVisitor<T extends MessageVisitor> extends DelegatingMessageVisitor<T> { |
| 75 | |
|
| 76 | |
StructuresVisitor(T visitor) { |
| 77 | 0 | super(visitor); |
| 78 | 0 | } |
| 79 | |
|
| 80 | |
@Override |
| 81 | |
public boolean start(Segment segment, Location location) throws HL7Exception { |
| 82 | 0 | super.start(segment, location); |
| 83 | 0 | return false; |
| 84 | |
} |
| 85 | |
|
| 86 | |
@Override |
| 87 | |
public final boolean start(Composite type, Location location) throws HL7Exception { |
| 88 | 0 | return false; |
| 89 | |
} |
| 90 | |
|
| 91 | |
@Override |
| 92 | |
public boolean visit(Primitive type, Location location) throws HL7Exception { |
| 93 | 0 | return false; |
| 94 | |
} |
| 95 | |
} |
| 96 | |
|
| 97 | |
public final static class PopulatedVisitor<T extends MessageVisitor> extends DelegatingMessageVisitor<T> { |
| 98 | |
|
| 99 | |
PopulatedVisitor(T visitor) { |
| 100 | 5 | super(visitor); |
| 101 | 5 | } |
| 102 | |
|
| 103 | |
@Override |
| 104 | |
public boolean start(Group group, Location location) throws HL7Exception { |
| 105 | 25 | return !group.isEmpty() && super.start(group, location); |
| 106 | |
} |
| 107 | |
|
| 108 | |
@Override |
| 109 | |
public boolean end(Group group, Location location) throws HL7Exception { |
| 110 | 25 | return !group.isEmpty() && super.end(group, location); |
| 111 | |
} |
| 112 | |
|
| 113 | |
@Override |
| 114 | |
public boolean start(Segment segment, Location location) throws HL7Exception { |
| 115 | 45 | return !segment.isEmpty() && super.start(segment, location); |
| 116 | |
} |
| 117 | |
|
| 118 | |
@Override |
| 119 | |
public boolean end(Segment segment, Location location) throws HL7Exception { |
| 120 | 45 | return !segment.isEmpty() && super.end(segment, location); |
| 121 | |
} |
| 122 | |
|
| 123 | |
@Override |
| 124 | |
public final boolean start(Composite type, Location location) throws HL7Exception { |
| 125 | 130 | return !type.isEmpty() && super.start(type, location); |
| 126 | |
} |
| 127 | |
|
| 128 | |
@Override |
| 129 | |
public boolean end(Composite type, Location location) throws HL7Exception { |
| 130 | 130 | return !type.isEmpty() && super.end(type, location); |
| 131 | |
} |
| 132 | |
|
| 133 | |
@Override |
| 134 | |
public boolean visit(Primitive type, Location location) throws HL7Exception { |
| 135 | 325 | return !type.isEmpty() && super.visit(type, location); |
| 136 | |
} |
| 137 | |
|
| 138 | |
|
| 139 | |
} |
| 140 | |
} |