diff options
Diffstat (limited to 'sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java')
-rw-r--r-- | sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java | 254 |
1 files changed, 127 insertions, 127 deletions
diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java index 39a87a91..bea21387 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java @@ -23,7 +23,7 @@ package org.onap.ccsdk.sli.core.sli.provider; import java.io.File; import java.io.FileInputStream; -import java.io.IOException;
+import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.lang.reflect.Constructor; @@ -34,14 +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;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp; 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;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber; import org.opendaylight.yangtools.yang.binding.Identifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -287,52 +287,52 @@ public class MdsalHelper { LOG.error("Caught exception trying to convert value returned by " + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); } - } else if (isPortNumber(returnType)) {
- // Save its value
- try {
- String propName = propNamePfx + "." + fieldName;
- boolean isAccessible = m.isAccessible();
- if (!isAccessible) {
- m.setAccessible(true);
- }
- PortNumber retValue = (PortNumber) m.invoke(fromObj);
- if (!isAccessible) {
- m.setAccessible(isAccessible);
- }
-
- if (retValue != null) {
- propVal = "" + retValue.getValue();
- LOG.debug("Setting property " + propName + " to " + propVal);
- props.setProperty(propName, propVal);
-
- }
- } catch (Exception e) {
- LOG.error("Caught exception trying to convert value returned by " + fromClass.getName()
- + "." + m.getName() + "() to Properties entry", e);
- }
- } else if (isDscp(returnType)) {
- // Save its value
- try {
- String propName = propNamePfx + "." + fieldName;
- boolean isAccessible = m.isAccessible();
- if (!isAccessible) {
- m.setAccessible(true);
- }
- Dscp retValue = (Dscp) m.invoke(fromObj);
- if (!isAccessible) {
- m.setAccessible(isAccessible);
- }
-
- if (retValue != null) {
- propVal = "" + retValue.getValue();
- LOG.debug("Setting property " + propName + " to " + propVal);
- props.setProperty(propName, propVal);
-
- }
- } catch (Exception e) {
- LOG.error("Caught exception trying to convert value returned by " + fromClass.getName()
- + "." + m.getName() + "() to Properties entry", e);
- }
+ } else if (isPortNumber(returnType)) { + // Save its value + try { + String propName = propNamePfx + "." + fieldName; + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + PortNumber retValue = (PortNumber) m.invoke(fromObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + + if (retValue != null) { + propVal = "" + retValue.getValue(); + LOG.debug("Setting property " + propName + " to " + propVal); + props.setProperty(propName, propVal); + + } + } catch (Exception e) { + LOG.error("Caught exception trying to convert value returned by " + fromClass.getName() + + "." + m.getName() + "() to Properties entry", e); + } + } else if (isDscp(returnType)) { + // Save its value + try { + String propName = propNamePfx + "." + fieldName; + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + Dscp retValue = (Dscp) m.invoke(fromObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + + if (retValue != null) { + propVal = "" + retValue.getValue(); + LOG.debug("Setting property " + propName + " to " + propVal); + props.setProperty(propName, propVal); + + } + } catch (Exception e) { + LOG.error("Caught exception trying to convert value returned by " + fromClass.getName() + + "." + m.getName() + "() to Properties entry", e); + } } else { try { boolean isAccessible = m.isAccessible(); @@ -621,9 +621,9 @@ public class MdsalHelper { String paramValue = props.getProperty(propName); if (paramValue == null) { LOG.trace(propName + " is unset"); - } else if ("".equals(paramValue)) {
- LOG.trace(propName + " was set to the empty string, setting it to null");
- paramValue = null;
+ } else if ("".equals(paramValue)) { + LOG.trace(propName + " was set to the empty string, setting it to null"); + paramValue = null; } else { LOG.trace(propName + " = " + paramValue); } @@ -720,28 +720,28 @@ public class MdsalHelper { + "(" + paramValue + ")", e); } } - } else if ("PortNumber".equals(simpleName)) {
- if ((paramValue != null) && (paramValue.length() > 0)) {
- try {
- PortNumber portNumber = PortNumber.getDefaultInstance(paramValue);
- m.invoke(toObj, portNumber);
- foundValue = true;
- } catch (Exception e) {
- LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName()
- + "(" + paramValue + ")", e);
- }
- }
- } else if ("Dscp".equals(simpleName)) {
- if ((paramValue != null) && (paramValue.length() > 0)) {
- try {
- Dscp dscp = Dscp.getDefaultInstance(paramValue);
- m.invoke(toObj, dscp);
- foundValue = true;
- } catch (Exception e) {
- LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName()
- + "(" + paramValue + ")", e);
- }
- }
+ } else if ("PortNumber".equals(simpleName)) { + if ((paramValue != null) && (paramValue.length() > 0)) { + try { + PortNumber portNumber = PortNumber.getDefaultInstance(paramValue); + m.invoke(toObj, portNumber); + foundValue = true; + } catch (Exception e) { + LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName() + + "(" + paramValue + ")", e); + } + } + } else if ("Dscp".equals(simpleName)) { + if ((paramValue != null) && (paramValue.length() > 0)) { + try { + Dscp dscp = Dscp.getDefaultInstance(paramValue); + m.invoke(toObj, dscp); + foundValue = true; + } catch (Exception e) { + LOG.error("Caught exception calling " + toClass.getName() + "." + m.getName() + + "(" + paramValue + ")", e); + } + } } else { // setter expects a yang-generated class. Need // to @@ -1095,8 +1095,8 @@ public class MdsalHelper { String simpleName = returnClass.getSimpleName(); if ("Ipv4Address".equals(simpleName) || "Ipv6Address".equals(simpleName) - || "IpAddress".equals(simpleName) || "IpPrefix".equals(simpleName)
- || "PortNumber".equals(simpleName) || "Dscp".equals(simpleName)) {
+ || "IpAddress".equals(simpleName) || "IpPrefix".equals(simpleName) + || "PortNumber".equals(simpleName) || "Dscp".equals(simpleName)) { LOG.trace(m.getName() + " is an " + simpleName); pstr.print("\n\n * " + propName); } else { @@ -1155,9 +1155,9 @@ public class MdsalHelper { if (c == null) { return (false); } - if (!isIetfInet(c)) {
- return (false);
- }
+ if (!isIetfInet(c)) { + return (false); + } String simpleName = c.getSimpleName(); return ("IpPrefix".equals(simpleName)); } @@ -1167,9 +1167,9 @@ public class MdsalHelper { if (c == null) { return (false); } - if (!isIetfInet(c)) {
- return (false);
- }
+ if (!isIetfInet(c)) { + return (false); + } String simpleName = c.getSimpleName(); return ("Ipv4Address".equals(simpleName)); } @@ -1179,9 +1179,9 @@ public class MdsalHelper { if (c == null) { return (false); } - if (!isIetfInet(c)) {
- return (false);
- }
+ if (!isIetfInet(c)) { + return (false); + } String simpleName = c.getSimpleName(); return ("Ipv6Address".equals(simpleName)); } @@ -1191,52 +1191,52 @@ public class MdsalHelper { if (c == null) { return (false); } - if (!isIetfInet(c)) {
- return (false);
- }
+ if (!isIetfInet(c)) { + return (false); + } String simpleName = c.getSimpleName(); return ("IpAddress".equals(simpleName)); } - public static boolean isPortNumber(Class c) {
-
- if (c == null) {
- return (false);
- }
- if (!isIetfInet(c)) {
- return (false);
- }
-
- String simpleName = c.getSimpleName();
- return ("PortNumber".equals(simpleName));
- }
-
- public static boolean isDscp(Class c) {
-
- if (c == null) {
- return (false);
- }
- if (!isIetfInet(c)) {
- return (false);
- }
- String simpleName = c.getSimpleName();
- return ("Dscp".equals(simpleName));
- }
-
- public static boolean isIetfInet(Class c) {
-
- Package p = c.getPackage();
- if (p != null) {
- String pkgName = p.getName();
-
- if ((pkgName != null) && (pkgName.indexOf("yang.ietf.inet.types") > -1)) {
- return (true);
- }
- }
-
- return (false);
- }
-
+ public static boolean isPortNumber(Class c) { + + if (c == null) { + return (false); + } + if (!isIetfInet(c)) { + return (false); + } + + String simpleName = c.getSimpleName(); + return ("PortNumber".equals(simpleName)); + } + + public static boolean isDscp(Class c) { + + if (c == null) { + return (false); + } + if (!isIetfInet(c)) { + return (false); + } + String simpleName = c.getSimpleName(); + return ("Dscp".equals(simpleName)); + } + + public static boolean isIetfInet(Class c) { + + Package p = c.getPackage(); + if (p != null) { + String pkgName = p.getName(); + + if ((pkgName != null) && (pkgName.indexOf("yang.ietf.inet.types") > -1)) { + return (true); + } + } + + return (false); + } + public static String toLowerHyphen(String inStr) { if (inStr == null) { return (null); |