9d2b88702eba612dcfc55c01d8f6d9d54e3af49f
[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 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  * Failure of asynchronous transaction commit caused by invalid data.
17  *
18  * <p>
19  * This exception is raised and returned when transaction commit
20  * failed, because other data submitted via transactions.
21  *
22  * <p>
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 public class DataValidationFailedException extends TransactionCommitFailedException {
28
29     private static final long serialVersionUID = 1L;
30
31     private final Path<?> path;
32
33     private final Class<? extends Path<?>> pathType;
34
35     public <P extends Path<P>> DataValidationFailedException(final Class<P> pathType,final P path,
36                                                              final String message, final Throwable cause) {
37         super(message, cause, RpcResultBuilder.newError(ErrorType.APPLICATION, "invalid-value", message, null,
38                                                         path != null ? path.toString() : null, cause));
39         this.pathType = Preconditions.checkNotNull(pathType, "path type must not be null");
40         this.path = Preconditions.checkNotNull(path,"path must not be null.");
41     }
42
43     public  <P extends Path<P>> DataValidationFailedException(final Class<P> pathType,final P path,
44                                                               final String message) {
45         this(pathType, path, message, null);
46     }
47
48     public final Path<?> getPath() {
49         return path;
50     }
51
52     public final Class<? extends Path<?>> getPathType() {
53         return pathType;
54     }
55 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.