Hi,
In answer to issue 1. below. We experienced the same problem. You have to
call JAXBContext.newInstance before using the generated typesafe enums. I
believe from debugging and inference from the documentation that the call to
newInstance actually set the proper DatatypeConvertor instance.
Regards,
Phil
-----Original Message-----
From: Wiedmann, Jochen [mailto:jochen.wiedmann_at_softwareag.com]
Sent: Monday, August 11, 2003 3:17 PM
To: 'users_at_jaxb.dev.java.net'
Subject: Questions on typesafe enum classes
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