BUG 2970 : Throw a specific exception when schema validation fails 18/21018/4
authorMoiz Raja <moraja@cisco.com>
Sat, 23 May 2015 00:46:00 +0000 (17:46 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 28 May 2015 07:20:39 +0000 (07:20 +0000)
When resolving a modification if there is a failure in validating
a data node because it's schema is not present we should throw
a specific exception instead of just an IllegalArgument exception.

This specific exception can be used by CDS to determine if the failure
to add a node was due to a schema validation failure and then we will
attempt to prune data from the normalized node so that the invalid
data elements are removed.

Change-Id: Ieba347c29a9e92ea6aa7ccc2570935cd7a233b8e
Signed-off-by: Moiz Raja <moraja@cisco.com>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeModification.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/SchemaValidationFailedException.java [new file with mode: 0644]

index 032bd927a42b4eec10c966b9ce2d49c7fdbfa696..21ccb1962d49f5189d24c90ae6f31a18d32b1648 100644 (file)
@@ -153,7 +153,7 @@ final class InMemoryDataTreeModification implements DataTreeModification {
         for(final PathArgument pathArg : path.getPathArguments()) {
             final Optional<ModificationApplyOperation> potential = operation.getChild(pathArg);
             if (!potential.isPresent()) {
-                throw new IllegalArgumentException(String.format("Child %s is not present in schema tree.",
+                throw new SchemaValidationFailedException(String.format("Child %s is not present in schema tree.",
                         Iterables.toString(Iterables.limit(path.getPathArguments(), i))));
             }
             operation = potential.get();
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/SchemaValidationFailedException.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/SchemaValidationFailedException.java
new file mode 100644 (file)
index 0000000..f55270c
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * 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
+ */
+
+package org.opendaylight.yangtools.yang.data.impl.schema.tree;
+
+/**
+ * SchemaValidationFailedException is thrown when an attempt is made to modify the data tree and the modification
+ * does not match the schema context
+ */
+public class SchemaValidationFailedException extends IllegalArgumentException {
+
+    private static final long serialVersionUID = 1L;
+
+    public SchemaValidationFailedException(String message){
+        super(message);
+    }
+
+    public SchemaValidationFailedException(String message, Throwable cause){
+        super(message, cause);
+    }
+
+}