* @return True if the two objects are equal or else false. The equality is checked as explained above.
*/
public boolean equals(Object obj) {
String attrValue = getValue();
if (obj instanceof OMAttribute) { // Checks equality of an OMAttributeImpl or an AttrImpl with this instance
OMAttribute other = (OMAttribute) obj;
return (namespace == null ? other.getNamespace() == null :
namespace.equals(other.getNamespace()) &&
localName.equals(other.getLocalName()) &&
(attrValue == null ? other.getAttributeValue() == null :
attrValue.toString().equals(other.getAttributeValue())));
} else if (obj instanceof Attr) {// Checks equality of an org.w3c.dom.Attr with this instance
Attr other = (Attr)obj;
String otherNs = other.getNamespaceURI();
if (namespace == null) { // I don't have a namespace
if (otherNs != null) {
return false; // I don't have a namespace and the other has. So return false
} else {
// Both of us don't have namespaces. So check for name and value equality only
return (localName.equals(other.getLocalName()) &&
(attrValue == null ? other.getValue() == null :
attrValue.toString().equals(other.getValue())));
}
} else { // Ok, now I've a namespace
String ns = namespace.getNamespaceURI();
String prefix = namespace.getPrefix();
String otherPrefix = other.getPrefix();
// First check for namespaceURI equality. Then check for prefix equality.
// Then check for name and value equality
return (ns.equals(otherNs) && (prefix == null ? otherPrefix == null : prefix.equals(otherPrefix)) &&
(localName.equals(other.getLocalName())) &&
(attrValue == null ? other.getValue() == null :
attrValue.toString().equals(other.getValue())));
}
}
return false;
}