BUG-2453 (De)Serialize enum values as defined in yang
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / attributes / AttributeIfcSwitchStatement.java
index 697b811d51c90c9b7cab4f05f266292d25d2a260..38c0b06de487ca6b5f2cc5fdd44a36cbb75e7ffe 100644 (file)
@@ -8,6 +8,10 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes;
 
+import javax.management.openmbean.ArrayType;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
 import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
 import org.opendaylight.controller.config.yangjmxgenerator.attribute.DependencyAttribute;
 import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute;
@@ -16,25 +20,29 @@ import org.opendaylight.controller.config.yangjmxgenerator.attribute.ListDepende
 import org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute;
 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
 
-import javax.management.openmbean.ArrayType;
-import javax.management.openmbean.CompositeType;
-import javax.management.openmbean.OpenType;
-import javax.management.openmbean.SimpleType;
-
 public abstract class AttributeIfcSwitchStatement<T> {
 
-    protected AttributeIfc lastAttribute;
+    private AttributeIfc lastAttribute;
 
     public T switchAttribute(AttributeIfc attributeIfc) {
 
         this.lastAttribute = attributeIfc;
 
+        OpenType<?> openType = attributeIfc.getOpenType();
+
         if (attributeIfc instanceof JavaAttribute) {
             try {
                 if(((JavaAttribute)attributeIfc).getTypeDefinition() instanceof BinaryTypeDefinition) {
-                    return caseJavaBinaryAttribute(attributeIfc.getOpenType());
-                } else
-                    return caseJavaAttribute(attributeIfc.getOpenType());
+                    return caseJavaBinaryAttribute(openType);
+                } else if(((JavaAttribute)attributeIfc).isUnion()) {
+                    return caseJavaUnionAttribute(openType);
+                } else if(((JavaAttribute)attributeIfc).isIdentityRef()) {
+                    return caseJavaIdentityRefAttribute(openType);
+                } else if(((JavaAttribute)attributeIfc).isEnum()) {
+                    return caseJavaEnumAttribute(openType);
+                } else {
+                    return caseJavaAttribute(openType);
+                }
             } catch (UnknownOpenTypeException e) {
                 throw getIllegalArgumentException(attributeIfc);
             }
@@ -42,9 +50,9 @@ public abstract class AttributeIfcSwitchStatement<T> {
         } else if (attributeIfc instanceof DependencyAttribute) {
             return caseDependencyAttribute(((DependencyAttribute) attributeIfc).getOpenType());
         } else if (attributeIfc instanceof ListAttribute) {
-            return caseListAttribute((ArrayType<?>) attributeIfc.getOpenType());
+            return caseListAttribute((ArrayType<?>) openType);
         } else if (attributeIfc instanceof ListDependenciesAttribute) {
-            return caseListDependeciesAttribute((ArrayType<?>) attributeIfc.getOpenType());
+            return caseListDependeciesAttribute((ArrayType<?>) openType);
         } else if (attributeIfc instanceof TOAttribute) {
             return caseTOAttribute(((TOAttribute) attributeIfc).getOpenType());
         }
@@ -52,6 +60,22 @@ public abstract class AttributeIfcSwitchStatement<T> {
         throw getIllegalArgumentException(attributeIfc);
     }
 
+    public AttributeIfc getLastAttribute() {
+        return lastAttribute;
+    }
+
+    protected T caseJavaIdentityRefAttribute(OpenType<?> openType) {
+        return caseJavaAttribute(openType);
+    }
+
+    protected T caseJavaUnionAttribute(OpenType<?> openType) {
+        return caseJavaAttribute(openType);
+    }
+
+    protected T caseJavaEnumAttribute(OpenType<?> openType) {
+        return caseJavaAttribute(openType);
+    }
+
     protected T caseJavaBinaryAttribute(OpenType<?> openType) {
         return caseJavaAttribute(openType);
     }
@@ -88,6 +112,8 @@ public abstract class AttributeIfcSwitchStatement<T> {
     protected abstract T caseListDependeciesAttribute(ArrayType<?> openType);
 
     private static class UnknownOpenTypeException extends RuntimeException {
+        private static final long serialVersionUID = 1L;
+
         public UnknownOpenTypeException(String message) {
             super(message);
         }