/** * Adds a new Structure (group or segment) to this Group. A place for the Structure is added to * the group but there are initially zero repetitions. This method should be used by the * constructors of implementing classes to specify which Structures the Group contains - * Structures should be added in the order in which they appear. Note that the class is supplied * instead of an instance because we want there initially to be zero instances of each structure * but we want the AbstractGroup code to be able to create instances as necessary to support * get(...) calls. * * @return the actual name used to store this structure (may be appended with an integer if * there are duplicates in the same Group). */ protected String add(Class<? extends Structure> c, boolean required, boolean repeating, boolean choiceElement) throws HL7Exception { String name = getName(c); return insert(c, required, repeating, choiceElement, this.names.size(), name); }
/** * Adds a new Structure (group or segment) to this Group. A place for the Structure is added to * the group but there are initially zero repetitions. This method should be used by the * constructors of implementing classes to specify which Structures the Group contains - * Structures should be added in the order in which they appear. Note that the class is supplied * instead of an instance because we want there initially to be zero instances of each structure * but we want the AbstractGroup code to be able to create instances as necessary to support * get(...) calls. * * @return the actual name used to store this structure (may be appended with an integer if * there are duplicates in the same Group). */ protected String add(Class<? extends Structure> c, boolean required, boolean repeating, boolean choiceElement) throws HL7Exception { String name = getName(c); return insert(c, required, repeating, choiceElement, this.names.size(), name); }
/** * Adds a new Structure (group or segment) to this Group. A place for the Structure is added to * the group but there are initially zero repetitions. This method should be used by the * constructors of implementing classes to specify which Structures the Group contains - * Structures should be added in the order in which they appear. Note that the class is supplied * instead of an instance because we want there initially to be zero instances of each structure * but we want the AbstractGroup code to be able to create instances as necessary to support * get(...) calls. * * @return the actual name used to store this structure (may be appended with an integer if * there are duplicates in the same Group). */ protected String add(Class<? extends Structure> c, boolean required, boolean repeating, int index) throws HL7Exception { String name = getName(c); return insert(c, required, repeating, index, name); }
/** * Adds a new Structure (group or segment) to this Group. A place for the Structure is added to * the group but there are initially zero repetitions. This method should be used by the * constructors of implementing classes to specify which Structures the Group contains - * Structures should be added in the order in which they appear. Note that the class is supplied * instead of an instance because we want there initially to be zero instances of each structure * but we want the AbstractGroup code to be able to create instances as necessary to support * get(...) calls. * * @return the actual name used to store this structure (may be appended with an integer if * there are duplicates in the same Group). */ protected String add(Class<? extends Structure> c, boolean required, boolean repeating, int index) throws HL7Exception { String name = getName(c); return insert(c, required, repeating, index, name); }
protected String insert(Class<? extends Structure> c, boolean required, boolean repeating, boolean choiceElement, int index, String name) throws HL7Exception { // tryToInstantiateStructure(c, name); //may throw exception // see if there is already something by this name and make a new name if // necessary ... if (nameExists(name)) { int version = 2; String newName = name; while (nameExists(newName)) { newName = name + version++; } name = newName; } if (index > this.names.size()) { throw new HL7Exception("Invalid index " + index + " - Should be <= " + this.names.size()); } this.names.add(index, name); this.required.put(name, required); this.repeating.put(name, repeating); this.classes.put(name, c); this.structures.put(name, new ArrayList<Structure>()); if (choiceElement) { this.choiceElements.add(name); } return name; }
protected String insert(Class<? extends Structure> c, boolean required, boolean repeating, boolean choiceElement, int index, String name) throws HL7Exception { // tryToInstantiateStructure(c, name); //may throw exception // see if there is already something by this name and make a new name if // necessary ... if (nameExists(name)) { int version = 2; String newName = name; while (nameExists(newName)) { newName = name + version++; } name = newName; } if (index > this.names.size()) { throw new HL7Exception("Invalid index " + index + " - Should be <= " + this.names.size()); } this.names.add(index, name); this.required.put(name, required); this.repeating.put(name, repeating); this.classes.put(name, c); this.structures.put(name, new ArrayList<Structure>()); if (choiceElement) { this.choiceElements.add(name); } return name; }
public String addNonstandardSegment(String theName, int theIndex) throws HL7Exception { if (this instanceof Message && theIndex == 0) { throw new HL7Exception("Can not add nonstandard segment \"" + theName + "\" to start of message."); } String version = this.getMessage().getVersion(); if (version == null) throw new HL7Exception("Need message version to add segment by name; message.getVersion() returns null"); Class<? extends Segment> c = myFactory.getSegmentClass(theName, version); if (c == null) { c = GenericSegment.class; } tryToInstantiateStructure(c, theName); // may throw exception String newName = insert(c, false, true, theIndex, theName); if (this.nonStandardNames == null) { this.nonStandardNames = new HashSet<String>(); } this.nonStandardNames.add(newName); return newName; }
public String addNonstandardSegment(String theName, int theIndex) throws HL7Exception { if (this instanceof Message && theIndex == 0) { throw new HL7Exception("Can not add nonstandard segment \"" + theName + "\" to start of message."); } String version = this.getMessage().getVersion(); if (version == null) throw new HL7Exception("Need message version to add segment by name; message.getVersion() returns null"); Class<? extends Segment> c = myFactory.getSegmentClass(theName, version); if (c == null) { c = GenericSegment.class; } tryToInstantiateStructure(c, theName); // may throw exception String newName = insert(c, false, true, theIndex, theName); if (this.nonStandardNames == null) { this.nonStandardNames = new HashSet<String>(); } this.nonStandardNames.add(newName); return newName; }
/** * Expands the group definition to include a segment that is not defined by HL7 to be part of * this group (eg an unregistered Z segment). The new segment is slotted at the end of the * group. Thenceforward if such a segment is encountered it will be parsed into this location. * If the segment name is unrecognized a GenericSegment is used. The segment is defined as * repeating and not required. */ public String addNonstandardSegment(String name) throws HL7Exception { String version = this.getMessage().getVersion(); if (version == null) throw new HL7Exception("Need message version to add segment by name; message.getVersion() returns null"); Class<? extends Segment> c = myFactory.getSegmentClass(name, version); if (c == null) c = GenericSegment.class; int index = this.getNames().length; tryToInstantiateStructure(c, name); // may throw exception String newName = insert(c, false, true, index, name); if (this.nonStandardNames == null) { this.nonStandardNames = new HashSet<String>(); } this.nonStandardNames.add(newName); return newName; }
/** * Expands the group definition to include a segment that is not defined by HL7 to be part of * this group (eg an unregistered Z segment). The new segment is slotted at the end of the * group. Thenceforward if such a segment is encountered it will be parsed into this location. * If the segment name is unrecognized a GenericSegment is used. The segment is defined as * repeating and not required. */ public String addNonstandardSegment(String name) throws HL7Exception { String version = this.getMessage().getVersion(); if (version == null) throw new HL7Exception("Need message version to add segment by name; message.getVersion() returns null"); Class<? extends Segment> c = myFactory.getSegmentClass(name, version); if (c == null) c = GenericSegment.class; int index = this.getNames().length; tryToInstantiateStructure(c, name); // may throw exception String newName = insert(c, false, true, index, name); if (this.nonStandardNames == null) { this.nonStandardNames = new HashSet<String>(); } this.nonStandardNames.add(newName); return newName; }