Special handling for inet classes
authorTimoney, Dan (dt5972) <dt5972@att.com>
Thu, 12 Jul 2018 16:29:42 +0000 (12:29 -0400)
committerTimoney, Dan (dt5972) <dt5972@att.com>
Thu, 12 Jul 2018 16:29:42 +0000 (12:29 -0400)
Add special handling for inet POJOs (which have different form
then POJOs generated from Yang by yangtools) in toList method.

Change-Id: Ie25527e6aacbf683965d7f24018fe066c74fb917
Issue-ID: CCSDK-362
Signed-off-by: Timoney, Dan (dt5972) <dt5972@att.com>
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java

index b652c43..e50b997 100644 (file)
@@ -528,24 +528,60 @@ public class MdsalHelper {
             String curBase = pfx + "[" + i + "]";
 
             if (isYangGenerated(elemType)) {
-                String builderName = elemType.getName() + "Builder";
-                try {
-                    Class builderClass = Class.forName(builderName);
-                    Object builderObj = builderClass.newInstance();
-                    Method buildMethod = builderClass.getMethod("build");
-                    builderObj = toBuilder(props, curBase, builderObj, true);
-                    if (builderObj != null) {
-                        LOG.trace("Calling " + builderObj.getClass().getName() + "." + buildMethod.getName() + "()");
-                        Object builtObj = buildMethod.invoke(builderObj);
-                        toObj.add(builtObj);
+               
+               if (isIpAddress(elemType) || isIpv4Address(elemType) || isIpv6Address(elemType)) {
+
+                    String curValue = props.getProperty(curBase, "");
+
+                    if ((curValue != null) && (curValue.length() > 0)) {
+                       toObj.add(IpAddressBuilder.getDefaultInstance(curValue));
                         foundValue = true;
                     }
+               } else if (isIpPrefix(elemType)) {
 
-                } catch (ClassNotFoundException e) {
-                    LOG.warn("Could not find builder class {}", builderName, e);
-                } catch (Exception e) {
-                    LOG.error("Caught exception trying to populate list from {}", pfx, e);
-                }
+                    String curValue = props.getProperty(curBase, "");
+
+                    if ((curValue != null) && (curValue.length() > 0)) {
+                       toObj.add(IpPrefixBuilder.getDefaultInstance(curValue));
+                        foundValue = true;
+                    }
+               } else if (isPortNumber(elemType)) {
+
+                    String curValue = props.getProperty(curBase, "");
+
+                    if ((curValue != null) && (curValue.length() > 0)) {
+                       toObj.add(PortNumber.getDefaultInstance(curValue));
+                        foundValue = true;
+                    }
+               } else if (isDscp(elemType)) {
+
+                    String curValue = props.getProperty(curBase, "");
+
+                    if ((curValue != null) && (curValue.length() > 0)) {
+                       toObj.add(Dscp.getDefaultInstance(curValue));
+                        foundValue = true;
+                    }
+                               } else {
+                                       String builderName = elemType.getName() + "Builder";
+                                       try {
+                                               Class builderClass = Class.forName(builderName);
+                                               Object builderObj = builderClass.newInstance();
+                                               Method buildMethod = builderClass.getMethod("build");
+                                               builderObj = toBuilder(props, curBase, builderObj, true);
+                                               if (builderObj != null) {
+                                                       LOG.trace(
+                                                                       "Calling " + builderObj.getClass().getName() + "." + buildMethod.getName() + "()");
+                                                       Object builtObj = buildMethod.invoke(builderObj);
+                                                       toObj.add(builtObj);
+                                                       foundValue = true;
+                                               }
+
+                                       } catch (ClassNotFoundException e) {
+                                               LOG.warn("Could not find builder class {}", builderName, e);
+                                       } catch (Exception e) {
+                                               LOG.error("Caught exception trying to populate list from {}", pfx, e);
+                                       }
+                               }
             } else {
                 // Must be a leaf list
                 String curValue = props.getProperty(curBase, "");