I think that we urgently need a way to obtain the 'arguments' of a
'function' on a node, and perhaps a nicer way to define functions.

Currently, if you want to add functionality to nodes, and use it then you have to do
the following:

1. Make entry in executeFunction(node, string, list) of your MMObjectBuilder
   extension.

2. This function now can be called from the bridge with:
   node.getFunctionValue(string, list);

This nice and all, but what you obviously want, especially when trying to
map this to mmbase taglib is _named parameters_ (<mm:param name='..'
value='' /> and so on) , and more generally a way to check the parameters for
correctnes.

As a kick off to do something about this I implemented
org.mmbase.util.Arguments which in fact is a List implementation with
pre-defined entries, which can be filled by name. As long as you are in
java, that works, because you can simply request the right 'arguments'
constant when calling the function (even when otherwise using the bridge).

For example, in the image tag implementation we encounter now something
like:
 number = node.getFunctionValue("cache", new 
Arguments(Images.CACHE_ARGUMENTS).set("template", t)).toString();

You see, I don't want to know 'how-manieth' entry of the argumetn list the
'template' argument is, so I simply (mis)used the Image.CACHE_ARGUMENTS
contant for this.

But I feel that this kind of hackery cannot stay.  We need a consented about
way to do these things, and a way to do it entirely 'bridge only'

My first idea would be to add a function to NodeManager which creates an
'Arguments' List for you.

The line above would then become:
number = node.getFunctionValue("cache", 
node.getNodeManager().getFunctionArguments("cache").set("template", t)).toString();

which works the same as before (setting 'template' on the right place,
throwing exception if 'template' is unknown etc).

Besides this 'getFunctionArguments' member-funciton on NodeManager, also
'Arguments' or an interface which looks like it, must be defined in the
bridge.

The corresponding fucntion should then also be added to MMObjectBuilder.

The recipe for adding a function to your builder is then:

1. Make entry in executeFunction(node, string, list) of your MMObjectBuilder
   extension.

2. Make entry in getFunctionArguments(string) of your MMObjectBuilder
   extension. (for backwards compatibility, it would work without this, only
   'named arguments' and 'arguments checking' will not work then.)

3. This function now can be called from the bridge with:
   node.getFunctionValue(string, list);
   and the necessary list can be generated with:
   list = node.getNodeManager().getFunctionArguments(string)


To make it really nice, we could perhaps also make reflection based
generic implementations for (1) and (2). Perhaps the images 'cache' could
e.g. be implemented simply like this then:

int cacheFunction(String template, ServletRequest request);
And getFunctionArguments("cache") should then automagicly return a Arguments
with 2 entries, the first named 'tempalte' and the second 'request'.

I don't really know how to proceed with e.g. function-tags in mmbase-taglib
as long as I don't know how people feel like about this.

Michiel.

-- 
Michiel Meeuwissen 
Mediapark C101 Hilversum  
+31 (0)35 6772979
nl_NL, eo, en_US
mihxil'
[]()

Reply via email to