Rob van Maris <[EMAIL PROTECTED]> wrote:
> > -----Original Message-----
> > From: [EMAIL PROTECTED] 
> > [mailto:[EMAIL PROTECTED] On Behalf Of Michiel Meeuwissen
> > 
> > As a second example of a Function we've implemented 
> > NodeFunction which will use reflection to find a 
> > java-constant in the MMObjectBuilder extension which should 
> > define the parameters of the functions of 'executeFunction' 
> > (if you check the current taglib use in 1.7 e.g. in the cloud 
> > context security editors, you see that as a temporary 
> > solution I simply specified this constant directly, which is 
> > very ugly).
> 
> Could you explain this part in more detail? As it stands I have no idea
> how the reflection part is supposed to work.

As it stands now in speeltuin it works like this:

Say we are looking for a function named 'gui' on a node of type 'images'.

So, you simply do on the FunctionFactory 
function = FunctionFactory.getFunction(imageNode, "gui");

And you get it back. You can now create some argumetns for this function:
Parameters params = function.getNewParameters();
params.set("language", "nl");
...
and execute the function
String result = (String) function.getFunctionValue(params);


But how is this implemented now? Perhaps the current idea is not very nice, but it 
works for the moment.

The 'gui' function needs to be implemented in MMObjectBuilder or in the
extension (Images in this case), so it is looking in this class (and its
superclasses for a constant of the type 'Parameter[]' of which the name
starts with GUI_). This constant serves as the definition for the function
arguments. It looks like this in MMObjectBuilder
 
public final static Parameter[] GUI_PARAMETERS = {
        new Parameter("field",    String.class),
        Parameter.LANGUAGE,
        new Parameter("session",  String.class),
        Parameter.RESPONSE,
        Parameter.REQUEST
    };

and in Images you could e.g. extend it:

public final static Parameter[] GUI_PARAMETERS = { 
        new Parameter.Wrapper(MMObjectBuilder.GUI_PARAMETERS),
        new Parameter("template", String.class)
    };

Having this constant, it knows what are the possible arguments for the gui
function, and you can fill them now by name, and it can give errors if you
try to set an unkown parameters or supply one of the wrong type.

It would perhaps be better to add a method in MMObjectBuilder
'getFunctionParameterDefinition("gui")' ('if (name.equals("gui")) return
GUI_PARAMETERS...) or so, because that would perhaps be better overridable.
Pierre pointed this out to me, and I tend to agree.

I would consider any other reasonable suggestion for this. 

For other function types (e.g. 'stand alone' functions) you can make up
completely different algoritms (e.g. with an XML specifying class and
method).

But the essence of the hack is, that I want the the mechanism I described 'getFunction
- function.getNewParameters, function.getFunctionValue)' to work, and that
the actual implemenation of 'getFunction' can vary.

 Michiel


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

Reply via email to