dev@jersey.java.net

RE: [Jersey] WebDAV "Depth" header and enum <was> Re: Developer role

From: Markus KARG <markus.karg_at_gmx.net>
Date: Fri, 9 Jan 2009 22:36:04 +0100

> >> I currently have defined header constants like "Depth", as defined
> >> by the WebDAV spec. I have seen that some of them are defined in
> >> the WebDAV spec to be actually not Strings but enums, i. e. for
> >> example, the WebDAV "Depth" header must only be one of the Strings
> >> "0", "1" or "infinity". So to prevent people from incidentially
> >> using "2", "3" or "infinte" as an invalid header value, it would be
> >> great to make that particular header not a String but an enum. Is
> >> that possible in JAX-RS? For example, can I use an enum in a method
> >> as a @HeaderParam variable?
> >
> > IIRC it is possible to use Enum classes, i recommend experimenting
> > with a simple class.
> >
> Add a "public static DepthEnum valueOf(String)" method to your enum
> class that returns the corresponding enum constant for the string
> value (or null if none exists) and you should be all set.

Seems this is not possible. After I added this line to my enum class:

public static Depth valueOf(final String name) {
        if (name.equals("0"))
                return ZERO;
        ...
}

the compiler says: "The enum Depth already defines the method value(String)
implicitly.".

It seems it is impossible to overwrite valueOf(String) with your own
implementation.

Regards
Markus