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 bfeb2a69ee3c94bcee0e2de34f2deb3660a5bf1e..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 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;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -63,10 +65,19 @@ public class DocumentedException extends Exception {
     }
 
     public enum ErrorType {
     }
 
     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() {
 
         public String getTypeValue() {
-            return name();
+            return this.typeValue;
         }
 
         /**
         }
 
         /**
@@ -74,16 +85,17 @@ public class DocumentedException extends Exception {
          */
         @Deprecated
         public String getTagValue() {
          */
         @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 {
     }
 
     public enum ErrorSeverity {
-        ERROR, WARNING;
+        ERROR("error"),
+        WARNING("warning");
+
+        private final String severityValue;
+
+        ErrorSeverity(String severityValue) {
+            this.severityValue = Preconditions.checkNotNull(severityValue);
+        }
 
         public String getSeverityValue() {
 
         public String getSeverityValue() {
-            return name();
+            return this.severityValue;
         }
 
         /**
         }
 
         /**
@@ -142,16 +161,17 @@ public class DocumentedException extends Exception {
          */
         @Deprecated
         public String getTagValue() {
          */
         @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;
         }
     }
 
         }
     }