Decouple config and netconf subsystems.
[controller.git] / opendaylight / netconf / netconf-api / src / main / java / org / opendaylight / controller / netconf / api / NetconfDocumentedException.java
index 1ecbc55b2a02ac7af0757e777d960956cfddc0a0..9cf78c930be985c47b373501d982d723b1408f3f 100644 (file)
 
 package org.opendaylight.controller.netconf.api;
 
-import org.opendaylight.controller.config.api.ConflictingVersionException;
-import org.opendaylight.controller.config.api.ValidationException;
-
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.Map;
+import org.opendaylight.controller.config.util.xml.DocumentedException;
+import org.w3c.dom.Document;
 
 /**
  * Checked exception to communicate an error that needs to be sent to the
  * netconf client.
  */
-public class NetconfDocumentedException extends Exception {
-
-    private static final long serialVersionUID = 1L;
-
-
-
-    public enum ErrorType {
-        transport, rpc, protocol, application;
-
-        public String getTagValue() {
-            return name();
-        }
-    }
+public class NetconfDocumentedException extends DocumentedException {
 
-    public enum ErrorTag {
-        missing_attribute("missing-attribute"), unknown_element("unknown-element"), operation_not_supported(
-                "operation-not-supported"), bad_attribute("bad-attribute"), data_missing("data-missing"), operation_failed(
-                "operation-failed"), invalid_value("invalid-value"), malformed_message("malformed-message");
-
-        private final String tagValue;
-
-        ErrorTag(final String tagValue) {
-            this.tagValue = tagValue;
-        }
-
-        public String getTagValue() {
-            return this.tagValue;
-        }
-    }
-
-    public enum ErrorSeverity {
-        error, warning;
-
-        public String getTagValue() {
-            return name();
-        }
-    }
-
-    private final ErrorType errorType;
-    private final ErrorTag errorTag;
-    private final ErrorSeverity errorSeverity;
-    private final Map<String, String> errorInfo;
-
-    public NetconfDocumentedException(String message) {
-        this(message,
-                NetconfDocumentedException.ErrorType.application,
-                NetconfDocumentedException.ErrorTag.invalid_value,
-                NetconfDocumentedException.ErrorSeverity.error
-        );
-    }
-
-    public NetconfDocumentedException(final String message, final ErrorType errorType, final ErrorTag errorTag,
-            final ErrorSeverity errorSeverity) {
-        this(message, errorType, errorTag, errorSeverity, Collections.<String, String> emptyMap());
-    }
-
-    public NetconfDocumentedException(final String message, final ErrorType errorType, final ErrorTag errorTag,
-            final ErrorSeverity errorSeverity, final Map<String, String> errorInfo) {
+    public NetconfDocumentedException(final String message) {
         super(message);
-        this.errorType = errorType;
-        this.errorTag = errorTag;
-        this.errorSeverity = errorSeverity;
-        this.errorInfo = errorInfo;
-    }
-
-    public NetconfDocumentedException(final String message, final Exception cause, final ErrorType errorType,
-            final ErrorTag errorTag, final ErrorSeverity errorSeverity) {
-        this(message, cause, errorType, errorTag, errorSeverity, Collections.<String, String> emptyMap());
-    }
-
-    public NetconfDocumentedException(final String message, final Exception cause, final ErrorType errorType,
-            final ErrorTag errorTag, final ErrorSeverity errorSeverity, final Map<String, String> errorInfo) {
-        super(message, cause);
-        this.errorType = errorType;
-        this.errorTag = errorTag;
-        this.errorSeverity = errorSeverity;
-        this.errorInfo = errorInfo;
-    }
-
-    public static <E extends Exception> NetconfDocumentedException wrap(E exception) throws NetconfDocumentedException {
-        final Map<String, String> errorInfo = new HashMap<>();
-        errorInfo.put(ErrorTag.operation_failed.name(), "Exception thrown");
-        throw new NetconfDocumentedException(exception.getMessage(), exception, ErrorType.application, ErrorTag.operation_failed,
-                ErrorSeverity.error, errorInfo);
-    }
-    public static NetconfDocumentedException wrap(ValidationException e) throws NetconfDocumentedException {
-        final Map<String, String> errorInfo = new HashMap<>();
-        errorInfo.put(ErrorTag.operation_failed.name(), "Validation failed");
-        throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.application, ErrorTag.operation_failed,
-                ErrorSeverity.error, errorInfo);
     }
 
-    public static NetconfDocumentedException wrap(ConflictingVersionException e) throws NetconfDocumentedException {
-        final Map<String, String> errorInfo = new HashMap<>();
-        errorInfo.put(ErrorTag.operation_failed.name(), "Optimistic lock failed");
-        throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.application, ErrorTag.operation_failed,
-                ErrorSeverity.error, errorInfo);
+    public NetconfDocumentedException(final String message, final ErrorType errorType, final ErrorTag errorTag, final ErrorSeverity errorSeverity) {
+        super(message, errorType, errorTag, errorSeverity);
     }
 
-    public ErrorType getErrorType() {
-        return this.errorType;
+    public NetconfDocumentedException(final String message, final ErrorType errorType, final ErrorTag errorTag, final ErrorSeverity errorSeverity, final Map<String, String> errorInfo) {
+        super(message, errorType, errorTag, errorSeverity, errorInfo);
     }
 
-    public ErrorTag getErrorTag() {
-        return this.errorTag;
+    public NetconfDocumentedException(final String message, final Exception cause, final ErrorType errorType, final ErrorTag errorTag, final ErrorSeverity errorSeverity) {
+        super(message, cause, errorType, errorTag, errorSeverity);
     }
 
-    public ErrorSeverity getErrorSeverity() {
-        return this.errorSeverity;
+    public NetconfDocumentedException(final String message, final Exception cause, final ErrorType errorType, final ErrorTag errorTag, final ErrorSeverity errorSeverity, final Map<String, String> errorInfo) {
+        super(message, cause, errorType, errorTag, errorSeverity, errorInfo);
     }
 
-    public Map<String, String> getErrorInfo() {
-        return this.errorInfo;
+    public NetconfDocumentedException(DocumentedException e) {
+        super(e.getMessage(), e.getErrorType(), e.getErrorTag(), e.getErrorSeverity(), e.getErrorInfo());
     }
 
-    @Override
-    public String toString() {
-        return "NetconfDocumentedException{" + "message=" + getMessage() + ", errorType=" + this.errorType
-                + ", errorTag=" + this.errorTag + ", errorSeverity=" + this.errorSeverity + ", errorInfo="
-                + this.errorInfo + '}';
+    public static NetconfDocumentedException fromXMLDocument( Document fromDoc) {
+        return new NetconfDocumentedException(DocumentedException.fromXMLDocument(fromDoc));
     }
 }