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