public class MessageNavigator extends Object
Used to navigate the nested group structure of a message. This is an alternate way of accessing parts of a message, ie rather than getting a segment through a chain of getXXX() calls on the message, you can create a MessageNavigator for the message, "navigate" to the desired segment, and then call getCurrentStructure() to get the segment you have navigated to. A message navigator always has a "current location" pointing to some structure location (segment or group location) within the message. Note that a location exists whether or not there are any instances of the structure at that location.
This class is used by Terser, which presents an even more convenient way of navigating a message.
This class also has an iterate() method, which iterates over segments (and optionally groups).
Constructor and Description |
---|
MessageNavigator(Group root)
Creates a new instance of MessageNavigator
|
Modifier and Type | Method and Description |
---|---|
void |
drillDown(int rep)
Drills down into the group at the CURRENT location.
|
void |
drillDown(int childNumber,
int rep)
Drills down into the group at the given index within the current
group -- ie sets the location pointer to the first structure within the child
|
boolean |
drillUp()
Switches the group context to the parent of the current group,
and sets the child pointer to the next sibling.
|
Structure[] |
getCurrentChildReps()
Returns the array of structures at the current location.
|
Group |
getCurrentGroup()
Returns the group within which the pointer is currently located.
|
Structure |
getCurrentStructure(int rep)
Returns the given rep of the structure at the current location.
|
Group |
getRoot() |
boolean |
hasNextChild()
Returns true if there is a sibling following the current location.
|
String |
iterate(boolean segmentsOnly,
boolean loop)
Iterates through the message tree to the next segment/group location (regardless
of whether an instance of the segment exists).
|
void |
nextChild()
Moves to the next sibling of the current location.
|
void |
reset()
Resets the location to the beginning of the tree (the root)
|
String |
toChild(int child)
Moves to the sibling of the current location at the specified index.
|
public MessageNavigator(Group root)
root
- the root of navigation -- may be a message or a group
within a message. Navigation will only occur within the subtree
of which the given group is the root.public void drillDown(int childNumber, int rep) throws HL7Exception
childNumber
- the index of the group child into which to drillrep
- the group repetition into which to drillHL7Exception
public void drillDown(int rep) throws HL7Exception
HL7Exception
public boolean drillUp()
public boolean hasNextChild()
public void nextChild() throws HL7Exception
HL7Exception
public String toChild(int child) throws HL7Exception
HL7Exception
public void reset()
public Structure getCurrentStructure(int rep) throws HL7Exception
HL7Exception
public Group getCurrentGroup()
public Structure[] getCurrentChildReps() throws HL7Exception
HL7Exception
public String iterate(boolean segmentsOnly, boolean loop) throws HL7Exception
segmentsOnly
- if true, only stops at segments (not groups)loop
- if true, loops back to beginning when end of msg reached; if false,
throws HL7Exception if end of msg reachedHL7Exception
Copyright © 2001–2017 University Health Network. All rights reserved.