Gert Vanthienen's blog

Friday, April 25, 2008

Unwrapping the wrapper

When we started development on the Scala DSL for Camel, we were using implicit conversion to convert a Java DSL type into a Scala DSL type like this:

implicit def enrichChoice(choice: ChoiceType) = new RichChoiceType(choice)

However, when we try to create a nice-looking DSL this way, we run into problems with the explicits-first rule for implicit conversion in Scala sometimes: methods on the original Java DSL type would take precedence over the 'new' Scala DSL methods.

We actually wanted the behavior to be the other way around: prefer the Scala DSL methods and only fail back to the Java DSL when necessary. Just to whet your appetite for Scala, all it takes to implement this is a simple trait...

trait Wrapper[T] {
val unwrap : T
... implemented on our Scala DSL types ...

class RichChoiceType(val unwrap: ChoiceType) with Wrapper[ChoiceType]

... and one equally simple implicit conversion method.

implicit def unwrap[T](wrapper: Wrapper[T]) = wrapper.unwrap

Labels: , ,

Saturday, April 12, 2008

Scala DSL for Camel

I attended ApacheCon Europe this week in Amsterdam. Finally got a chance to meet Guillaume Nodet after chatting with him for hours on IRC and Bruce Snyder was there as well, so I guess the the ServiceMix team was duly represented.

Personally, I was particularly interested in the talks on JCR, Jackrabbit and Sling. I was planning to build a message archiving and monitoring solution for ServiceMix and the talks have convinced me to go for it.

Also took this opportunity to give a 15 minute Fast Feather talk on the new Scala DSL in Camel. The slides are available here.

Labels: , , ,