X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsal%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fcore%2FNode.java;h=0ea04c32065e7746518504901abc454f4d5e6281;hp=5c21294f46da0438da325b263039a895e3f08371;hb=0007635e8377230bf3befc836f1e05b6e075251b;hpb=69bbdbb02e3f4755b95fa62b9a3610a3a11c9724 diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java index 5c21294f46..0ea04c3206 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java @@ -27,11 +27,12 @@ import java.util.concurrent.ConcurrentHashMap; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; import org.opendaylight.controller.sal.utils.HexEncode; +import org.opendaylight.controller.sal.utils.INodeFactory; +import org.opendaylight.controller.sal.utils.ServiceHelper; /** * Describe a generic network element in multiple SDNs technologies. A @@ -197,7 +198,7 @@ public class Node implements Serializable { * * @return The node Type for this Node object */ - @XmlAttribute(name = "type") + @XmlElement(name = "type") public String getType() { return this.nodeType; } @@ -228,15 +229,20 @@ public class Node implements Serializable { } else if (typeStr.equals(NodeIDType.PRODUCTION)) { this.nodeID = IDStr; } else { - // We need to lookup via OSGi service registry for an - // handler for this + //Use plugin's method to get appropriate conversion from IDStr to nodeID + INodeFactory f = (INodeFactory) ServiceHelper + .getGlobalInstance(INodeFactory.class, new Node(), "(protocolName="+typeStr+")"); + if(f!=null){ + Node n = f.fromString(typeStr, IDStr); + this.nodeID = n.nodeID; + } } } - /** + /** * Private setter for nodeType to be called by JAXB not by anyone * else, Node is immutable - * + * * @param type of node to be set */ private void setType(String type) { @@ -261,7 +267,7 @@ public class Node implements Serializable { * * @return The nodeID in string format */ - @XmlAttribute(name = "id") + @XmlElement(name = "id") public String getNodeIDString() { if (this.nodeType.equals(NodeIDType.OPENFLOW)) { return HexEncode.longToHexString((Long) this.nodeID); @@ -269,10 +275,10 @@ public class Node implements Serializable { return this.nodeID.toString(); } } - - /** + + /** * private setter to be used by JAXB - * + * * @param nodeIDString String representation for NodeID */ private void setNodeIDString(String nodeIDString) { @@ -284,33 +290,43 @@ public class Node implements Serializable { @Override public int hashCode() { - return new HashCodeBuilder(163841, 56473) - .append(nodeType) - .append(nodeID) - .hashCode(); + final int prime = 31; + int result = 1; + result = prime * result + ((nodeID == null) ? 0 : nodeID.hashCode()); + result = prime * result + + ((nodeType == null) ? 0 : nodeType.hashCode()); + return result; } @Override public boolean equals(Object obj) { - if (obj == null) { return false; } - if (obj == this) { return true; } - if (obj.getClass() != getClass()) { + if (this == obj) + return true; + if (obj == null) return false; - } - Node rhs = (Node)obj; - return new EqualsBuilder() - .append(this.getType(), rhs.getType()) - .append(this.getID(), rhs.getID()) - .isEquals(); + if (getClass() != obj.getClass()) + return false; + Node other = (Node) obj; + if (nodeID == null) { + if (other.nodeID != null) + return false; + } else if (!nodeID.equals(other.nodeID)) + return false; + if (nodeType == null) { + if (other.nodeType != null) + return false; + } else if (!nodeType.equals(other.nodeType)) + return false; + return true; } @Override public String toString() { if (this.nodeType.equals(NodeIDType.OPENFLOW)) { - return this.nodeType.toString() + "|" + return this.nodeType + "|" + HexEncode.longToHexString((Long) this.nodeID); } else { - return this.nodeType.toString() + "|" + this.nodeID.toString(); + return this.nodeType + "|" + this.nodeID.toString(); } } @@ -429,9 +445,13 @@ public class Node implements Serializable { return null; } } else { - // We need to lookup via OSGi service registry for an - // handler for this + //Use INodeFactory to create a Node of registered Node type. + //The protocol plugin being used depends on typeStr. + INodeFactory f = (INodeFactory) ServiceHelper + .getGlobalInstance(INodeFactory.class, new Node(), "(protocolName="+typeStr+")"); + if(f==null) + return null; + return f.fromString(typeStr, IDStr); } - return null; } }