Done. The toString() method is very similar, but simpler. Maybe it should be a very good idea to implement it as well.
Michele Ralf Joachim wrote: > Hi Michele, > > to create new issues you need to login which is only possible if you > have signed up first. You can do that with the following steps: > > - goto: http://jira.codehaus.org/browse/CASTOR > - select "login" at the top right corner of the page > - select "signup" at right side of page > - enter the requested information > > You should be redirected to the original url from above after you > finished but this time you should see "CREATE NEW ISSUE" as the 4. item > on the menue bar at the top of the page. > > As creator of the issue you should get notification mails if someone > comments to or changes the issue as I, and other commiters, get > notifications on every new /changed issue. > > Hope this helps > Ralf > > > Michele Mazzucco schrieb: >> Ralf, >> >> I'm sorry, but I've never used a tool like that. How can I create a new >> issue (it seems that from that link you can just browse issues)? >> >> Michele >> >> Ralf Joachim wrote: >> >>> Hi Michele, >>> >>> thank you very much for your contribution so far. May it be possible for >>> you to create a new issue for this in castor bug tracking under: >>> >>> http://jira.codehaus.org/browse/CASTOR >>> >>> and attach you additions as a unified patch to the new issue. The patch >>> would make my work just a bit easier then without. Having said that I'll >>> try to get your additions into next release. >>> >>> Regards >>> Ralf >>> >>> >>> Michele Mazzucco schrieb: >>> >>>> I added this code to the org.exolab.castor.builder.SourceFactory class: >>>> >>>> /** >>>> * Create an "hashCode" method on the given JClass. >>>> * >>>> * @param jclass the JClass in wich we create the hashCode method. >>>> */ >>>> public static void createHashCodeMethod(JClass jclass) { >>>> if (jclass == null) { >>>> throw new IllegalArgumentException("JClass must not be >>>> null"); >>>> } >>>> >>>> // The argument is not null >>>> JField[] fields = jclass.getFields(); >>>> >>>> // Creates the method signature >>>> JMethod jMethod = new JMethod(JType.Int, "hashCode"); >>>> jMethod.setComment("Override the java.lang.Object.hashCode >>>> method"); >>>> >>>> // The hashCode method has no arguments >>>> jclass.addMethod(jMethod); >>>> >>>> JSourceCode jsc = jMethod.getSourceCode(); >>>> >>>> // The following steps came from Effective Java Programming >>>> Language >>>> Guide by Joshua Bloch, chapter 3 >>>> jsc.add("int result = 17;"); >>>> >>>> for (int i = 0; i <fields.length; i++) { >>>> JField temp = fields[i]; >>>> // If the field is an object the hashCode method is >>>> called recursively >>>> >>>> JType type = temp.getType(); >>>> String name = temp.getName(); >>>> if (type.isPrimitive()) { >>>> if (type == JType.Boolean) { >>>> jsc.add("result = 37 * result + (" + >>>> name + "?0:1);"); >>>> } else >>>> if ((type == JType.Byte) || >>>> (type == JType.Short) || >>>> (type == JType.Int)) { >>>> >>>> jsc.add("result = 37 * result + (int)" >>>> + name + ";"); >>>> } else if (type == JType.Long) { >>>> jsc.add("result = 37 * result + (int)(" >>>> + name + "^(" + name + >>>> ">>>32));"); >>>> } else if (type == JType.Float) { >>>> jsc.add("result = 37 * result + >>>> Float.floatToIntBits(" + name + ");"); >>>> } else if (type == JType.Double) { >>>> jsc.add("long tmp = >>>> Double.doubleToLongBits(" + name + ");"); >>>> jsc.add("result = 37 * result + >>>> (int)(tmp^(tmp>>>32));"); >>>> } >>>> } else { >>>> // Calculates hashCode in a recursive manner. >>>> jsc.add("result = 37 * result + " + name + >>>> ".hashCode();"); >>>> } >>>> } >>>> jsc.add(""); >>>> jsc.add("return result;"); >>>> } //createHashCodeMethod >>>> >>>> >>>> >>>> >>>> and into the createSourceCode() method I've added the following control >>>> >>>> //create equals() method? >>>> if (component.hasEquals()) { >>>> createEqualsMethod(jClass); >>>> createHashCodeMethod(jClass); >>>> } >>>> >>>> since the hashCode method *must* be added when the equals method is >>>> created (see Effective Java Programming Language Guide by Joshua Bloch, >>>> chapter 3). >>>> >>>> >>>> Best regards, >>>> Michele >>>> >>>> >>>> >>>> Ralf Joachim wrote: >>>> >>>> >>>>> Hi Michele, >>>>> >>>>> SourceGenerator seams not to be able to generate hashcode() / equals() >>>>> methods at the moment. In general I don't see a reason why it should not >>>>> be possible to improve SourceGenerator to also generate them. As with >>>>> other open source projects we are open for contributions. So you are >>>>> open to volunteer on this addition. >>>>> >>>>> Regards >>>>> Ralf >>>>> Castor JDO, committer >>>>> >>>>> >>>>> Michele Mazzucco schrieb: >>>>> >>>>> >>>>>> Hi all, >>>>>> >>>>>> is it possible to "autogenerate" the hashCode() method on java objects >>>>>> created from the xml schema?, otherwise checks on the server side could >>>>>> return wrong values (i.e. checking if an object sent by by client is >>>>>> stored in a collection hosted by the server side). >>>>>> >>>>>> >>>>>> Thanks in advance, >>>>>> Michele >>>>>> >>>>>> ------------------------------------------------- >>>>>> If you wish to unsubscribe from this list, please send an empty >>>>>> message to the following address: >>>>>> >>>>>> [EMAIL PROTECTED] >>>>>> ------------------------------------------------- >>>>> ------------------------------------------------- >>>>> If you wish to unsubscribe from this list, please send an empty message >>>>> to the following address: >>>>> >>>>> [EMAIL PROTECTED] >>>>> ------------------------------------------------- >>>>> >>>> ------------------------------------------------- >>>> If you wish to unsubscribe from this list, please >>>> send an empty message to the following address: >>>> >>>> [EMAIL PROTECTED] >>>> ------------------------------------------------- >> ------------------------------------------------- >> If you wish to unsubscribe from this list, please >> send an empty message to the following address: >> >> [EMAIL PROTECTED] >> ------------------------------------------------- > ------------------------------------------------- If you wish to unsubscribe from this list, please send an empty message to the following address: [EMAIL PROTECTED] -------------------------------------------------

