Support additional IETF types
authorDan Timoney <dtimoney@att.com>
Mon, 18 Dec 2017 20:01:10 +0000 (15:01 -0500)
committerDan Timoney <dtimoney@att.com>
Mon, 18 Dec 2017 20:01:10 +0000 (15:01 -0500)
Support additional IETF types in MdsalHelper.

Change-Id: I1d0b4ab28645435d1ef72bc30a053d796aea44c8
Issue-ID: CCSDK-155
Signed-off-by: Dan Timoney <dtimoney@att.com>
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicActivator.java

index 52c25b6..39a87a9 100644 (file)
@@ -8,9 +8,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,6 +23,7 @@ package org.onap.ccsdk.sli.core.sli.provider;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;\r
 import java.io.InputStream;
 import java.io.PrintStream;
 import java.lang.reflect.Constructor;
@@ -33,12 +34,14 @@ import java.lang.reflect.Type;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Properties;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddressBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefixBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;\r
 import org.opendaylight.yangtools.yang.binding.Identifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -188,8 +191,9 @@ public class MdsalHelper {
                                 }
                             } catch (Exception e) {
                                 LOG.error(
-                                    "Caught exception trying to convert Yang-generated enum returned by " + fromClass
-                                        .getName() + "." + m.getName() + "() to Properties entry", e);
+                                        "Caught exception trying to convert Yang-generated enum returned by "
+                                                + fromClass.getName() + "." + m.getName() + "() to Properties entry",
+                                        e);
                             }
                         } else if (isIpv4Address(returnType)) {
                             // Save its value
@@ -211,9 +215,8 @@ public class MdsalHelper {
 
                                 }
                             } catch (Exception e) {
-                                LOG.error(
-                                    "Caught exception trying to convert value returned by " + fromClass.getName() + "."
-                                        + m.getName() + "() to Properties entry", e);
+                                LOG.error("Caught exception trying to convert value returned by " + fromClass.getName()
+                                        + "." + m.getName() + "() to Properties entry", e);
                             }
                         } else if (isIpv6Address(returnType)) {
                             // Save its value
@@ -235,9 +238,8 @@ public class MdsalHelper {
 
                                 }
                             } catch (Exception e) {
-                                LOG.error(
-                                    "Caught exception trying to convert value returned by " + fromClass.getName() + "."
-                                        + m.getName() + "() to Properties entry", e);
+                                LOG.error("Caught exception trying to convert value returned by " + fromClass.getName()
+                                        + "." + m.getName() + "() to Properties entry", e);
                             }
                         } else if (isIpAddress(returnType)) {
                             // Save its value
@@ -259,9 +261,8 @@ public class MdsalHelper {
 
                                 }
                             } catch (Exception e) {
-                                LOG.error(
-                                    "Caught exception trying to convert value returned by " + fromClass.getName() + "."
-                                        + m.getName() + "() to Properties entry", e);
+                                LOG.error("Caught exception trying to convert value returned by " + fromClass.getName()
+                                        + "." + m.getName() + "() to Properties entry", e);
                             }
                         } else if (isIpPrefix(returnType)) {
                             // Save its value
@@ -283,10 +284,55 @@ public class MdsalHelper {
 
                                 }
                             } catch (Exception e) {
-                                LOG.error(
-                                    "Caught exception trying to convert value returned by " + fromClass.getName() + "."
-                                        + m.getName() + "() to Properties entry", e);
+                                LOG.error("Caught exception trying to convert value returned by " + fromClass.getName()
+                                        + "." + m.getName() + "() to Properties entry", e);
                             }
+                        } else if (isPortNumber(returnType)) {\r
+                            // Save its value\r
+                            try {\r
+                                String propName = propNamePfx + "." + fieldName;\r
+                                boolean isAccessible = m.isAccessible();\r
+                                if (!isAccessible) {\r
+                                    m.setAccessible(true);\r
+                                }\r
+                                PortNumber retValue = (PortNumber) m.invoke(fromObj);\r
+                                if (!isAccessible) {\r
+                                    m.setAccessible(isAccessible);\r
+                                }\r
+\r
+                                if (retValue != null) {\r
+                                    propVal = "" + retValue.getValue();\r
+                                    LOG.debug("Setting property " + propName + " to " + propVal);\r
+                                    props.setProperty(propName, propVal);\r
+\r
+                                }\r
+                            } catch (Exception e) {\r
+                                LOG.error("Caught exception trying to convert value returned by " + fromClass.getName()\r
+                                        + "." + m.getName() + "() to Properties entry", e);\r
+                            }\r
+                        } else if (isDscp(returnType)) {\r
+                            // Save its value\r
+                            try {\r
+                                String propName = propNamePfx + "." + fieldName;\r
+                                boolean isAccessible = m.isAccessible();\r
+                                if (!isAccessible) {\r
+                                    m.setAccessible(true);\r
+                                }\r
+                                Dscp retValue = (Dscp) m.invoke(fromObj);\r
+                                if (!isAccessible) {\r
+                                    m.setAccessible(isAccessible);\r
+                                }\r
+\r
+                                if (retValue != null) {\r
+                                    propVal = "" + retValue.getValue();\r
+                                    LOG.debug("Setting property " + propName + " to " + propVal);\r
+                                    props.setProperty(propName, propVal);\r
+\r
+                                }\r
+                            } catch (Exception e) {\r
+                                LOG.error("Caught exception trying to convert value returned by " + fromClass.getName()\r
+                                        + "." + m.getName() + "() to Properties entry", e);\r
+                            }\r
                         } else {
                             try {
                                 boolean isAccessible = m.isAccessible();
@@ -299,7 +345,7 @@ public class MdsalHelper {
                                     LOG.trace(m.getName() + " returns a byte[]");
                                     retValue = new String((byte[]) retValue, "UTF-8");
                                     LOG.trace("Converted byte array " + propNamePfx + "." + fieldName + "to string "
-                                        + retValue);
+                                            + retValue);
                                 }
                                 if (!isAccessible) {
                                     m.setAccessible(isAccessible);
@@ -311,10 +357,10 @@ public class MdsalHelper {
 
                                 if (m.getName().equals("getKey")) {
                                     LOG.trace("Caught " + e.getClass().getName()
-                                        + " exception trying to convert results from getKey() - ignoring");
+                                            + " exception trying to convert results from getKey() - ignoring");
                                 } else {
                                     LOG.error("Caught exception trying to convert Yang-generated class returned by"
-                                        + fromClass.getName() + "." + m.getName() + "() to Properties entry", e);
+                                            + fromClass.getName() + "." + m.getName() + "() to Properties entry", e);
                                 }
                             }
                         }
@@ -340,9 +386,8 @@ public class MdsalHelper {
                             Type elementType = ((ParameterizedType) paramType).getActualTypeArguments()[0];
                             toProperties(props, propNamePfx + "." + fieldName, retList, (Class) elementType);
                         } catch (Exception e) {
-                            LOG.error(
-                                "Caught exception trying to convert List returned by " + fromClass.getName() + "." + m
-                                    .getName() + "() to Properties entry", e);
+                            LOG.error("Caught exception trying to convert List returned by " + fromClass.getName() + "."
+                                    + m.getName() + "() to Properties entry", e);
                         }
 
                     } else {
@@ -366,7 +411,7 @@ public class MdsalHelper {
                                     LOG.trace(m.getName() + " returns a byte[]");
                                     propVal = new String((byte[]) propValObj, "UTF-8");
                                     LOG.trace("Converted byte array " + propNamePfx + "." + fieldName + "to string "
-                                        + propVal);
+                                            + propVal);
 
                                 } else {
                                     propVal = propValObj.toString();
@@ -378,11 +423,10 @@ public class MdsalHelper {
                         } catch (Exception e) {
                             if (m.getName().equals("getKey")) {
                                 LOG.trace("Caught " + e.getClass().getName()
-                                    + " exception trying to convert results from getKey() - ignoring");
+                                        + " exception trying to convert results from getKey() - ignoring");
                             } else {
-                                LOG.error(
-                                    "Caught exception trying to convert value returned by" + fromClass.getName() + "."
-                                        + m.getName() + "() to Properties entry", e);
+                                LOG.error("Caught exception trying to convert value returned by" + fromClass.getName()
+                                        + "." + m.getName() + "() to Properties entry", e);
                             }
                         }
                     }
@@ -394,13 +438,12 @@ public class MdsalHelper {
             // "getValue", then
             // set value identified by "prefix" to that one value.
             if ((numGetters == 1) && ("getValue".equals(lastGetterName))) {
-                LOG.trace(
-                    "getValueFIX : " + propNamePfx + " only has getValue() getter - setting " + propNamePfx + " = "
-                        + propVal);
+                LOG.trace("getValueFIX : " + propNamePfx + " only has getValue() getter - setting " + propNamePfx
+                        + " = " + propVal);
                 props.setProperty(propNamePfx, propVal);
             } else {
                 LOG.trace("getValueFIX : " + propNamePfx + " has " + numGetters + " getter(s), last one found was "
-                    + lastGetterName);
+                        + lastGetterName);
 
             }
 
@@ -578,6 +621,9 @@ public class MdsalHelper {
                     String paramValue = props.getProperty(propName);
                     if (paramValue == null) {
                         LOG.trace(propName + " is unset");
+                    } else if ("".equals(paramValue)) {\r
+                        LOG.trace(propName + " was set to the empty string, setting it to null");\r
+                        paramValue = null;\r
                     } else {
                         LOG.trace(propName + " = " + paramValue);
                     }
@@ -596,7 +642,7 @@ public class MdsalHelper {
                                     paramObj = Enum.valueOf(paramClass, toJavaEnum(paramValue));
                                 } catch (Exception e) {
                                     LOG.error("Caught exception trying to convert field " + propName + " to enum "
-                                        + paramClass.getName(), e);
+                                            + paramClass.getName(), e);
                                 }
 
                                 try {
@@ -605,9 +651,8 @@ public class MdsalHelper {
                                         m.setAccessible(true);
                                     }
 
-                                    LOG.trace(
-                                        "Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + paramValue
-                                            + ")");
+                                    LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "("
+                                            + paramValue + ")");
                                     m.invoke(toObj, paramObj);
 
                                     if (!isAccessible) {
@@ -616,17 +661,16 @@ public class MdsalHelper {
                                     foundValue = true;
 
                                 } catch (Exception e) {
-                                    LOG.error(
-                                        "Caught exception trying to create Yang-generated enum expected by" + toClass
-                                            .getName() + "." + m.getName() + "() from Properties entry", e);
+                                    LOG.error("Caught exception trying to create Yang-generated enum expected by"
+                                            + toClass.getName() + "." + m.getName() + "() from Properties entry", e);
                                 }
                             }
                         } else {
 
                             String simpleName = paramClass.getSimpleName();
 
-                            if ("Ipv4Address".equals(simpleName) || "Ipv6Address".equals(simpleName) || "IpAddress"
-                                .equals(simpleName)) {
+                            if ("Ipv4Address".equals(simpleName) || "Ipv6Address".equals(simpleName)
+                                    || "IpAddress".equals(simpleName)) {
 
                                 if ((paramValue != null) && (paramValue.length() > 0)) {
                                     try {
@@ -642,9 +686,8 @@ public class MdsalHelper {
                                         }
                                         foundValue = true;
                                     } catch (Exception e) {
-                                        LOG.error(
-                                            "Caught exception calling " + toClass.getName() + "." + m.getName() + "("
-                                                + paramValue + ")", e);
+                                        LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName()
+                                                + "(" + paramValue + ")", e);
 
                                     }
                                 } else {
@@ -654,7 +697,7 @@ public class MdsalHelper {
                                             m.setAccessible(true);
                                         }
                                         LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "("
-                                            + paramValue + ")");
+                                                + paramValue + ")");
                                         m.invoke(toObj, paramValue);
                                         if (!isAccessible) {
                                             m.setAccessible(isAccessible);
@@ -662,9 +705,8 @@ public class MdsalHelper {
                                         foundValue = true;
 
                                     } catch (Exception e) {
-                                        LOG.error(
-                                            "Caught exception trying to call " + toClass.getName() + "." + m.getName()
-                                                + "() with Properties entry", e);
+                                        LOG.error("Caught exception trying to call " + toClass.getName() + "."
+                                                + m.getName() + "() with Properties entry", e);
                                     }
                                 }
                             } else if ("IpPrefix".equals(simpleName)) {
@@ -674,11 +716,32 @@ public class MdsalHelper {
                                         m.invoke(toObj, ipPrefix);
                                         foundValue = true;
                                     } catch (Exception e) {
-                                        LOG.error(
-                                            "Caught exception calling " + toClass.getName() + "." + m.getName() + "("
-                                                + paramValue + ")", e);
+                                        LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName()
+                                                + "(" + paramValue + ")", e);
                                     }
                                 }
+                            } else if ("PortNumber".equals(simpleName)) {\r
+                                if ((paramValue != null) && (paramValue.length() > 0)) {\r
+                                    try {\r
+                                        PortNumber portNumber = PortNumber.getDefaultInstance(paramValue);\r
+                                        m.invoke(toObj, portNumber);\r
+                                        foundValue = true;\r
+                                    } catch (Exception e) {\r
+                                        LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName()\r
+                                                + "(" + paramValue + ")", e);\r
+                                    }\r
+                                }\r
+                            } else if ("Dscp".equals(simpleName)) {\r
+                                if ((paramValue != null) && (paramValue.length() > 0)) {\r
+                                    try {\r
+                                        Dscp dscp = Dscp.getDefaultInstance(paramValue);\r
+                                        m.invoke(toObj, dscp);\r
+                                        foundValue = true;\r
+                                    } catch (Exception e) {\r
+                                        LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName()\r
+                                                + "(" + paramValue + ")", e);\r
+                                    }\r
+                                }\r
                             } else {
                                 // setter expects a yang-generated class. Need
                                 // to
@@ -692,7 +755,7 @@ public class MdsalHelper {
                                 Object constObj = null;
 
                                 LOG.trace(m.getName() + " expects a yang-generated class - looking for builder "
-                                    + builderName);
+                                        + builderName);
                                 try {
                                     builderClass = Class.forName(builderName);
                                     builderObj = builderClass.newInstance();
@@ -705,17 +768,17 @@ public class MdsalHelper {
                                             if (!isAccessible) {
                                                 m.setAccessible(true);
                                             }
-                                            LOG.trace(
-                                                "Calling " + toObj.getClass().getName() + "." + m.getName() + "(null)");
-                                            m.invoke(toObj, new Object[]{null});
+                                            LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName()
+                                                    + "(null)");
+                                            m.invoke(toObj, new Object[] {null});
                                             if (!isAccessible) {
                                                 m.setAccessible(isAccessible);
                                             }
                                             foundValue = true;
 
                                         } catch (Exception e1) {
-                                            LOG.error("Caught exception trying to cally" + toClass.getName() + "." + m
-                                                .getName() + "() with Properties entry", e1);
+                                            LOG.error("Caught exception trying to cally" + toClass.getName() + "."
+                                                    + m.getName() + "() with Properties entry", e1);
                                         }
                                     } else {
                                         try {
@@ -753,8 +816,8 @@ public class MdsalHelper {
                                                 // method
                                                 // getDefaultInstance(String)
                                                 try {
-                                                    Method gm = paramClass
-                                                        .getMethod("getDefaultInstance", String.class);
+                                                    Method gm =
+                                                            paramClass.getMethod("getDefaultInstance", String.class);
 
                                                     int gmodifier = gm.getModifiers();
                                                     if (Modifier.isStatic(gmodifier)) {
@@ -765,20 +828,20 @@ public class MdsalHelper {
 
                                                 } catch (Exception gme) {
                                                     LOG.info("Unable to find static method getDefaultInstance for "
-                                                        + "class {}", paramClass.getSimpleName(), gme);
+                                                            + "class {}", paramClass.getSimpleName(), gme);
                                                 }
                                             }
 
                                         } catch (Exception e1) {
                                             LOG.warn(
-                                                "Could not find a suitable constructor for " + paramClass.getName(),
-                                                e1);
+                                                    "Could not find a suitable constructor for " + paramClass.getName(),
+                                                    e1);
                                         }
 
                                         if (constObj == null) {
                                             LOG.warn("Could not find builder class " + builderName
-                                                + " and could not find a String or Long constructor or static "
-                                                + "getDefaultInstance(String) - trying just to set passing paramValue");
+                                                    + " and could not find a String or Long constructor or static "
+                                                    + "getDefaultInstance(String) - trying just to set passing paramValue");
 
                                         }
                                     }
@@ -790,9 +853,8 @@ public class MdsalHelper {
 
                                     try {
                                         Method buildMethod = builderClass.getMethod("build");
-                                        LOG.trace(
-                                            "Calling " + paramObj.getClass().getName() + "." + buildMethod.getName()
-                                                + "()");
+                                        LOG.trace("Calling " + paramObj.getClass().getName() + "."
+                                                + buildMethod.getName() + "()");
                                         Object builtObj = buildMethod.invoke(paramObj);
 
                                         boolean isAccessible = m.isAccessible();
@@ -808,9 +870,9 @@ public class MdsalHelper {
                                         foundValue = true;
 
                                     } catch (Exception e) {
-                                        LOG.error(
-                                            "Caught exception trying to set Yang-generated class expected by" + toClass
-                                                .getName() + "." + m.getName() + "() from Properties entry", e);
+                                        LOG.error("Caught exception trying to set Yang-generated class expected by"
+                                                + toClass.getName() + "." + m.getName() + "() from Properties entry",
+                                                e);
                                     }
                                 } else {
                                     try {
@@ -822,11 +884,11 @@ public class MdsalHelper {
                                         if (constObj != null) {
 
                                             LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "("
-                                                + constObj.toString() + ")");
+                                                    + constObj.toString() + ")");
                                             m.invoke(toObj, constObj);
                                         } else {
                                             LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "("
-                                                + paramValue + ")");
+                                                    + paramValue + ")");
                                             m.invoke(toObj, paramValue);
 
                                         }
@@ -836,9 +898,8 @@ public class MdsalHelper {
                                         foundValue = true;
 
                                     } catch (Exception e) {
-                                        LOG.error(
-                                            "Caught exception trying to convert value returned by" + toClass.getName()
-                                                + "." + m.getName() + "() to Properties entry", e);
+                                        LOG.error("Caught exception trying to convert value returned by"
+                                                + toClass.getName() + "." + m.getName() + "() to Properties entry", e);
                                     }
                                 }
                             }
@@ -862,7 +923,7 @@ public class MdsalHelper {
                                 paramObj = toList(props, propName, (List) paramObj, (Class) elementType);
                             } catch (Exception e) {
                                 LOG.error("Caught exception trying to create list expected as argument to {}.{}",
-                                    toClass.getName(), m.getName(), e);
+                                        toClass.getName(), m.getName(), e);
                             }
 
                             if (paramObj != null) {
@@ -871,9 +932,8 @@ public class MdsalHelper {
                                     if (!isAccessible) {
                                         m.setAccessible(true);
                                     }
-                                    LOG.trace(
-                                        "Calling " + toObj.getClass().getName() + "." + m.getName() + "(" + paramValue
-                                            + ")");
+                                    LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "("
+                                            + paramValue + ")");
                                     m.invoke(toObj, paramObj);
                                     if (!isAccessible) {
                                         m.setAccessible(isAccessible);
@@ -881,9 +941,8 @@ public class MdsalHelper {
                                     foundValue = true;
 
                                 } catch (Exception e) {
-                                    LOG.error(
-                                        "Caught exception trying to convert List returned by" + toClass.getName() + "."
-                                            + m.getName() + "() to Properties entry", e);
+                                    LOG.error("Caught exception trying to convert List returned by" + toClass.getName()
+                                            + "." + m.getName() + "() to Properties entry", e);
                                 }
                             }
                         } else {
@@ -891,8 +950,8 @@ public class MdsalHelper {
                             // Setter expects something that is not a List and
                             // not yang-generated. Just pass the parameter value
 
-                            LOG.trace(
-                                "Parameter class " + paramClass.getName() + " is not a yang-generated class or a List");
+                            LOG.trace("Parameter class " + paramClass.getName()
+                                    + " is not a yang-generated class or a List");
 
                             if ((paramValue != null) && (paramValue.length() > 0)) {
 
@@ -927,7 +986,7 @@ public class MdsalHelper {
                                     if (constObj != null) {
                                         try {
                                             LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "("
-                                                + constObj + ")");
+                                                    + constObj + ")");
                                             m.invoke(toObj, constObj);
                                             foundValue = true;
                                         } catch (Exception e2) {
@@ -940,7 +999,7 @@ public class MdsalHelper {
                                                 m.setAccessible(true);
                                             }
                                             LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "("
-                                                + paramValue + ")");
+                                                    + paramValue + ")");
                                             m.invoke(toObj, paramValue);
                                             if (!isAccessible) {
                                                 m.setAccessible(isAccessible);
@@ -948,8 +1007,9 @@ public class MdsalHelper {
                                             foundValue = true;
 
                                         } catch (Exception e) {
-                                            LOG.error("Caught exception trying to convert value returned by" + toClass
-                                                .getName() + "." + m.getName() + "() to Properties entry", e);
+                                            LOG.error("Caught exception trying to convert value returned by"
+                                                    + toClass.getName() + "." + m.getName() + "() to Properties entry",
+                                                    e);
                                         }
                                     }
                                 } catch (Exception e1) {
@@ -1034,8 +1094,9 @@ public class MdsalHelper {
 
                             String simpleName = returnClass.getSimpleName();
 
-                            if ("Ipv4Address".equals(simpleName) || "Ipv6Address".equals(simpleName) || "IpAddress"
-                                .equals(simpleName) || "IpPrefix".equals(simpleName)) {
+                            if ("Ipv4Address".equals(simpleName) || "Ipv6Address".equals(simpleName)
+                                    || "IpAddress".equals(simpleName) || "IpPrefix".equals(simpleName)\r
+                                    || "PortNumber".equals(simpleName) || "Dscp".equals(simpleName)) {\r
                                 LOG.trace(m.getName() + " is an " + simpleName);
                                 pstr.print("\n\n     * " + propName);
                             } else {
@@ -1058,11 +1119,11 @@ public class MdsalHelper {
                             Type returnType = m.getGenericReturnType();
                             Type elementType = ((ParameterizedType) returnType).getActualTypeArguments()[0];
                             Class elementClass = (Class) elementType;
-                            LOG.trace(
-                                "Calling printPropertyList on list type (" + elementClass.getName() + "), pfx is ("
-                                    + pfx + "), toClass is (" + toClass.getName() + ")");
+                            LOG.trace("Calling printPropertyList on list type (" + elementClass.getName()
+                                    + "), pfx is (" + pfx + "), toClass is (" + toClass.getName() + ")");
                             printPropertyList(pstr,
-                                propNamePfx + "." + toLowerHyphen(elementClass.getSimpleName()) + "[]", elementClass);
+                                    propNamePfx + "." + toLowerHyphen(elementClass.getSimpleName()) + "[]",
+                                    elementClass);
 
                         } else if (!returnClass.equals(Class.class)) {
 
@@ -1070,7 +1131,7 @@ public class MdsalHelper {
                             // not yang-generated. Just pass the parameter value
 
                             LOG.trace("Parameter class " + returnClass.getName()
-                                + " is not a yang-generated class or a List");
+                                    + " is not a yang-generated class or a List");
 
                             pstr.print("\n\n     * " + propName);
                         }
@@ -1094,6 +1155,9 @@ public class MdsalHelper {
         if (c == null) {
             return (false);
         }
+        if (!isIetfInet(c)) {\r
+            return (false);\r
+        }\r
         String simpleName = c.getSimpleName();
         return ("IpPrefix".equals(simpleName));
     }
@@ -1103,6 +1167,9 @@ public class MdsalHelper {
         if (c == null) {
             return (false);
         }
+        if (!isIetfInet(c)) {\r
+            return (false);\r
+        }\r
         String simpleName = c.getSimpleName();
         return ("Ipv4Address".equals(simpleName));
     }
@@ -1112,6 +1179,9 @@ public class MdsalHelper {
         if (c == null) {
             return (false);
         }
+        if (!isIetfInet(c)) {\r
+            return (false);\r
+        }\r
         String simpleName = c.getSimpleName();
         return ("Ipv6Address".equals(simpleName));
     }
@@ -1121,10 +1191,52 @@ public class MdsalHelper {
         if (c == null) {
             return (false);
         }
+        if (!isIetfInet(c)) {\r
+            return (false);\r
+        }\r
         String simpleName = c.getSimpleName();
         return ("IpAddress".equals(simpleName));
     }
 
+    public static boolean isPortNumber(Class c) {\r
+\r
+        if (c == null) {\r
+            return (false);\r
+        }\r
+        if (!isIetfInet(c)) {\r
+            return (false);\r
+        }\r
+\r
+        String simpleName = c.getSimpleName();\r
+        return ("PortNumber".equals(simpleName));\r
+    }\r
+\r
+    public static boolean isDscp(Class c) {\r
+\r
+        if (c == null) {\r
+            return (false);\r
+        }\r
+        if (!isIetfInet(c)) {\r
+            return (false);\r
+        }\r
+        String simpleName = c.getSimpleName();\r
+        return ("Dscp".equals(simpleName));\r
+    }\r
+\r
+    public static boolean isIetfInet(Class c) {\r
+\r
+        Package p = c.getPackage();\r
+        if (p != null) {\r
+            String pkgName = p.getName();\r
+\r
+            if ((pkgName != null) && (pkgName.indexOf("yang.ietf.inet.types") > -1)) {\r
+                return (true);\r
+            }\r
+        }\r
+\r
+        return (false);\r
+    }\r
+\r
     public static String toLowerHyphen(String inStr) {
         if (inStr == null) {
             return (null);
@@ -1144,7 +1256,7 @@ public class MdsalHelper {
         return (retval);
     }
 
-    //This is called when mapping the yang value back to a valid java enumeration
+    // This is called when mapping the yang value back to a valid java enumeration
     public static String toJavaEnum(String inStr) {
         if (inStr == null) {
             return (null);
@@ -1152,17 +1264,17 @@ public class MdsalHelper {
             return (inStr);
         }
 
-        //This will strip out all periods, which cannot be in a java enum
+        // This will strip out all periods, which cannot be in a java enum
         inStr = inStr.replaceAll("\\.", "");
 
         String[] terms = inStr.split("-");
         StringBuffer sbuff = new StringBuffer();
 
-        //appends an _ if the string starts with a digit to make it a valid java enum
+        // appends an _ if the string starts with a digit to make it a valid java enum
         if (Character.isDigit(inStr.charAt(0))) {
             sbuff.append('_');
         }
-        //If the string contains hyphens it will convert the string to upperCamelCase without hyphens
+        // If the string contains hyphens it will convert the string to upperCamelCase without hyphens
         for (String term : terms) {
             sbuff.append(term.substring(0, 1).toUpperCase());
             if (term.length() > 1) {
@@ -1205,8 +1317,8 @@ public class MdsalHelper {
         if (Modifier.isPublic(m.getModifiers()) && (m.getParameterTypes().length == 1)) {
             if (m.getName().matches("^set[A-Z].*")) {
                 Class[] paramTypes = m.getParameterTypes();
-                if (paramTypes[0].isAssignableFrom(Identifier.class) || Identifier.class
-                    .isAssignableFrom(paramTypes[0])) {
+                if (paramTypes[0].isAssignableFrom(Identifier.class)
+                        || Identifier.class.isAssignableFrom(paramTypes[0])) {
                     return (false);
                 } else {
                     return (true);
@@ -1222,7 +1334,7 @@ public class MdsalHelper {
         return "/opt/bvc/controller/configuration/" + propertiesFileName;
     }
 
-    //This is called when mapping a valid java enumeration back to the yang model value
+    // This is called when mapping a valid java enumeration back to the yang model value
     public static String mapEnumeratedValue(String propertyName, String propertyValue) {
         LOG.info("mapEnumeratedValue called with propertyName=" + propertyName + " and value=" + propertyValue);
         String mappingKey = "yang." + propertyName + "." + propertyValue;
index 502c1a4..d0c052a 100644 (file)
@@ -60,8 +60,16 @@ public class SetNodeExecutor extends SvcLogicNodeExecutor {
                        
                        // Resolve LHS of assignment (could contain index variables)
                        try {
+                //Backticks symbolize the variable should be handled as an expression instead of as a variable\r
+                if (curName.trim().startsWith("`")) {\r
+                    int lastParen = curName.lastIndexOf("`");\r
+                    String evalExpr = curName.trim().substring(1, lastParen);\r
+                    SvcLogicExpression lhsExpr = SvcLogicExpressionFactory.parse(evalExpr);\r
+                    lhsVarName = SvcLogicExpressionResolver.evaluate(lhsExpr, node, ctx);\r
+                } else {\r
                                SvcLogicExpression lhsExpr = SvcLogicExpressionFactory.parse(curName);
                                lhsVarName = SvcLogicExpressionResolver.resolveVariableName(lhsExpr, node, ctx);
+                }\r
                        } catch (Exception e) {
                                LOG.warn("Caught exception trying to resolve variable name ("+curName+")", e);
                        }
index cbde44d..95dfb2b 100644 (file)
@@ -67,7 +67,7 @@ public class SvcLogicActivator implements BundleActivator {
             put("switch", new SwitchNodeExecutor());
             put("update", new UpdateNodeExecutor());
             put("break", new BreakNodeExecutor());
-
+            put("while", new WhileNodeExecutor());\r
         }
     };