And below, a corrected version:
protected static boolean objectEquals(final XmlObject a, final XmlObject
b)
{
if (a == null)
{
if (b == null)
return true;
else
return false;
}
if (b == null)
return false;
final SchemaType sa = a.schemaType();
final SchemaType sb = b.schemaType();
if (sa.getContentType() == SchemaType.NOT_COMPLEX_TYPE)
{
if (sb.getContentType() == SchemaType.NOT_COMPLEX_TYPE)
return a.valueEquals(b);
else
return false;
}
if (!sa.equals(sb))
return false;
// compare attributes
for (final SchemaProperty property : sa.getAttributeProperties())
{
final XmlObject pa = a.selectAttribute(property.getName());
final XmlObject pb = b.selectAttribute(property.getName());
if (!RegistryBase.objectEquals(pa, pb))
return false;
}
// compare elements
for (final SchemaProperty property : sa.getElementProperties())
{
final XmlObject[] ea = a.selectChildren(property.getName());
final XmlObject[] eb = b.selectChildren(property.getName());
if (ea.length != eb.length)
return false;
for (int i = 0; i < ea.length; i++)
{
if (!RegistryBase.objectEquals(ea[i], eb[i]))
return false;
}
}
return a.valueEquals(b);
}
On 5/2/09 23:25, "Wesley Leggette" <[email protected]> wrote:
> In my application code, I've attempted to implement a somewhat generic
> content aware comparison. Would anyone care to review this and let me know
> if it seems correct? If it is a sound approach, should I look to make a
> patch adding this to xmlbeans proper?
>
>
> Thanks,
> Wesley
>
>
> ----------
>
>
> private boolean objectEquals(final XmlObject a, final XmlObject b)
> {
> if (a == null)
> {
> if (b == null)
> return true;
> else
> return false;
> }
>
> if (b == null)
> return false;
>
> if (a instanceof SimpleValue)
> {
> if (b instanceof SimpleValue)
> return a.valueEquals(b);
> else
> return false;
> }
>
> final SchemaType sa = a.schemaType();
> final SchemaType sb = b.schemaType();
>
> if (!sa.equals(sb))
> return false;
>
> // compare attributes
> for (final SchemaProperty property : sa.getAttributeProperties())
> {
> final XmlObject pa = a.selectAttribute(property.getName());
> final XmlObject pb = b.selectAttribute(property.getName());
> if (!objectEquals(pa, pb))
> return false;
> }
>
> // compare elements
> for (final SchemaProperty property : sa.getElementProperties())
> {
> final XmlObject[] ea = a.selectChildren(property.getName());
> final XmlObject[] eb = b.selectChildren(property.getName());
>
> if (ea.length != eb.length)
> return false;
> for (int i = 0; i < ea.length; i++)
> objectEquals(ea[i], eb[i]);
> }
>
> return a.valueEquals(b);
> }
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]