Bug 7180 - error-severity and error-type values should be lowercase
[controller.git] / opendaylight / config / config-util / src / main / java / org / opendaylight / controller / config / util / xml / DocumentedException.java
index 736a4fc035eff377863c2d60e7683194f2477ff8..2f18bf0d0128f56dd3be876e47f31e9ace745a75 100644 (file)
@@ -10,6 +10,8 @@ package org.opendaylight.controller.config.util.xml;
 
 import static org.opendaylight.controller.config.util.xml.XmlMappingConstants.RPC_REPLY_KEY;
 import static org.opendaylight.controller.config.util.xml.XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0;
+
+import com.google.common.base.Preconditions;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -63,19 +65,37 @@ public class DocumentedException extends Exception {
     }
 
     public enum ErrorType {
-        TRANSPORT, RPC, PROTOCOL, APPLICATION;
+        TRANSPORT("transport"),
+        RPC("rpc"),
+        PROTOCOL("protocol"),
+        APPLICATION("application");
+
+        private final String typeValue;
 
+        ErrorType(String typeValue) {
+            this.typeValue = Preconditions.checkNotNull(typeValue);
+        }
+
+        public String getTypeValue() {
+            return this.typeValue;
+        }
+
+        /**
+         * @deprecated Use {@link #getTypeValue()} instead.
+         */
+        @Deprecated
         public String getTagValue() {
-            return name();
+            return this.typeValue;
         }
 
-        public static ErrorType from( String text ) {
-            try {
-                return valueOf( text.toUpperCase() );
-            }
-            catch( Exception e ) {
-                return APPLICATION;
+        public static ErrorType from(String text) {
+            for (ErrorType e : values()) {
+               if (e.getTypeValue().equalsIgnoreCase(text)) {
+                   return e;
+               }
             }
+
+            return APPLICATION;
         }
     }
 
@@ -123,19 +143,35 @@ public class DocumentedException extends Exception {
     }
 
     public enum ErrorSeverity {
-        ERROR, WARNING;
+        ERROR("error"),
+        WARNING("warning");
+
+        private final String severityValue;
 
+        ErrorSeverity(String severityValue) {
+            this.severityValue = Preconditions.checkNotNull(severityValue);
+        }
+
+        public String getSeverityValue() {
+            return this.severityValue;
+        }
+
+        /**
+         * @deprecated Use {@link #getSeverityValue()} instead.
+         */
+        @Deprecated
         public String getTagValue() {
-            return name();
+            return this.severityValue;
         }
 
-        public static ErrorSeverity from( String text ) {
-            try {
-                return valueOf( text.toUpperCase() );
-            }
-            catch( Exception e ) {
-                return ERROR;
+        public static ErrorSeverity from(String text) {
+            for (ErrorSeverity e : values()) {
+                if (e.getSeverityValue().equalsIgnoreCase(text)) {
+                    return e;
+                }
             }
+
+            return ERROR;
         }
     }
 
@@ -285,9 +321,9 @@ public class DocumentedException extends Exception {
             Node rpcError = doc.createElementNS( URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, RPC_ERROR );
             rpcReply.appendChild( rpcError );
 
-            rpcError.appendChild( createTextNode( doc, ERROR_TYPE, getErrorType().getTagValue() ) );
+            rpcError.appendChild( createTextNode( doc, ERROR_TYPE, getErrorType().getTypeValue() ) );
             rpcError.appendChild( createTextNode( doc, ERROR_TAG, getErrorTag().getTagValue() ) );
-            rpcError.appendChild( createTextNode( doc, ERROR_SEVERITY, getErrorSeverity().getTagValue() ) );
+            rpcError.appendChild( createTextNode( doc, ERROR_SEVERITY, getErrorSeverity().getSeverityValue() ) );
             rpcError.appendChild( createTextNode( doc, ERROR_MESSAGE, getLocalizedMessage() ) );
 
             Map<String, String> errorInfoMap = getErrorInfo();