Adopt odlparent-10.0.0/yangtools-8.0.0-SNAPSHOT
[mdsal.git] / common / mdsal-common-api / src / main / java / org / opendaylight / mdsal / common / api / DataValidationFailedException.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.mdsal.common.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.opendaylight.yangtools.concepts.HierarchicalIdentifier;
13 import org.opendaylight.yangtools.yang.common.ErrorTag;
14 import org.opendaylight.yangtools.yang.common.ErrorType;
15 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
16
17 /**
18  * Failure of asynchronous transaction commit caused by invalid data. This exception is raised and returned when
19  * a transaction commit failed, because other data submitted via transactions.
20  *
21  * <p>
22  * Clients usually are not able recover from this error condition by retrieving same transaction, since data introduced
23  * by this transaction is invalid.
24  */
25 public class DataValidationFailedException extends TransactionCommitFailedException {
26     private static final long serialVersionUID = 1L;
27
28     private final HierarchicalIdentifier<?> path;
29     private final Class<? extends HierarchicalIdentifier<?>> pathType;
30
31     public <P extends HierarchicalIdentifier<P>> DataValidationFailedException(final Class<P> pathType, final P path,
32             final String message, final Throwable cause) {
33         super(message, cause, RpcResultBuilder.newError(ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, message, null,
34             path != null ? path.toString() : null, cause));
35         this.pathType = requireNonNull(pathType, "path type must not be null");
36         this.path = requireNonNull(path, "path must not be null.");
37     }
38
39     public <P extends HierarchicalIdentifier<P>> DataValidationFailedException(final Class<P> pathType, final P path,
40             final String message) {
41         this(pathType, path, message, null);
42     }
43
44     public final HierarchicalIdentifier<?> getPath() {
45         return path;
46     }
47
48     public final Class<? extends HierarchicalIdentifier<?>> getPathType() {
49         return pathType;
50     }
51 }