KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > utils > ObjectEqualsXmlObjectComparator


1 /**
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.config.schema.utils;
5
6 import org.apache.xmlbeans.XmlObject;
7
8 /**
9  * An {@link XmlObjectComparator} that simply calls {@link Object#equals(Object)} to compare its arguments. Note that
10  * this should <strong>NEVER</strong> be used on real {@link XmlObject}s, as they don't implement
11  * {@link Object#equals(Object)} correctly. Rather, this is used only for tests.
12  */

13 public class ObjectEqualsXmlObjectComparator implements XmlObjectComparator {
14
15   public boolean equals(XmlObject one, XmlObject two) {
16     try {
17       checkEquals(one, two);
18       return true;
19     } catch (NotEqualException nee) {
20       return false;
21     }
22   }
23
24   public void checkEquals(XmlObject one, XmlObject two) throws NotEqualException {
25     if ((one == null) != (two == null)) throw new NotEqualException("nullness not the same");
26     if (one == null) return;
27     if (!one.equals(two)) throw new NotEqualException("not equal");
28   }
29
30 }
31
Popular Tags