Hi.

I'm new to the list, but have been developing with castor for a year or two now. So far, we have had few problems that weren't fixed in a timely fashion by the castor developers - until now.

I was wondering if is worth re-opening or creating a new bug for the sourcegenerator's hashCode() method generation function introduced through http://jira.codehaus.org/browse/CASTOR-1417

Basically, the hashCode that is currently calculated is only dependent on the elements and attributes specific defined specifically for an XML type/element. This means that changes to any elements and attributes inherited from base types do not affect the hashCode() for the whole element.

I have a small patch to ensure that for a schema like:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";>
    <xs:complexType name="bar">
        <xs:attribute name="name" type="xs:string"/>
    </xs:complexType>
    <xs:element name="foo">
        <xs:complexType>
            <xs:complexContent>
                <xs:extension base="bar">
                    <xs:sequence>
                        <xs:element name="foobar" type="xs:string"/>
                    </xs:sequence>
                </xs:extension>
            </xs:complexContent>
        </xs:complexType>
    </xs:element>
</xs:schema>

The value of hashCode for the source-generated class bound to element 'foo' changes when the attribute 'name' changes.

The patch for castor-1.1\codegen\src\main\java\org\exolab\castor\builder\SourceFactory.java is below:
-----Start of Patch
*** SourceFactory.java  2007-02-10 16:48:00.000000000 +0000
--- SourceFactory-new.java      2007-03-20 22:40:31.000000000 +0000
***************
*** 1107,1115 ****
          jclass.addMethod(jMethod);
          JSourceCode jsc = jMethod.getSourceCode();
          jsc.add("int result = 17;");
          jsc.add("");
          jsc.add("long tmp;");
          for (int i = 0; i < fields.length; i++) {
--- 1107,1119 ----
          jclass.addMethod(jMethod);
          JSourceCode jsc = jMethod.getSourceCode();
!         if (jclass.getSuperClassQualifiedName()==null) {
            jsc.add("int result = 17;");
+         } else {
+           jsc.add("int result = super.hashCode();");
+         }
          jsc.add("");
+
          jsc.add("long tmp;");
          for (int i = 0; i < fields.length; i++) {
-----End of Patch

As I said. It's really small - so almost not worth tracking in Jira.

thanks for a great tool!
Jim Procter.

--
-------------------------------------------------------------------
J. B. Procter (VAMSAS Project) Barton Bioinformatics Research Group
Phone/Fax:+44(0)1382 388734/345764  http://www.compbio.dundee.ac.uk

---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to