1 package org.opendaylight.controller.md.sal.dom.xsql;
3 import java.io.Serializable;
4 import java.sql.SQLException;
5 import java.util.Collection;
6 import java.util.HashSet;
9 public class XSQLBluePrintNode implements Serializable {
11 private static final long serialVersionUID = 1L;
12 private Class<?> myInterface = null;
13 private String myInterfaceString = null;
14 private Set<XSQLBluePrintRelation> relations =
15 new HashSet<XSQLBluePrintRelation>();
16 private Set<XSQLBluePrintNode> inheritingNodes =
17 new HashSet<XSQLBluePrintNode>();
18 private Set<XSQLBluePrintNode> children = new HashSet<XSQLBluePrintNode>();
19 private XSQLBluePrintNode parent = null;
21 private int level = -1;
22 private transient Set<String> parentHierarchySet = null;
23 private String myInterfaceName = null;
24 private Set<XSQLColumn> columns = new HashSet<XSQLColumn>();
26 private transient Object odlNode = null;
27 private boolean module = false;
28 private String bluePrintTableName = null;
29 private String odlTableName = null;
31 public XSQLBluePrintNode(Class<?> _myInterface, int _level) {
32 this.myInterface = _myInterface;
33 this.myInterfaceString = _myInterface.getName();
34 this.myInterfaceName = myInterface.getSimpleName();
38 public XSQLBluePrintNode(Object _odlNode, int _level,XSQLBluePrintNode _parent) {
39 this.odlNode = _odlNode;
41 this.module = XSQLODLUtils.isModule(_odlNode);
42 this.parent = _parent;
43 this.bluePrintTableName = XSQLODLUtils.getBluePrintName(_odlNode);
47 public String getBluePrintNodeName(){
48 return this.bluePrintTableName;
51 public boolean isModule() {
55 public Set<XSQLBluePrintNode> getChildren() {
59 public String getODLTableName() {
60 if (this.odlTableName == null) {
61 this.odlTableName = XSQLODLUtils.getODLNodeName(this.odlNode);
63 return this.odlTableName;
66 public Object getODLNode() {
70 public void AddChild(XSQLBluePrintNode ch) {
71 this.children.add(ch);
74 public boolean isModelChild(Class p) {
75 if (this.relations.size() == 0) {
78 for (XSQLBluePrintRelation parentRelation : this.relations) {
79 if (parentRelation.getParent().getInterface().equals(p)) {
83 for (XSQLBluePrintRelation dtr : this.relations) {
84 XSQLBluePrintNode parent = dtr.getParent();
85 if (!parent.getInterface().equals(this.getInterface()) && !parent
86 .getInterface().isAssignableFrom(this.getInterface()) &&
87 this.getInterface().isAssignableFrom(parent.getInterface())
88 && parent.isModelChild(p)) {
95 public Set<XSQLBluePrintRelation> getRelations() {
96 return this.relations;
99 public String getClassName() {
100 return this.myInterfaceString;
103 public void addInheritingNode(XSQLBluePrintNode node) {
104 this.inheritingNodes.add(node);
107 public Set<XSQLBluePrintNode> getInheritingNodes() {
108 return this.inheritingNodes;
111 public void addColumn(Object node, String tableName) {
112 XSQLColumn c = new XSQLColumn(node,getBluePrintNodeName(), this);
116 public void addColumn(String methodName) {
117 if (methodName.startsWith("get")) {
118 methodName = methodName.substring(3);
119 } else if (methodName.startsWith("is")) {
120 methodName = methodName.substring(2);
122 XSQLColumn c = new XSQLColumn(methodName, myInterfaceName, null);
126 public Collection<XSQLColumn> getColumns() {
130 public XSQLColumn findColumnByName(String name) throws SQLException {
132 XSQLColumn exactMatch = null;
133 XSQLColumn indexOfMatch = null;
134 XSQLColumn exactLowercaseMatch = null;
135 XSQLColumn indexOfLowerCaseMatch = null;
137 for (XSQLColumn col : columns) {
138 if (col.getName().equals(name)) {
141 if (col.getName().indexOf(name) != -1) {
144 if (col.getName().toLowerCase().equals(name.toLowerCase())) {
145 exactLowercaseMatch = col;
147 if (col.getName().toLowerCase().indexOf(name.toLowerCase()) != -1) {
148 indexOfLowerCaseMatch = col;
152 if (exactMatch != null) {
155 if (exactLowercaseMatch != null) {
156 return exactLowercaseMatch;
158 if (indexOfMatch != null) {
161 if (indexOfLowerCaseMatch != null) {
162 return indexOfLowerCaseMatch;
165 throw new SQLException("Unknown field name '" + name + "'");
169 public void addParent(XSQLBluePrintNode parent, String property) {
171 if (property.equals("ContainingTPs")) {
174 //Method m = parent.getInterface().getMethod("get"+property, null);
175 //if(!m.getDeclaringClass().equals(parent.getInterface()))
177 XSQLBluePrintRelation rel =
178 new XSQLBluePrintRelation(parent, property, myInterface);
180 } catch (Exception err) {
181 err.printStackTrace();
185 public XSQLBluePrintNode getParent() {
189 public Set<XSQLBluePrintRelation> getClonedParents() {
190 Set<XSQLBluePrintRelation> result =
191 new HashSet<XSQLBluePrintRelation>();
192 result.addAll(this.relations);
196 public String toString() {
197 if (myInterfaceName != null) {
198 return myInterfaceName;
200 if (odlNode != null) {
201 return getBluePrintNodeName();
206 public Class getInterface() {
207 return this.myInterface;
210 public int getLevel() {
215 public boolean equals(Object obj) {
216 XSQLBluePrintNode other = (XSQLBluePrintNode) obj;
217 if (odlNode != null) {
218 return getBluePrintNodeName().equals(other.getBluePrintNodeName());
219 } else if (this.odlTableName != null) {
220 return this.odlTableName.equals(other.odlTableName);
222 return other.myInterface.equals(myInterface);
227 public int hashCode() {
228 if (myInterfaceString != null) {
229 return myInterfaceString.hashCode();
230 } else if (odlNode != null) {
231 return bluePrintTableName.hashCode();