Hi Yuri,

Sure this can be done, the default constructor will be in beta 13 released
tomorrow. 

In addition, I'm also think that it would be nice to be able to just do:
attachOrders("/orders$") in your case. To be able to do this, we would need
to provide a FactoryBuilder that could be subclassed to instantiate the
customized builders (a subclass of MapletBuilder in your case)... Would that
interest you?

Thanks,
Jerome

> -----Message d'origine-----
> De : news [mailto:[EMAIL PROTECTED] De la part de Yuri de Wit
> Envoyé : mercredi 24 mai 2006 23:52
> À : discuss@restlet.tigris.org
> Objet : Re: RE: Fluent API and StructureBuilder
> 
> 
> Hi Jerome, 
> 
> It is not a big deal, as I mentioned before, and the latest solution
> does the job nicely. Having special builders to do the 
> configuration job is
> much less invasive than requiring a return this on most
> getters/setters. 
> One point re: RestletContainerBuilder. Since it is quite 
> common to have
> user-defined Restlets added while building the structure, it would be
> great if the instantiation of these restlets could be abstracted in a
> user-defined Builder method. So instead of .attach("/order", new
> OrderRestlet(param1)) one could do .attach("/order", 
> order()). This is already
> possible with the current design by subclassing, but ideally I would,
> instead of creating a subclass, want to use anonymous classes 
> to the same, but
> more fluent, effect. Something along these lines:
>         new RestletContainerBuilder(){
> 
>               RestletContainer build() throws Exception{
> 
>                       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", true)                               
> .addExtension("html",
> MediaTypes.TEXT_HTML)                               
> .addExtension("css", MediaTypes.TEXT_CSS)
>                                .addExtension("gif",
> MediaTypes.IMAGE_GIF)                               .up(2).toMaplet()
>                          .attachMaplet("/users")
>                             .attachMaplet("/[a-z]+")
>                                .attach("$", orders())
>                                   .up().toMaplet()
>                                .attach("/orders$", orders())
>                                   .owner();           
>               }
> 
>               Restlet orders(){
>                       return new MyOrdersRestlet(param1, param2, etc);
>               }
> 
>         }.build().start();
> 
> This way I can offload the new XXX() to a method added to the 
> anonymous
> class and use that method right in there. The only thing that seems to
> preclude me from doing so is the fact that 
> RestletContainerBuilder does
> not have a default constructor. Is that something that could be
> supported?
> thanks,
> 
> -- yuri
> 
> "Jerome Louvel" <[EMAIL PROTECTED]> wrote:
> >
> >Hi all,
> >
> >In beta 12 there is now support for fluent builders. Thanks 
> Yuri and =
> >Lars
> >for the cool ideas, it definitely makes Restlet usage easier, see
> >http://www.restlet.org/tutorial#part12 for details.
> >
> >Also, I've decided not to return "this" anymore from the attach() =
> >methods,
> >mainly for simplification purpose and because they are not 
> following the
> >classical Java API style. I prefer to orient people towards the new =
> >builders
> >instead. Yuri, I know you requested this initialy, but I 
> think that if =
> >the
> >build package satisfies your needs, you shouldn't need this return =
> >params
> >anymore. Let me know if I'm wrong.
> >
> >On the implementation side, you'll see that I didn't need to 
> manage a =
> >stack
> >manually as I'm relying on a tree of specialized builders 
> instead. Let =
> >me
> >know how we can improve this further. I know I need to provide a =
> >specialized
> >builder for HostMaplets in order to easily add allowed 
> domains, ports, =
> >etc.
> >
> >Best regards,
> >Jerome
> >
> >> -----Message d'origine-----
> >> De : news [mailto:[EMAIL PROTECTED] De la part de Yuri de Wit
> >> Envoy=E9 : jeudi 18 mai 2006 17:43
> >> =C0 : discuss@restlet.tigris.org
> >> Objet : Re: Fluent API and StructureBuilder
> >>=20
> >>=20
> >> One thing that I forgot to mention is that using new XXX() 
> as the new
> >> "stack" instead of up()/back() still allows you to=20
> >> comment/uncomment what
> >> you want and you get some auto indentation for free when=20
> >> using IDEs. :-)
> >> regards,=20
> >>=20
> >> -- yuri
> >>=20
> >> Yuri de Wit<[EMAIL PROTECTED]> wrote:
> >> >
> >> >Hi Lars,=20
> >> >
> >> >fair enough. The back() (or up() as proposed by Jerome) is=20
> >> indeed more
> >> >flexible (even though I am not sure how an IDE will auto=20
> >> format that -
> >> >minor detail) and I'll be happy to use it as soon as Jerome=20
> >> incorporate it
> >> >instead of what I have been using.
> >> >regards,=20
> >> >
> >> >-- yuri
> >> >
> >> >
> >> >Lars Heuer <[EMAIL PROTECTED]> wrote:
> >> >>Hi Yuri,
> >> >>
> >> >>> Interesting...
> >> >>
> >> >>> The approach I was taking was to use Java itself as the=20
> >> 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",=20
> >> >>>                         new Restlet()
> >> >>>                 )
> >> >>>         )
> >> >>> )
> >> >>
> >> >>Yep, I thought about the same approach but it has the 
> disadvantage
> >> >>that you cannot easily comment out a section and you have to keep
> >> >>track about the braces (or the IDE does it).
> >> >>I am very happy that I could do the following:
> >> >>
> >> >>  builder
> >> >>         .attach(SomeChainlet(....))
> >> >>           .attach(Someother)
> >> >>
> >> >>And if I don't need a chainlet or maplet I can easily 
> comment it out
> >> >>without breaking the flow.
> >> >>          =20
> >> >>  builder
> >> >>//         .attach(SomeChainlet(....))
> >> >>           .attach(Someother)
> >> >>
> >> >>
> >> >>          =20
> >> >>[...]
> >> >>> Each ")" above would correspond to the .back(1) in Lars=20
> >> solution, I
> >> >>> guess. The generic back(?) seems more flexible and I=20
> >> would interested in
> >> >>> knowing what kind of scenarios does it enable.
> >> >>
> >> >>I use it just to save some .back().back() chains if I've to=20
> >> jump to a
> >> >>higher level. It is build in because I am lazy. ;)
> >> >>
> >> >>Best regards,
> >> >>Lars
> >> >>--=20
> >> >>http://semagia.com
> >> >>
> >> >
> >> >
> >> >
> >> >--=20
> >> >
> >> >
> >> >
> >>=20
> >>=20
> >>=20
> >> --=20
> >>=20
> >>=20
> >
> 
> 
> 
> -- 
> 
> 

Reply via email to