Hi,

In the new component-based architecture we are creating lots of  
specific apis that we need to make available to velocity. For example  
the rendering module should make available it's XDO object so that  
users can access any part of a document.
However there are some impedance mismatch.

For example in XDOM the method to find all blocks of a given type  
today is: XDOM.getChildrenByType(SectionBlock.class).

This cannot be called from velocity since SectionBlock.class will not  
work.

There are lots of other similar examples. One solution would be to  
modify the API to be for example: XDOM.getChildrenByType(String  
blockName) but this is ugly and type-unsafe.

So I was thinking about a different approach. What about intercepting  
method calls in our velocity module and instead of calling the method  
right away have some transformation to it. The idea would be for  
modules to register method handlers to our velocity runtime so that it  
can do the conversion.

For example when you'd call $xdom.getChildrenByType("section") it  
would call the XDOMVelocityMethodHandler.convert(...) method and  
transform "section" into SectionBlock.class and call the API method.

Thus the idea would be that modules that want to make their APIs more  
velocity friendly would just create components implementing some  
VelocityMethodHandler interface and automatically these would be used  
by our velocity runtime.

The only downside I can think of is javadoc or rather how users will  
know the method signature to use from velocity but I think we can find  
solutions for this. One solution for example is to use annotations on  
methods that need to have a velocity method hander. We'll need that  
anyway I think. Something like:

@velocityMethodHandler("rendering"')
XDOM.getChildrenByType(...)

(where "rendering" is the component role-hint)

WDYT?

Sergiu, since you're the one to have manipulated this part of  
Velocity, is this possible? (I think it is using uberspectors).

Thanks
-Vincent

PS: Since we don't want to make our code special for Velocity we  
should check how we would do it for other templating engine like  
FreeMarker for example.
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to