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 bfeb2a6..2f18bf0 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,10 +65,19 @@ 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 name();
+            return this.typeValue;
         }
 
         /**
@@ -74,16 +85,17 @@ public class DocumentedException extends Exception {
          */
         @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;
         }
     }
 
@@ -131,10 +143,17 @@ 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 name();
+            return this.severityValue;
         }
 
         /**
@@ -142,16 +161,17 @@ public class DocumentedException extends Exception {
          */
         @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;
         }
     }