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