users@jaxb.java.net

Questions on typesafe enum classes

From: Wiedmann, Jochen <jochen.wiedmann_at_softwareag.com>
Date: Mon, 11 Aug 2003 22:17:06 +0200

Hi,

I have just started my first attempt to work with the typesafe enum classes
and found a couple of questions arising. Attached you find a sample schema,
that I was using.

1.) When I write a simple main class, that invokes the enum classes
fromValue() method, I receive the following exception:

      Exception in thread "main" java.lang.ExceptionInInitializerError
      Caused by: java.lang.NullPointerException
        at
javax.xml.bind.DatatypeConverter.parseInt(DatatypeConverter.java:144)
        at
net.sf.jaxme.examples.misc.enumeration.LocalIntTypeClass.<clinit>(LocalIntTy
peClass.java:28)

    Do I need some initialization when using the typesafe enum classes?

2.) I was expecting that an anonymous simple types enum classes would be
generated as inner classes
    of the corresponding complex types interface. However, this doesn't seem
to be the case. To quote
    the spec: "By default, if the XML component containing a typesafe enum
class to be generated is
    scoped within a complex type as opposed to a global scope, the typesafe
enum class should occur
    as a nested class within the Java content interface representing the
complex type scope." [4.3]

    Perhaps I misunderstand the meaning of "the XML component containing a
typesafe enum class". If
    so, please verify the "LocalSimpleTypesElement" in the attached class
and fix my error.

3.) I wondered that the typesafe enum classes to not implement the
java.io.Serializable interface.

4.) Perhaps related to 3.), I wondered about the hashCode() and equals()
methods. I was expecting
    something similar to

        public int hashCode() { return value; }
        public boolean equals(Object o) { return o != null && o instanceof
MyClass && ((MyClass) o).value == value; }

    IMO the generated equals method (which is simply invoking
Object.equals(Object)) fails on
    objects that I receive via serialization. I wasn't able to demonstrate
that, though, due to
    the problems in 1.)



Regards,

Jochen

  




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net