map.remove(tag); if (!cardinality.isValid(count)) { build(sb, "The number of occurrences (%d) for tag '%s' falls outside the range of %d - %d.", count, tag, cardinality.getMinimum(), cardinality.getMaximum()); if (child.getValue().getMinimum() > 0) { build(sb, "A required child tag (%s) is missing.", child.getKey());
private void addChildElement(Element seq, ComponentDefinition childDef, ComponentDefinition parentDef, Cardinality card) { if (childDef.getTag().startsWith("#")) { return; } if (childDef != null && !childDef.isParentTag(parentDef.getTag())) { return; } Element child = createElement("element", seq, "ref", childDef.getTag()); child.setAttribute("minOccurs", Integer.toString(card.getMinimum())); if (card.hasMaximum()) { child.setAttribute("maxOccurs", Integer.toString(card.getMaximum())); } else { child.setAttribute("maxOccurs", "unbounded"); } }
public void validateChild(ComponentDefinition childDefinition, IntSupplier childCount) { if (!childrenAllowed()) { throw new ComponentException(componentClass, "Children are not allowed"); } childDefinition.validateParent(this); Cardinality cardinality = getCardinality(childDefinition.tag); if (cardinality == null) { throw new ComponentException(componentClass, "%s is not a valid child", childDefinition.componentClass); } if (cardinality.hasMaximum() && childCount.getAsInt() >= cardinality.getMaximum()) { throw new ComponentException(componentClass, "A maximum of %d children of type %s are allowed", cardinality.getMaximum(), childDefinition.componentClass); } }
/** * Registers a child tag. * * @param tag A child tag. */ private void addChildTag(ChildTag tag) { childTags.put(tag.value(), new Cardinality(tag.minimum(), tag.maximum())); }