/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
- * This program and the accompanying materials are made available under the terms of the Eclipse
- * Public License v1.0 which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
+
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import com.google.common.base.Verify;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
LOG.debug("Could not validate {}, does not implement expected class {}", nodeMod, ModifiedNode.class);
return;
}
- final ModifiedNode modification = (ModifiedNode) nodeMod;
- final int childrenBefore = findChildrenBefore(current);
+ final ModifiedNode modification = (ModifiedNode) nodeMod;
+ final int childrenBefore = (modification.getOperation() == LogicalOperation.WRITE) ? 0 : findChildrenBefore
+ (current);
+ Verify.verify(childrenBefore >= 0, "Child count before is %s (from %s)", childrenBefore, current);
final int childrenAfter = findChildrenAfter(modification);
+ Verify.verify(childrenAfter >= 0, "Child count after is %s (from %s)", childrenAfter, modification);
+
+ final int childrenModified = numOfChildrenFromChildMods(modification, current);
+ LOG.debug("Modified child count is %s (from %s and %s)", childrenModified, modification, current);
+
+ final int childrenTotal = childrenBefore + childrenAfter + childrenModified;
+ Verify.verify(childrenTotal >= 0, "Total child count is %s (from %s and %s)", childrenTotal, modification, current);
- final int childrenTotal = childrenBefore + childrenAfter + numOfChildrenFromChildMods(modification, current);
if (minElements != null && minElements > childrenTotal) {
throw new DataValidationFailedException(path, String.format(
"%s does not have enough elements (%s), needs at least %s", modification.getIdentifier(),
for (final ModifiedNode modChild : modification.getChildren()) {
switch (modChild.getOperation()) {
case WRITE:
- result++;
+ if (!checkOriginalPresent(modChild)) {
+ result++;
+ }
break;
case MERGE:
- if (!current.isPresent()) {
+ if (!checkOriginalPresent(modChild)) {
result++;
}
break;
case DELETE:
- result--;
+ if (checkOriginalPresent(modChild)) {
+ result--;
+ }
break;
case NONE:
case TOUCH:
return result;
}
+ private static boolean checkOriginalPresent(ModifiedNode child) {
+ return child.getOriginal().isPresent();
+ }
+
@Override
protected void checkTouchApplicable(final YangInstanceIdentifier path, final NodeModification modification,
final Optional<TreeNode> current) throws DataValidationFailedException {
}
@Override
- void verifyStructure(final ModifiedNode modification) throws IllegalArgumentException {
- delegate.verifyStructure(modification);
+ protected void verifyStructure(final NormalizedNode<?, ?> modification, final boolean verifyChildren) {
+ delegate.verifyStructure(modification, verifyChildren);
}
@Override
}
@Override
- protected void verifyWrittenStructure(final NormalizedNode<?, ?> writtenValue) {
- delegate.verifyWrittenStructure(writtenValue);
+ protected ChildTrackingPolicy getChildPolicy() {
+ return delegate.getChildPolicy();
}
@Override
- protected ChildTrackingPolicy getChildPolicy() {
- return delegate.getChildPolicy();
+ void mergeIntoModifiedNode(final ModifiedNode node, final NormalizedNode<?, ?> value, final Version version) {
+ delegate.mergeIntoModifiedNode(node, value, version);
+ }
+
+ @Override
+ void recursivelyVerifyStructure(NormalizedNode<?, ?> value) {
+ delegate.recursivelyVerifyStructure(value);
}
}