dev@jersey.java.net

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

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 12 Jan 2009 21:52:16 +0100

On Jan 12, 2009, at 8:09 PM, Markus KARG wrote:

> Well, it's less that I don't WANT the enum constants to be named
> "ZERO", but more the problem is that 0 is not recognized as a valid
> constant identified, obviously...
>
> The idea with the wrapper, well, yes, is possible but seems to be
> too complicated for the programmer: It imposes the need to unwrap
> the object to get to the enum -- in that case it is far easier to
> live with the header value as a string and do not use any special
> WebDAV Classes at all... :-(
>
> Your last propsal, using no headers but a complex class being built
> by a message body reader from the entity plus all headers, sounds
> interesting. I doubt that it will work with WebDAV since the bodies
> can be different, but I will ask the WebDAV expert, Julian Reschke.
> Also, maybe it is possible to declare an abstract type
> "WebDav.class" and let the message body reader decide to return one
> of several possible child classes?

Yes, it is possible for a reader to support multiple Java types,
related or otherwise.


> That would be cool for the programmer, and hides all the WebDav
> stuff behind a single class.

Right, nice from an ease of use perspective, i which i thought might
work for certain WebDAV methods but obviously not all HTTP methods.

Paul.


> Sounds good, but we'll have to check.
>
> Thanks a lot!
> Markus
>
> From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
> Sent: Montag, 12. Januar 2009 11:00
> To: dev_at_jersey.dev.java.net
> Subject: Re: [Jersey] WebDAV "Depth" header and enum <was> Re:
> Developer role
>
>
> On Jan 10, 2009, at 3:36 PM, Markus KARG wrote:
>
>
> Paul,
>
> thank you for your comments.
>
> I wonder how to code an enum that has a value of "0"? Any idea?
>
>
> Ah, i remember now, enum already supports this but the string
> parameter:
> "must match exactly an identifier used to declare an enum
> constant in this type."
>
> which is, unfortunately, not what you want. The only other way i can
> think of is to create a wrapper class that takes a string
> constructor and from a method on the class the enum can be obtained.
>
>
>
> For your last sentence, I just did not understand what you like to
> tell me. Can you rephrase that?
>
>
> I was wondering if you could combine a request entity with WebDAV
> headers. Since my knowledge of WebDAV is limited the following might
> not be suitable: for example:
>
> @PROPFIND
> public .. . put(PropFind find) {
> }
>
> the class PropFind encapsulates the request entity (if any) and
> relevant WebDAV headers. The message body reader for the PropFind
> would be responsible for reading the request entity and processing
> the WebDAV headers. The above approach, if possible, might be easier
> for the end user.
>
> Paul.
>
>
> Thanks
> Markus
>
>
>
> From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
> Sent: Freitag, 9. Januar 2009 14:53
> To: Markus KARG
> Cc: dev_at_jersey.dev.java.net
> Subject: [Jersey] WebDAV "Depth" header and enum <was> Re: Developer
> role
>
>
> On Dec 30, 2008, at 7:13 PM, Markus KARG wrote:
> 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.
>
>
>
>
> Like:
>
> @PROPFIND
> public MultiStatus propfind(@HeaderParam final DepthEnum depth)
>
> @HeaderParam("Depth")
>
>
>
>
>
> Will Jersey be able to parse the header value "0" to inject
> Depth.ZERO here?
>
> If "0" is the value of the enum constant then i think yes.
>
>
>
>
>
> If possible, then I will overhaul the code once more before
> committing it, since it is so much easier to work with enums. :-)
>
> Is Depth associated with all forms of WebDAV method or with
> particular methods.
>
> The reason i ask is that you might be able to combine the request
> entity with headers without your own special type and message body
> reader (as they are also capable of getting request header
> information).
>
> Paul.
>
>
>
>
>
>
>
>
>
>
>
>
>
>