5a85e9425783c4171ce41d52b01dd71b9a3c9079
[controller.git] / opendaylight / netconf / netconf-api / src / main / java / org / opendaylight / controller / netconf / api / NetconfDocumentedException.java
1 /*
2  * Copyright (c) 2013 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
9 package org.opendaylight.controller.netconf.api;
10
11 import java.util.Collections;
12 import java.util.Map;
13
14 /**
15  * Checked exception to communicate an error that needs to be sent to the
16  * netconf client.
17  */
18 public class NetconfDocumentedException extends Exception {
19
20     private static final long serialVersionUID = 1L;
21
22     public enum ErrorType {
23         transport, rpc, protocol, application;
24
25         public String getTagValue() {
26             return name();
27         }
28     }
29
30     public enum ErrorTag {
31         missing_attribute("missing-attribute"), unknown_element("unknown-element"), operation_not_supported(
32                 "operation-not-supported"), bad_attribute("bad-attribute"), data_missing("data-missing"), operation_failed(
33                 "operation-failed"), invalid_value("invalid-value"), malformed_message("malformed-message");
34
35         private final String tagValue;
36
37         ErrorTag(final String tagValue) {
38             this.tagValue = tagValue;
39         }
40
41         public String getTagValue() {
42             return this.tagValue;
43         }
44     }
45
46     public enum ErrorSeverity {
47         error, warning;
48
49         public String getTagValue() {
50             return name();
51         }
52     }
53
54     private final ErrorType errorType;
55     private final ErrorTag errorTag;
56     private final ErrorSeverity errorSeverity;
57     private final Map<String, String> errorInfo;
58
59     public NetconfDocumentedException(final String message, final ErrorType errorType, final ErrorTag errorTag,
60             final ErrorSeverity errorSeverity) {
61         this(message, errorType, errorTag, errorSeverity, Collections.<String, String> emptyMap());
62     }
63
64     public NetconfDocumentedException(final String message, final ErrorType errorType, final ErrorTag errorTag,
65             final ErrorSeverity errorSeverity, final Map<String, String> errorInfo) {
66         super(message);
67         this.errorType = errorType;
68         this.errorTag = errorTag;
69         this.errorSeverity = errorSeverity;
70         this.errorInfo = errorInfo;
71     }
72
73     public NetconfDocumentedException(final String message, final Exception cause, final ErrorType errorType,
74             final ErrorTag errorTag, final ErrorSeverity errorSeverity) {
75         this(message, cause, errorType, errorTag, errorSeverity, Collections.<String, String> emptyMap());
76     }
77
78     public NetconfDocumentedException(final String message, final Exception cause, final ErrorType errorType,
79             final ErrorTag errorTag, final ErrorSeverity errorSeverity, final Map<String, String> errorInfo) {
80         super(message, cause);
81         this.errorType = errorType;
82         this.errorTag = errorTag;
83         this.errorSeverity = errorSeverity;
84         this.errorInfo = errorInfo;
85     }
86
87     public ErrorType getErrorType() {
88         return this.errorType;
89     }
90
91     public ErrorTag getErrorTag() {
92         return this.errorTag;
93     }
94
95     public ErrorSeverity getErrorSeverity() {
96         return this.errorSeverity;
97     }
98
99     public Map<String, String> getErrorInfo() {
100         return this.errorInfo;
101     }
102
103     @Override
104     public String toString() {
105         return "NetconfDocumentedException{" + "message=" + getMessage() + ", errorType=" + this.errorType
106                 + ", errorTag=" + this.errorTag + ", errorSeverity=" + this.errorSeverity + ", errorInfo="
107                 + this.errorInfo + '}';
108     }
109 }