From 95a09595da1e5385047ddd1ce773b784f7671f8e Mon Sep 17 00:00:00 2001 From: Moiz Raja Date: Fri, 22 May 2015 17:46:00 -0700 Subject: [PATCH] BUG 2970 : Throw a specific exception when schema validation fails 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 --- .../tree/InMemoryDataTreeModification.java | 2 +- .../tree/SchemaValidationFailedException.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/SchemaValidationFailedException.java diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeModification.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeModification.java index 032bd927a4..21ccb1962d 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeModification.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeModification.java @@ -153,7 +153,7 @@ final class InMemoryDataTreeModification implements DataTreeModification { for(final PathArgument pathArg : path.getPathArguments()) { final Optional 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 index 0000000000..f55270ca1f --- /dev/null +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/SchemaValidationFailedException.java @@ -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); + } + +} -- 2.36.6