Search in sources :

Example 1 with Equals

use of org.jvnet.jaxb2_commons.lang.Equals in project midpoint by Evolveum.

the class PrismPropertyValue method equalsComplex.

public boolean equalsComplex(PrismPropertyValue<?> other, boolean ignoreMetadata, boolean isLiteral, MatchingRule<T> matchingRule) {
    if (!super.equalsComplex(other, ignoreMetadata, isLiteral)) {
        return false;
    }
    if (this.rawElement != null && other.rawElement != null) {
        return equalsRawElements((PrismPropertyValue<T>) other);
    }
    PrismPropertyValue<T> otherProcessed = (PrismPropertyValue<T>) other;
    PrismPropertyValue<T> thisProcessed = this;
    if (this.rawElement != null || other.rawElement != null) {
        try {
            if (this.rawElement == null) {
                otherProcessed = parseRawElementToNewValue((PrismPropertyValue<T>) other, this);
            } else if (other.rawElement == null) {
                thisProcessed = parseRawElementToNewValue(this, (PrismPropertyValue<T>) other);
            }
        } catch (SchemaException e) {
            // TODO: Maybe just return false?
            throw new IllegalArgumentException("Error parsing the value of property " + getParent() + " using the 'other' definition " + "during a compare: " + e.getMessage(), e);
        }
    }
    T otherRealValue = otherProcessed.getValue();
    T thisRealValue = thisProcessed.getValue();
    if (otherRealValue == null && thisRealValue == null) {
        return true;
    }
    if (otherRealValue == null || thisRealValue == null) {
        return false;
    }
    if (matchingRule != null) {
        try {
            return matchingRule.match(thisRealValue, otherRealValue);
        } catch (SchemaException e) {
            // ordinary equality mechanism instead.
            return thisRealValue.equals(otherRealValue);
        }
    } else {
        if (thisRealValue instanceof Element && otherRealValue instanceof Element) {
            return DOMUtil.compareElement((Element) thisRealValue, (Element) otherRealValue, isLiteral);
        }
        if (thisRealValue instanceof SchemaDefinitionType && otherRealValue instanceof SchemaDefinitionType) {
            SchemaDefinitionType thisSchema = (SchemaDefinitionType) thisRealValue;
            return thisSchema.equals(otherRealValue, isLiteral);
        //			return DOMUtil.compareElement((Element)thisRealValue, (Element)otherRealValue, isLiteral);
        }
        if (thisRealValue instanceof byte[] && otherRealValue instanceof byte[]) {
            return Arrays.equals((byte[]) thisRealValue, (byte[]) otherRealValue);
        }
        if (isLiteral) {
            if (thisRealValue instanceof QName && otherRealValue instanceof QName) {
                // we compare prefixes as well
                if (!thisRealValue.equals(otherRealValue)) {
                    return false;
                }
                return StringUtils.equals(((QName) thisRealValue).getPrefix(), ((QName) otherRealValue).getPrefix());
            } else if (thisRealValue instanceof Equals && otherRealValue instanceof Equals) {
                return ((Equals) thisRealValue).equals(null, null, otherRealValue, LiteralEqualsStrategy.INSTANCE);
            }
        }
        return thisRealValue.equals(otherRealValue);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Equals(org.jvnet.jaxb2_commons.lang.Equals) SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element)

Aggregations

SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SchemaDefinitionType (com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType)1 JAXBElement (javax.xml.bind.JAXBElement)1 QName (javax.xml.namespace.QName)1 Equals (org.jvnet.jaxb2_commons.lang.Equals)1 Element (org.w3c.dom.Element)1