- @Override
- protected void checkWriteApplicable(final YangInstanceIdentifier path, final NodeModification modification,
- final Optional<TreeNode> current, final Version version) throws DataValidationFailedException {
- delegate.checkWriteApplicable(path, modification, current, version);
- checkMinMaxElements(path, modification, current, version);
- }
-
- @Override
- public Optional<ModificationApplyOperation> getChild(final PathArgument child) {
- return delegate.getChild(child);
- }
-
- @Override
- protected void verifyStructure(final NormalizedNode<?, ?> modification, final boolean verifyChildren) {
- delegate.verifyStructure(modification, verifyChildren);
- if (verifyChildren) {
- final int children = numOfChildrenFromValue(modification);
- Preconditions.checkArgument(minElements <= children,
- "Node %s does not have enough elements (%s), needs at least %s", modification.getIdentifier(),
- children, minElements);
- Preconditions.checkArgument(maxElements >= children,
- "Node %s has too many elements (%s), can have at most %s", modification.getIdentifier(), children,
- maxElements);
+ private void validateMinMaxElements(final ModificationPath path, final NormalizedNode<?, ?> value)
+ throws DataValidationFailedException {
+ final PathArgument id = value.getIdentifier();
+ final int children = numOfChildrenFromValue(value);
+ if (minElements > children) {
+ throw new RequiredElementCountException(path.toInstanceIdentifier(), minElements, maxElements, children,
+ "%s does not have enough elements (%s), needs at least %s", id, children, minElements);