|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface MScriptFunction
Defines an Interface for custom MScript Functions.
Custom MScript functions can be developed my implementing this interface.
When MScriptResolver encounters a function, i.e. @repeat() which is not built in,
it first checks whether a function definition
exist in the configuration files. For Example:
<mscriptFunction name="repeat"> <class>mypack.RepeaterMScriptFunction</class> <repeat-seperator>,</repeat-seperator> </mscriptFunction>If it does, it loads the defined the class
mypack.RepeaterMScriptFunction.
If it does not then it assumes that the function name is a class name and tries to load it. It there is a success
the resolver calls the execute(Expression[] params, MScriptFunctionContext msfc)
method of the loaded class.
An Example Implementation
package mypack;
import org.moremotion.evaluator.*;
import org.moremotion.servlet.*;
public class RepeaterMScriptFunction implements MScriptFunction {
public Object execute(Expression[] params, MScriptFunctionContext msfc) throws MScriptFunctionException {
if (params.length < 2) throw new Exception("Less parameters than expected");
MMSymbolResolver sr = msfc.getSymbolResolver();
String seperator = msfc.getMScriptFunctionConfig().getParameter("repeat-seperator").stringValue(null);
String s = params[0].evaluate(sr).toString();
int times = ((Double)params[1].evaluate(sr)).intValue();
StringBuffer result = new StringBuffer();
for (int i = 0; i < times; i++) {
if (result.length() > 0) result.append(seperator);
result.append(s);
}
return result.toString();
}
}
| Field Summary | |
|---|---|
static java.lang.String |
NULL_FUNCTION_RESULT
|
| Method Summary | |
|---|---|
java.lang.Object |
execute(Expression[] params,
MScriptFunctionContext msfc)
Executes the algorithm of the custom MScript function and returns the result. |
| Field Detail |
|---|
static final java.lang.String NULL_FUNCTION_RESULT
| Method Detail |
|---|
java.lang.Object execute(Expression[] params,
MScriptFunctionContext msfc)
throws MScriptFunctionException
params - The function parameters as Expression object array.msfc - MScriptFunctionContext object
MScriptFunctionException - when something goes wrong with the execution of the function.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||