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=16a33b380bb4e54a09ee6e70025e45e8ab1de263;hp=17b8ae5f291e7a12f425dd20a96010ddb165af20;hb=78527e81f8cc82140af5cb2649863a597f380291;hpb=c181b0ab3202b1d5d87d6048d85c787fde090b8a 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 17b8ae5f29..16a33b380b 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 @@ -1,15 +1,27 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.md.sal.dom.xsql; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; 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; +import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; @@ -20,7 +32,9 @@ 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; - +/** + * @author Sharon Aicler(saichler@gmail.com) + **/ public class XSQLODLUtils { private static Map, Class> types = @@ -113,7 +127,7 @@ public class XSQLODLUtils { public static boolean createOpenDaylightCache(XSQLBluePrint bluePrint,Object module) { XSQLBluePrintNode node = new XSQLBluePrintNode(module, 0,null); - bluePrint.addToBluePrintCache(node); + bluePrint.addToBluePrintCache(node,null); collectODL(bluePrint, node, ((Module) module).getChildNodes(), 1); return true; } @@ -124,20 +138,30 @@ public class XSQLODLUtils { return; } for (DataSchemaNode n : nodes) { - if (n instanceof DataNodeContainer /*|| n instanceof LeafListSchemaNode*/ - || n instanceof ListSchemaNode) { + if (n instanceof DataNodeContainer) { XSQLBluePrintNode bn = new XSQLBluePrintNode(n, level,parent); - bluePrint.addToBluePrintCache(bn); - parent.AddChild(bn); - if (n instanceof DataNodeContainer) { + bn = bluePrint.addToBluePrintCache(bn,parent); + if (n instanceof ListSchemaNode) { level++; - collectODL(bluePrint, bn, - ((DataNodeContainer) n).getChildNodes(), level); + collectODL(bluePrint, bn,((ListSchemaNode) n).getChildNodes(), level); + Set s = ((ListSchemaNode)n).getAvailableAugmentations(); + if(s!=null){ + for(AugmentationSchema as:s){ + collectODL(bluePrint, bn,as.getChildNodes(), level); + } + } level--; - } else if (n instanceof ListSchemaNode) { + }else{ level++; - collectODL(bluePrint, bn, - ((ListSchemaNode) n).getChildNodes(), level); + collectODL(bluePrint, bn,((DataNodeContainer) n).getChildNodes(), level); + if(n instanceof ContainerSchemaNode){ + Set s = ((ContainerSchemaNode)n).getAvailableAugmentations(); + if(s!=null){ + for(AugmentationSchema as:s){ + collectODL(bluePrint, bn,as.getChildNodes(), level); + } + } + } level--; } } else { @@ -189,7 +213,7 @@ public class XSQLODLUtils { Field f = findField(c, name); return f.get(o); } catch (Exception err) { - XSQLAdapter.log(err); + //XSQLAdapter.log(err); } return null; } @@ -207,6 +231,21 @@ public class XSQLODLUtils { return (Map) get(o, "children"); } + public static Collection getChildrenCollection(Object o) { + Object value = get(o, "children"); + if(value==null) + return Collections.emptyList(); + if(value instanceof Map) + return ((Map)value).values(); + else + if(value instanceof Collection){ + return (Collection)value; + }else{ + XSQLAdapter.log("Unknown Child Value Type="+value.getClass().getName()); + return new ArrayList(); + } + } + public static Object getValue(Object o) { return get(o, "value"); }