/** Creates a new instance of Terser * * @param message message for which the Terser is created */ public Terser(Message message) { if (message == null) { throw new NullPointerException("Message may not be null"); } finder = new SegmentFinder(message); }
private Structure getStructure(String namePattern, int rep) throws HL7Exception { Structure s = null; if (getCurrentStructure(0).equals(this.getRoot())) drillDown(0); String[] names = getCurrentStructure(0).getParent().getNames(); for (int i = 0; i < names.length && s == null; i++) { if (matches(namePattern, names[i])) { toChild(i); s = getCurrentStructure(rep); } } if (s == null) throw new HL7Exception("Can't find " + namePattern + " as a direct child"); return s; }
/** * As findSegment(), but will only return a group. */ public Group findGroup(String namePattern, int rep) throws HL7Exception { Structure s; do { s = findStructure(namePattern, rep); } while (!Group.class.isAssignableFrom(s.getClass())); return (Group) s; }
/** * Returns the first matching structure AFTER the current position */ private Structure findStructure(String namePattern, int rep) throws HL7Exception { Structure s = null; while (s == null) { String currentNameInParent = iterate(false, false); String currentName = getCurrentStructure(0).getName(); if (matches(namePattern, currentName) || matches(namePattern, currentNameInParent)) { s = getCurrentStructure(rep); } } return s; }
getFinder().reset(); if (ps.isGroup) { Group g = ps.find ? finder.findGroup(ps.pattern, ps.rep) : finder.getGroup(ps.pattern, ps.rep); finder = new SegmentFinder(g); } else { seg = ps.find ? finder.findSegment(ps.pattern, ps.rep) : finder.getSegment(ps.pattern, ps.rep);
/** * As getSegment() but will only return a group. */ public Group getGroup(String namePattern, int rep) throws HL7Exception { Structure s = getStructure(namePattern, rep); if (!Group.class.isAssignableFrom(s.getClass())) { throw new HL7Exception(s.getName() + " is not a group"); } return (Group) s; }
getFinder().reset(); if (ps.isGroup) { Group g = ps.find ? finder.findGroup(ps.pattern, ps.rep) : finder.getGroup(ps.pattern, ps.rep); finder = new SegmentFinder(g); } else { seg = ps.find ? finder.findSegment(ps.pattern, ps.rep) : finder.getSegment(ps.pattern, ps.rep);
/** * Returns the first matching structure AFTER the current position */ private Structure findStructure(String namePattern, int rep) throws HL7Exception { Structure s = null; while (s == null) { String currentNameInParent = iterate(false, false); String currentName = getCurrentStructure(0).getName(); if (matches(namePattern, currentName) || matches(namePattern, currentNameInParent)) { s = getCurrentStructure(rep); } } return s; }
/** * As getSegment() but will only return a group. */ public Group getGroup(String namePattern, int rep) throws HL7Exception { Structure s = getStructure(namePattern, rep); if (!Group.class.isAssignableFrom(s.getClass())) { throw new HL7Exception(s.getName() + " is not a group"); } return (Group) s; }
private Structure getStructure(String namePattern, int rep) throws HL7Exception { Structure s = null; if (getCurrentStructure(0).equals(this.getRoot())) drillDown(0); String[] names = getCurrentStructure(0).getParent().getNames(); for (int i = 0; i < names.length && s == null; i++) { if (matches(namePattern, names[i])) { toChild(i); s = getCurrentStructure(rep); } } if (s == null) throw new HL7Exception("Can't find " + namePattern + " as a direct child"); return s; }
/** * As findSegment(), but will only return a group. */ public Group findGroup(String namePattern, int rep) throws HL7Exception { Structure s; do { s = findStructure(namePattern, rep); } while (!Group.class.isAssignableFrom(s.getClass())); return (Group) s; }
/** * Returns the first segment with a name matching the given pattern that is a sibling of * the structure at the current location. Other parts of the message are * not searched (in contrast to findSegment). * As a special case, if the pointer is at the root, the children of the root * are searched. * @param namePattern the name of the segment to get. The wildcad * means any number * of arbitrary characters; the wildard ? one arbitrary character * (eg "P*" or "*ID" or "???" or "P??" would match on PID). * @param rep the repetition of the segment to return */ public Segment getSegment(String namePattern, int rep) throws HL7Exception { Structure s = getStructure(namePattern, rep); if (!Segment.class.isAssignableFrom(s.getClass())) { throw new HL7Exception(s.getName() + " is not a segment"); } return (Segment) s; }
/** Creates a new instance of Terser * * @param message message for which the Terser is created */ public Terser(Message message) { if (message == null) { throw new NullPointerException("Message may not be null"); } finder = new SegmentFinder(message); }
/** * Returns the first segment with a name that matches the given pattern, in a depth-first search. * Repeated searches are initiated from the location just AFTER where the last segment was found. * Call reset() is this is not desired. Note: this means that the current location will not be found. * @param namePattern the name of the segment to find. The wildcard * means any number * of arbitrary characters; the wildcard ? one arbitrary character * (eg "P*" or "*ID" or "???" or "P??" would match on PID). * @param rep the repetition of the segment to return */ public Segment findSegment(String namePattern, int rep) throws HL7Exception { Structure s = null; do { s = findStructure(namePattern, rep); } while (!Segment.class.isAssignableFrom(s.getClass())); return (Segment) s; }
/** * Returns the first segment with a name matching the given pattern that is a sibling of * the structure at the current location. Other parts of the message are * not searched (in contrast to findSegment). * As a special case, if the pointer is at the root, the children of the root * are searched. * @param namePattern the name of the segment to get. The wildcad * means any number * of arbitrary characters; the wildard ? one arbitrary character * (eg "P*" or "*ID" or "???" or "P??" would match on PID). * @param rep the repetition of the segment to return */ public Segment getSegment(String namePattern, int rep) throws HL7Exception { Structure s = getStructure(namePattern, rep); if (!Segment.class.isAssignableFrom(s.getClass())) { throw new HL7Exception(s.getName() + " is not a segment"); } return (Segment) s; }
/** * Returns the first segment with a name that matches the given pattern, in a depth-first search. * Repeated searches are initiated from the location just AFTER where the last segment was found. * Call reset() is this is not desired. Note: this means that the current location will not be found. * @param namePattern the name of the segment to find. The wildcard * means any number * of arbitrary characters; the wildcard ? one arbitrary character * (eg "P*" or "*ID" or "???" or "P??" would match on PID). * @param rep the repetition of the segment to return */ public Segment findSegment(String namePattern, int rep) throws HL7Exception { Structure s = null; do { s = findStructure(namePattern, rep); } while (!Segment.class.isAssignableFrom(s.getClass())); return (Segment) s; }