4bae92e85f8f67856ee6af65433e65649f79627f
[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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13 import org.opendaylight.yangtools.concepts.Path;
14 import org.opendaylight.yangtools.yang.common.RpcError.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
27     private static final long serialVersionUID = 1L;
28
29     @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "Interfaces do not specify Serializable")
30     private final Path<?> path;
31
32     private final Class<? extends Path<?>> pathType;
33
34     public <P extends Path<P>> DataValidationFailedException(final Class<P> pathType, final P path,
35             final String message, final Throwable cause) {
36         super(message, cause, RpcResultBuilder.newError(ErrorType.APPLICATION, "invalid-value", message, null,
37             path != null ? path.toString() : null, cause));
38         this.pathType = requireNonNull(pathType, "path type must not be null");
39         this.path = requireNonNull(path, "path must not be null.");
40     }
41
42     public <P extends Path<P>> DataValidationFailedException(final Class<P> pathType, final P path,
43             final String message) {
44         this(pathType, path, message, null);
45     }
46
47     public final Path<?> getPath() {
48         return path;
49     }
50
51     public final Class<? extends Path<?>> getPathType() {
52         return pathType;
53     }
54 }