Re: UriBuilder Questions

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 31 Aug 2007 10:39:35 +0200

Dhanji R. Prasanna wrote:
> On 8/31/07, *Marc Hadley* <
> <>> wrote:
> (ii) UriBuilder state after a call to .build(...)
> Should the state be maintained after a call to build or should the
> builder be reset back to blank state ?
> Hmm, should it be idempotent on multiple invocations of build()? I like
> the idea that one can make some small changes and reuse the builder...

Me too. It can be more efficient, for example:

   UriBuilder ub = UriBuilder.fromUri(URI.create("http://host/"));
   URI u1 = ub.path("p1").build(); // "http://host/p1"
   URI u2 = ub.path("p2").build(); // "http://host/p1/p2"

rather than:

   URI u1 = UriBuilder.fromUri(URI.create("http://host/")).
   URI u2 = UriBuilder.fromUri(u1).path("p2").build();

> resets
> the state to blank to avoid a deep-copy of the builder contents to
> prevent subsequent modifications from affecting the returned
> Response.
> Instead I think it should just return an immutable response (private
> final fields).

The Response interface does not allow any direct modification of the
response state.

> I am not sure about entity references, if a user holds
> onto one and mutates it that is a risk that should be documented clearly
> (better to avoid deep copy as you say).

I guess we could say that the a Response instance can can only reliably
created and held for the scope of a request/response cycle. Beyond that
scope it's behavior is undefined and is application-specific whether it
can be reused or not.


| ? + ? = To question
    Paul Sandoz