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