bc393dde4fd8561829007d30b0794a105c98eb22
[controller.git] / opendaylight / md-sal / sal-common-api / src / main / java / org / opendaylight / controller / md / sal / common / api / data / 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.controller.md.sal.common.api.data;
9
10 import com.google.common.base.Preconditions;
11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import org.opendaylight.yangtools.concepts.Path;
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.
18  *
19  * <p>
20  * This exception is raised and returned when transaction commit
21  * failed, because other data submitted via transactions.
22  *
23  * <p>
24  * Clients usually are not able recover from this error condition by
25  * retrieving same transaction, since data introduced by this transaction
26  * are invalid.
27  *
28  * @deprecated Use {@link org.opendaylight.mdsal.common.api.DataValidationFailedException} instead.
29  */
30 @Deprecated
31 public class DataValidationFailedException extends TransactionCommitFailedException {
32
33     private static final long serialVersionUID = 1L;
34
35     @SuppressFBWarnings("SE_BAD_FIELD")
36     private final Path<?> path;
37
38     private final Class<? extends Path<?>> pathType;
39
40     public <P extends Path<P>> DataValidationFailedException(final Class<P> pathType,final P path,
41                                                              final String message, final Throwable cause) {
42         super(message, cause, RpcResultBuilder.newError(ErrorType.APPLICATION, "invalid-value", message, null,
43                                                         path != null ? path.toString() : null, cause));
44         this.pathType = Preconditions.checkNotNull(pathType, "path type must not be null");
45         this.path = Preconditions.checkNotNull(path,"path must not be null.");
46     }
47
48     public  <P extends Path<P>> DataValidationFailedException(final Class<P> pathType,final P path,
49                                                               final String message) {
50         this(pathType, path, message, null);
51     }
52
53     public final Path<?> getPath() {
54         return path;
55     }
56
57     public final Class<? extends Path<?>> getPathType() {
58         return pathType;
59     }
60 }