Hi all, Based on Lars's StructureBuilder and Yuri's fluent Configurator, I've started thinking about a solution that would take the best of both approaches. The goal is to provide an optional package in NRE ("com.noelios.restlet.ext.builder") implementing the fluent design pattern. I also want to take advantage of Java's strong typing and IDEs code completion as much as possible. This will imply having a tree of specialized builders. As a result, the code of tutorial 11 will look like this :-)
// Build and start the container new RestletContainerBuilder("My container") .addServer(Protocols.HTTP, "My server", 8182) .attachLog("com.noelios.restlet.example") .attachStatus(true, "[EMAIL PROTECTED]", "http://www.mysite.org") .attachHost(8182) .attachGuard("/docs/", "com.noelios.restlet.example", true, ChallengeSchemes.HTTP_BASIC , "Restlet tutorial", true) .authorize("scott", "tiger") .attachDirectory("D:/Restlet/www/docs/api/", true, "index") .addExtension("html", MediaTypes.TEXT_HTML) .addExtension("css", MediaTypes.TEXT_CSS) .addExtension("gif", MediaTypes.IMAGE_GIF) .up() .up().toMaplet(). .attachMaplet("/users") .attachMaplet("/[a-z]+") .attachRestlet("$", userRestlet) .up().toMaplet() .attachRestlet("/orders$", ordersRestlet) .root().toComponent().start(); The attach*() methods will move the focus to the attached/created node. Other methods will keep the focus on the current node. The up() and root() will change the focus in the tree of builder nodes. The to*() methods will allow the cast the builder to the best type (maybe upMaplet() and rootComponent() are even better?). Any thought? Thanks, Jerome > -----Message d'origine----- > De : news [mailto:[EMAIL PROTECTED] De la part de Yuri de Wit > Envoyé : mercredi 17 mai 2006 19:50 > À : discuss@restlet.tigris.org > Objet : Re: Fluent API and StructureBuilder > > > Interesting... > > The approach I was taking was to use Java itself as the stack > by using a > "new XXX()" to create/"push" a new entry to the "stack". > .attach("/a", new Maplet() > .attach("/b", new Maplet()) > .attach("/c", > new Restlet() > ) > ) > ) > > To abstract the new Maplet() even further I was configuring > this inside > a Configurator class that had methods such as map(), resource() that > would hide the new Maplet(), new resource() instantiation, > etc cleaning up > the code a bit more: > new Configurator(container){ > public Restlet build(){ > map() > .attach("/a", > new MyChainlet() > .map() > .attach("/b", > > resource().handle("GET", redirect("/WEB-INF/...")) > .attach("/c", > redirect("/home")))) > } > }.build(); > > > Each ")" above would correspond to the .back(1) in Lars solution, I > guess. The generic back(?) seems more flexible and I would > interested in > knowing what kind of scenarios does it enable. > Thanks, > > -- yuri > > Lars Heuer <[EMAIL PROTECTED]> wrote: > >Hi all, > > > >[...] > >> I think this may be a better way to support your fluent > design pattern. We > >> could > >> implement more complex things like multiple extractions, > etcs. Let me think > >> more > >> about this. > >[...] > > > >To explain a bit further: The StrutureBuilder holds an internal stack > >of Restlets and pushes always the last attached Restlet to the top of > >the stack. Exceptions are: addServer, addClient, attach(String, > >Class). > >Once I am finished with one path in my tree, I can call > back() to jump > >to the parent leaf or back(int) to jump to any higher level of the > >tree. > >Once the user has made a jump back to a higher level it is not > >possible to go to a lower level (because I never needed it, but it is > >trivial to implement). > > > >I can attach the code to the issue. Tomorrow. > > > >Best regards, > >Lars > >-- > >http://semagia.com > > > > > > > > -- > > >