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 / runtime / InstanceRuntime.java
index 8c3b35122c2061af455222b70b464b3471ad6fc5..ce30dc43918e9e46e1c7ff3e975209ac6d5dcef7 100644 (file)
@@ -8,23 +8,20 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.runtime;
 
-import java.util.Hashtable;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Sets;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
-
 import javax.management.ObjectName;
-
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.InstanceConfig;
+import org.opendaylight.controller.netconf.confignetconfconnector.osgi.EnumResolver;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Sets;
-
 public class InstanceRuntime {
 
     /**
@@ -48,20 +45,23 @@ public class InstanceRuntime {
      * root + any number of additional properties
      */
     private Set<ObjectName> findChildren(ObjectName innerRootBean, Set<ObjectName> childRbeOns) {
-        final Hashtable<String, String> wantedProperties = innerRootBean.getKeyPropertyList();
+        final Map<String, String> wantedProperties = innerRootBean.getKeyPropertyList();
 
         return Sets.newHashSet(Collections2.filter(childRbeOns, new Predicate<ObjectName>() {
 
             @Override
             public boolean apply(ObjectName on) {
-                Hashtable<String, String> localProperties = on.getKeyPropertyList();
+                Map<String, String> localProperties = on.getKeyPropertyList();
                 for (Entry<String, String> propertyEntry : wantedProperties.entrySet()) {
-                    if (!localProperties.containsKey(propertyEntry.getKey()))
+                    if (!localProperties.containsKey(propertyEntry.getKey())){
                         return false;
-                    if (!localProperties.get(propertyEntry.getKey()).equals(propertyEntry.getValue()))
+                    }
+                    if (!localProperties.get(propertyEntry.getKey()).equals(propertyEntry.getValue())){
                         return false;
-                    if (localProperties.size() <= wantedProperties.size())
+                    }
+                    if (localProperties.size() <= wantedProperties.size()){
                         return false;
+                    }
                 }
                 return true;
             }
@@ -77,22 +77,21 @@ public class InstanceRuntime {
 
             @Override
             public boolean apply(ObjectName on) {
-                if (on.getKeyPropertyList().size() != keyListSize + 1)
+                if (on.getKeyPropertyList().size() != keyListSize + 1){
                     return false;
-                if (!on.getKeyPropertyList().containsKey(string))
-                    return false;
-                return true;
+                }
+                return on.getKeyPropertyList().containsKey(string);
             }
         }));
     }
 
-    public Element toXml(ObjectName rootOn, Set<ObjectName> childRbeOns, Document document, Element parentElement, String namespace) {
-        return toXml(rootOn, childRbeOns, document, null, parentElement, namespace);
+    public Element toXml(ObjectName rootOn, Set<ObjectName> childRbeOns, Document document, Element parentElement, String namespace, final EnumResolver enumResolver) {
+        return toXml(rootOn, childRbeOns, document, null, parentElement, namespace, enumResolver);
     }
 
     public Element toXml(ObjectName rootOn, Set<ObjectName> childRbeOns, Document document, String instanceIndex,
-                         Element parentElement, String namespace) {
-        Element xml = instanceMapping.toXml(rootOn, null, namespace, document, parentElement);
+                         Element parentElement, String namespace, final EnumResolver enumResolver) {
+        Element xml = instanceMapping.toXml(rootOn, namespace, document, parentElement, enumResolver);
 
         if (instanceIndex != null) {
             xml.setAttribute(KEY_ATTRIBUTE_KEY, instanceIndex);
@@ -108,9 +107,9 @@ public class InstanceRuntime {
 
                 String elementName = jmxToYangChildRbeMapping.get(childMappingEntry.getKey());
 
-                Element innerXml = XmlUtil.createElement(document, elementName, Optional.<String>absent());
+                Element innerXml = XmlUtil.createElement(document, elementName, Optional.of(namespace));
                 childMappingEntry.getValue().toXml(objectName, innerChildRbeOns, document,
-                        runtimeInstanceIndex, innerXml, namespace);
+                        runtimeInstanceIndex, innerXml, namespace, enumResolver);
                 xml.appendChild(innerXml);
             }
         }