Class MessageNavigator
- Direct Known Subclasses:
SegmentFinder
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).
- Author:
- Bryan Tripp
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddrillDown(int rep) Drills down into the group at the CURRENT location.voiddrillDown(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 childbooleandrillUp()Switches the group context to the parent of the current group, and sets the child pointer to the next sibling.Returns the array of structures at the current location.Returns the group within which the pointer is currently located.getCurrentStructure(int rep) Returns the given rep of the structure at the current location.getRoot()booleanReturns true if there is a sibling following the current location.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).voidMoves to the next sibling of the current location.voidreset()Resets the location to the beginning of the tree (the root)toChild(int child) Moves to the sibling of the current location at the specified index.
-
Constructor Details
-
MessageNavigator
Creates a new instance of MessageNavigator- Parameters:
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.
-
-
Method Details
-
getRoot
-
drillDown
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- Parameters:
childNumber- the index of the group child into which to drillrep- the group repetition into which to drill- Throws:
HL7Exception
-
drillDown
Drills down into the group at the CURRENT location.- Throws:
HL7Exception
-
drillUp
Switches the group context to the parent of the current group, and sets the child pointer to the next sibling.- Returns:
- false if already at root
-
hasNextChild
Returns true if there is a sibling following the current location. -
nextChild
Moves to the next sibling of the current location.- Throws:
HL7Exception
-
toChild
Moves to the sibling of the current location at the specified index.- Returns:
- Throws:
HL7Exception
-
reset
Resets the location to the beginning of the tree (the root) -
getCurrentStructure
Returns the given rep of the structure at the current location. If at root, always returns the root (the rep is ignored).- Throws:
HL7Exception
-
getCurrentGroup
Returns the group within which the pointer is currently located. If at the root, the root is returned. -
getCurrentChildReps
Returns the array of structures at the current location. Throws an exception if pointer is at root.- Throws:
HL7Exception
-
iterate
Iterates through the message tree to the next segment/group location (regardless of whether an instance of the segment exists). If the end of the tree is reached, starts over at the root. Only enters the first repetition of a repeating group -- explicit navigation (using the drill...() methods) is necessary to get to subsequent reps.- Parameters:
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 reached- Returns:
- Returns the name of the next item within its parent, or "" for the root (message)
- Throws:
HL7Exception
-