On 17 February 2011 08:48, Claus Ibsen <claus.ib...@gmail.com> wrote:
> Hi
>
> DSL in plain Java is somewhat limited how far you can go with Java and 
> Generics.
>
> A common issue over the times has been the Content Based Router where
> users would use other "complex patterns" inside the when/otherwise
> blocks.
> By complex patterns I mean patterns which have additional DSL for
> configuration. Or for example multicast or load balancer which re-uses
> the commons DSL's, but under the given mode (eg multicast or load
> balancing).
>
> To indicate when the pattern "ends" you would have to use .end() and
> the DSL would return back the scope to the previous pattern. But
> that's not possible, as the Java Generics Type System sucks for doing
> DSLs.
>
> I have been experimenting to see if there was a way to tell in the
> end, which "scope" to return back to. So in the Content Based Router
> example, you could indicate: Choice, eg
>
> .end(ChoiceDefinition.class)
>
> But that doesn't work.
> So the best solution I have found is as follows:
>
>
>                from("direct:start")
>                    .choice()
>                        .when(body().contains("Camel"))
>                            // we need to use endChoice to tell Java
> DSL to return scope back to the choice DSL
>
> .loadBalance().roundRobin().to("mock:foo").to("mock:bar").endChoice()
>                        .otherwise()
>                            .to("mock:result");
>
> If you don't have .endChoice() then the code above will not compile.
>
>
> By introducing a method named: endChoice, we can force the Java DSL to
> return back to the CBR scope.
>
> Since this problem mostly manifests itself with the Content Based
> Router, then I think this is the best we can do as far.
> However do you think endChoice is a good name? It may indicate it ends
> the entire CBR block?
>
> We could also name it
> - asChoice
> - endAsChoice
> - endAndBackToChoice
> - backToChoice
> - scopeAsChoice

Wonder if we could use when() / otherwise() as terminators (and
starting the new block?).

-- 
James
-------
FuseSource
Email: ja...@fusesource.com
Web: http://fusesource.com
Twitter: jstrachan
Blog: http://macstrac.blogspot.com/

Open Source Integration

Reply via email to