X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-xsql%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fxsql%2FXSQLODLUtils.java;h=a42e47ba005cd9ee3451bad18491a6cff714e6f6;hp=16a33b380bb4e54a09ee6e70025e45e8ab1de263;hb=d0dc66335889ecec5dbc962a8604c3df96eca758;hpb=2727bea09c83646b6cbd2ef9672d0b7f6cf3b22f diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLODLUtils.java b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLODLUtils.java index 16a33b380b..a42e47ba00 100644 --- a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLODLUtils.java +++ b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLODLUtils.java @@ -17,7 +17,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; - import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; @@ -28,17 +27,20 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.Status; -import org.opendaylight.yangtools.yang.model.util.Uint16; -import org.opendaylight.yangtools.yang.model.util.Uint32; -import org.opendaylight.yangtools.yang.model.util.Uint64; -import org.opendaylight.yangtools.yang.model.util.Uint8; +import org.opendaylight.yangtools.yang.model.api.TypeDefinition; +import org.opendaylight.yangtools.yang.model.util.type.DerivedTypes; + /** * @author Sharon Aicler(saichler@gmail.com) **/ +/** + * To be removed in Nitrogen + */ +@Deprecated public class XSQLODLUtils { private static Map, Class> types = - new ConcurrentHashMap, Class>(); + new ConcurrentHashMap<>(); static { types.put(QName.class, QName.class); @@ -46,11 +48,11 @@ public class XSQLODLUtils { types.put(Status.class, Status.class); } - public static boolean isColumnType(Class cls) { + public static boolean isColumnType(final Class cls) { return types.containsKey(cls); } - public static String getTableName(Object odlNode) { + public static String getTableName(final Object odlNode) { if (odlNode instanceof Module) { return ((Module) odlNode).getNamespace().toString(); } else if (odlNode instanceof DataSchemaNode) { @@ -62,7 +64,7 @@ public class XSQLODLUtils { return null; } - public static String extractTableName(SchemaPath path) { + public static String extractTableName(final SchemaPath path) { List lst = path.getPath(); StringBuffer name = new StringBuffer(); int i = 0; @@ -76,7 +78,7 @@ public class XSQLODLUtils { return name.toString(); } - public static String getBluePrintName(Object odlNode){ + public static String getBluePrintName(final Object odlNode){ if (odlNode instanceof Module) { return ((Module) odlNode).getNamespace().toString(); } else if (odlNode instanceof DataSchemaNode) { @@ -86,7 +88,7 @@ public class XSQLODLUtils { return null; } - public static String getODLNodeName(Object odlNode) { + public static String getODLNodeName(final Object odlNode) { if (odlNode instanceof Module) { return ((Module) odlNode).getNamespace().toString(); } else if (odlNode instanceof DataSchemaNode) { @@ -97,12 +99,12 @@ public class XSQLODLUtils { return null; } - public static List getPath(Object odlNode) { + public static List getPath(final Object odlNode) { return ((DataSchemaNode) odlNode).getPath().getPath(); } - public static String getODLTableName(Object odlNode) { + public static String getODLTableName(final Object odlNode) { if (odlNode instanceof Module) { return ((Module) odlNode).getNamespace().toString(); } else if (odlNode instanceof DataSchemaNode) { @@ -111,29 +113,29 @@ public class XSQLODLUtils { return null; } - public static String getNodeNameFromDSN(Object o) { + public static String getNodeNameFromDSN(final Object o) { DataSchemaNode node = (DataSchemaNode) o; String nodeName = node.getQName().toString(); int index = nodeName.lastIndexOf(")"); return nodeName.substring(index + 1); } - public static boolean isModule(Object o) { + public static boolean isModule(final Object o) { if (o instanceof Module) { return true; } return false; } - public static boolean createOpenDaylightCache(XSQLBluePrint bluePrint,Object module) { + public static boolean createOpenDaylightCache(final XSQLBluePrint bluePrint, final Module module) { XSQLBluePrintNode node = new XSQLBluePrintNode(module, 0,null); bluePrint.addToBluePrintCache(node,null); - collectODL(bluePrint, node, ((Module) module).getChildNodes(), 1); + collectODL(bluePrint, node, module.getChildNodes(), 1); return true; } - private static void collectODL(XSQLBluePrint bluePrint, - XSQLBluePrintNode parent, Collection nodes, int level) { + private static void collectODL(final XSQLBluePrint bluePrint, + final XSQLBluePrintNode parent, final Collection nodes, int level) { if (nodes == null) { return; } @@ -175,9 +177,9 @@ public class XSQLODLUtils { } public static Map refFieldsCache = - new HashMap(); + new HashMap<>(); - public static Field findField(Class c, String name) { + public static Field findField(final Class c, final String name) { if (c == null) { return null; } @@ -207,7 +209,7 @@ public class XSQLODLUtils { } - public static Object get(Object o, String name) { + public static Object get(final Object o, final String name) { try { Class c = o.getClass(); Field f = findField(c, name); @@ -218,26 +220,27 @@ public class XSQLODLUtils { return null; } - public static List getMChildren(Object o) { + public static List getMChildren(final Object o) { Map children = getChildren(o); - List result = new LinkedList(); + List result = new LinkedList<>(); for (Object val : children.values()) { - result.add((Object) val); + result.add(val); } return result; } - public static Map getChildren(Object o) { + public static Map getChildren(final Object o) { return (Map) get(o, "children"); } - public static Collection getChildrenCollection(Object o) { + public static Collection getChildrenCollection(final Object o) { Object value = get(o, "children"); - if(value==null) + if(value==null) { return Collections.emptyList(); - if(value instanceof Map) + } + if(value instanceof Map) { return ((Map)value).values(); - else + } else if(value instanceof Collection){ return (Collection)value; }else{ @@ -246,11 +249,11 @@ public class XSQLODLUtils { } } - public static Object getValue(Object o) { + public static Object getValue(final Object o) { return get(o, "value"); } - public static String getNodeIdentiofier(Object o) { + public static String getNodeIdentiofier(final Object o) { try{ return ((PathArgument) get(o, "nodeIdentifier")).getNodeType().toString(); }catch(Exception err){ @@ -258,7 +261,7 @@ public class XSQLODLUtils { } } - public static String getNodeName(Object o) { + public static String getNodeName(final Object o) { Object nodeID = get(o, "nodeIdentifier"); if (nodeID != null) { String nodeName = nodeID.toString(); @@ -268,17 +271,20 @@ public class XSQLODLUtils { return "NULL"; } - public static Class getTypeForODLColumn(Object odlNode){ - Object type = get(odlNode,"type"); - if(type instanceof Uint32 || type instanceof Uint64){ - return long.class; - }else - if(type instanceof Uint16){ - return int.class; - }else - if(type instanceof Uint8){ - return byte.class; + public static Class getTypeForODLColumn(final Object odlNode){ + final Object o = get(odlNode,"type"); + if (o instanceof TypeDefinition) { + final TypeDefinition type = (TypeDefinition)o; + + if (DerivedTypes.isUint32(type) || DerivedTypes.isUint64(type)) { + return long.class; + } else if (DerivedTypes.isUint16(type)) { + return int.class; + } else if (DerivedTypes.isUint8(type)) { + return byte.class; + } } + return String.class; }