Bug 7180 - error-severity and error-type values should be lowercase 26/48326/9
authorJakub Morvay <jmorvay@cisco.com>
Mon, 14 Nov 2016 15:41:26 +0000 (16:41 +0100)
committerTom Pantelis <tpanteli@brocade.com>
Tue, 22 Nov 2016 13:46:53 +0000 (13:46 +0000)
Add String value fields to ErrorSeverity and ErrorType enums that
contain lowercase names of enums. Enums' string value getter methods
return these lowercase values.

Change-Id: I1509a7bbae4811025a5bbba11e9b2f0c0cc75b50
Signed-off-by: Jakub Morvay <jmorvay@cisco.com>
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;
         }
     }
 

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.