a928582ac0faa78aea4a9a7fa1ca5ec3c10f71c5
[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.RpcError.ErrorType;
14 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
15
16 /**
17  * Failure of asynchronous transaction commit caused by invalid data. This exception is raised and returned when
18  * a transaction commit failed, because other data submitted via transactions.
19  *
20  * <p>
21  * Clients usually are not able recover from this error condition by retrieving same transaction, since data introduced
22  * by this transaction is invalid.
23  */
24 public class DataValidationFailedException extends TransactionCommitFailedException {
25     private static final long serialVersionUID = 1L;
26
27     private final HierarchicalIdentifier<?> path;
28     private final Class<? extends HierarchicalIdentifier<?>> pathType;
29
30     public <P extends HierarchicalIdentifier<P>> DataValidationFailedException(final Class<P> pathType, final P path,
31             final String message, final Throwable cause) {
32         super(message, cause, RpcResultBuilder.newError(ErrorType.APPLICATION, "invalid-value", message, null,
33             path != null ? path.toString() : null, cause));
34         this.pathType = requireNonNull(pathType, "path type must not be null");
35         this.path = requireNonNull(path, "path must not be null.");
36     }
37
38     public <P extends HierarchicalIdentifier<P>> DataValidationFailedException(final Class<P> pathType, final P path,
39             final String message) {
40         this(pathType, path, message, null);
41     }
42
43     public final HierarchicalIdentifier<?> getPath() {
44         return path;
45     }
46
47     public final Class<? extends HierarchicalIdentifier<?>> getPathType() {
48         return pathType;
49     }
50 }