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