private HL7Exception[] doTestGroup(Group group, AbstractSegmentContainer profile, String profileID, boolean theValidateChildren) throws ProfileException {
ArrayList<HL7Exception> exList = new ArrayList<HL7Exception>(20);
ArrayList<String> allowedStructures = new ArrayList<String>(20);
for (int i = 1; i <= profile.getChildren(); i++) {
ProfileStructure struct = profile.getChild(i);
//only test a structure in detail if it isn't X
if (!struct.getUsage().equalsIgnoreCase("X")) {
allowedStructures.add(struct.getName());
//see which instances have content
try {
Structure[] instances = group.getAll(struct.getName());
ArrayList<Structure> instancesWithContent = new ArrayList<Structure>(10);
for (int j = 0; j < instances.length; j++) {
if (hasContent(instances[j])) instancesWithContent.add(instances[j]);
}
HL7Exception ce = testCardinality(instancesWithContent.size(),
struct.getMin(), struct.getMax(), struct.getUsage(), struct.getName());
if (ce != null) exList.add(ce);
//test children on instances with content
if (theValidateChildren) {
for (int j = 0; j < instancesWithContent.size(); j++) {
Structure s = (Structure) instancesWithContent.get(j);
HL7Exception[] childExceptions = testStructure(s, struct, profileID);
addToList(childExceptions, exList);
}
}
} catch (HL7Exception he) {
exList.add(new ProfileNotHL7CompliantException(struct.getName() + " not found in message"));
}
}
}
//complain about X structures that have content