/** * Remove message name prefix from group names for compatibility with getters. Due to * 3558962 we also need to look at the message's super classes to enable custom * messages that reuse groups from their ancestors. * * @param name the simple name of the group * @return the abbreviated group in name in case of matching prefixes */ private String getGroupName(String name) { Class<?> messageClass = getMessage().getClass(); while (Message.class.isAssignableFrom(messageClass)) { @SuppressWarnings("unchecked") // actually we should call getName() instead of getName(Class), but this // is due to issue 3558962 String messageName = getName((Class<? extends Message>)messageClass); if (name.startsWith(messageName) && name.length() > messageName.length()) { return name.substring(messageName.length() + 1); } messageClass = messageClass.getSuperclass(); } return name; }
/** * Remove message name prefix from group names for compatibility with getters. Due to * 3558962 we also need to look at the message's super classes to enable custom * messages that reuse groups from their ancestors. * * @param name the simple name of the group * @return the abbreviated group in name in case of matching prefixes */ private String getGroupName(String name) { Class<?> messageClass = getMessage().getClass(); while (Message.class.isAssignableFrom(messageClass)) { @SuppressWarnings("unchecked") // actually we should call getName() instead of getName(Class), but this // is due to issue 3558962 String messageName = getName((Class<? extends Message>)messageClass); if (name.startsWith(messageName) && name.length() > messageName.length()) { return name.substring(messageName.length() + 1); } messageClass = messageClass.getSuperclass(); } return name; }
/** * Inserts a repetition of a given Structure into repetitions of that structure by name. For * example, if the Group contains 10 repetitions an OBX segment and an OBX is supplied with an * index of 2, then this call would insert the new repetition at index 2. (Note that in this * example, the Set ID field in the OBX segments would also need to be renumbered manually). * * @throws HL7Exception if the named Structure is not part of this Group. */ protected void insertRepetition(String name, Structure structure, int index) throws HL7Exception { if (structure == null) { throw new NullPointerException("Structure may not be null"); } if (structure.getMessage() != this.getMessage()) { throw new HL7Exception("Structure does not belong to this message"); } List<Structure> list = structures.get(name); if (list == null) { throw new HL7Exception("The structure " + name + " does not exist in the group " + this.getClass().getName()); } if (list.size() < index) { throw new HL7Exception("Invalid index: " + index + ", structure " + name + " must be between 0 and " + (list.size())); } list.add(index, structure); }
/** * Inserts a repetition of a given Structure into repetitions of that structure by name. For * example, if the Group contains 10 repetitions an OBX segment and an OBX is supplied with an * index of 2, then this call would insert the new repetition at index 2. (Note that in this * example, the Set ID field in the OBX segments would also need to be renumbered manually). * * @throws HL7Exception if the named Structure is not part of this Group. */ protected void insertRepetition(String name, Structure structure, int index) throws HL7Exception { if (structure == null) { throw new NullPointerException("Structure may not be null"); } if (structure.getMessage() != this.getMessage()) { throw new HL7Exception("Structure does not belong to this message"); } List<Structure> list = structures.get(name); if (list == null) { throw new HL7Exception("The structure " + name + " does not exist in the group " + this.getClass().getName()); } if (list.size() < index) { throw new HL7Exception("Invalid index: " + index + ", structure " + name + " must be between 0 and " + (list.size())); } list.add(index, structure); }
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; }
EncodingCharacters.getInstance(getMessage()))); theStringBuilder.append(lineSeparator);
EncodingCharacters.getInstance(getMessage()))); theStringBuilder.append(lineSeparator);