protected List<ValidationException> testField( Type type, SegmentType.Field profile, boolean escape) { List<ValidationException> exList = new ArrayList<>(); UsageInfo usage = new UsageInfo(profile); // account for MSH 1 & 2 which aren't escaped String encoded = null; if (!escape && Primitive.class.isAssignableFrom(type.getClass())) encoded = ((Primitive) type).getValue(); exList.addAll(testType(type, profile.getDatatype(), usage, encoded, false)); // test children if (validateChildren) { if (profile.getComponents().size() > 0 && !usage.disallowed()) { if (Composite.class.isAssignableFrom(type.getClass())) { Composite comp = (Composite) type; int i = 1; boolean nullContext = false; for (SegmentType.Field.Component component : profile.getComponents()) { try { SegmentType.Field.Component component2; if (nullContext) { component2 = new SegmentType.Field.Component(); try { BeanUtils.copyProperties(component2, component); } catch (InvocationTargetException | IllegalAccessException e) { // nop } component2.setUsage("NULL"); } else { component2 = component; if ((i == 1) && profile.isNullable() && PipeParser.encode(comp.getComponent(0), this.enc).equals("\"\"")) { nullContext = true; } } exList.addAll(testComponent(comp.getComponent(i - 1), component2)); } catch (DataTypeException de) { profileNotHL7Compliant(exList, COMPONENT_TYPE_MISMATCH, type.getName(), i); } ++i; } exList.addAll(checkUndefinedComponents(comp, profile.getComponents().size())); } else { profileNotHL7Compliant(exList, WRONG_FIELD_TYPE, type.getClass().getName()); } } } return exList; }