Search in sources :

Example 1 with ExpressionParameter

use of io.vertigo.commons.script.ExpressionParameter in project vertigo by KleeGroup.

the class JaninoExpressionEvaluatorPlugin method evaluate.

/**
 * {@inheritDoc}
 */
@Override
public <J> J evaluate(final String expression, final List<ExpressionParameter> parameters, final Class<J> type) {
    Assertion.checkNotNull(expression);
    Assertion.checkNotNull(parameters);
    Assertion.checkNotNull(type);
    // -----
    // 0. Init Janino parameters defined by their names, types and values.
    final int size = parameters.size();
    final String[] parameterNames = new String[size];
    final Class<?>[] parameterTypes = new Class[size];
    final Object[] parameterValues = new Object[size];
    int i = 0;
    for (final ExpressionParameter parameter : parameters) {
        parameterNames[i] = parameter.getName();
        parameterTypes[i] = parameter.getType();
        parameterValues[i] = parameter.getValue();
        i++;
    }
    // 1. Build the scriptEvaluator
    final IScriptEvaluator scriptEvaluator = buildEvaluator(expression, type, parameterNames, parameterTypes);
    // 2.Evaluate the script
    return type.cast(doEvaluate(scriptEvaluator, parameterValues));
}
Also used : IScriptEvaluator(org.codehaus.commons.compiler.IScriptEvaluator) ExpressionParameter(io.vertigo.commons.script.ExpressionParameter)

Example 2 with ExpressionParameter

use of io.vertigo.commons.script.ExpressionParameter in project vertigo by KleeGroup.

the class ScriptPreProcessor method createParameters.

private static List<ExpressionParameter> createParameters(final ScriptManager scriptManager, final Map<TaskAttribute, Object> inTaskAttributes) {
    Assertion.checkNotNull(scriptManager);
    Assertion.checkNotNull(inTaskAttributes);
    // -----
    final List<ExpressionParameter> tmpParameters = new ArrayList<>(inTaskAttributes.size());
    // ==========Initialisation des types et noms de paramètre==============
    ExpressionParameter scriptEvaluatorParameter;
    for (final Entry<TaskAttribute, Object> entry : inTaskAttributes.entrySet()) {
        final TaskAttribute taskAttribute = entry.getKey();
        final Class<?> clazz = taskAttribute.getDomain().getTargetJavaClass();
        scriptEvaluatorParameter = new ExpressionParameter(StringUtil.constToLowerCamelCase(taskAttribute.getName()), clazz, entry.getValue());
        tmpParameters.add(scriptEvaluatorParameter);
    }
    return tmpParameters;
}
Also used : TaskAttribute(io.vertigo.dynamo.task.metamodel.TaskAttribute) ArrayList(java.util.ArrayList) ExpressionParameter(io.vertigo.commons.script.ExpressionParameter)

Aggregations

ExpressionParameter (io.vertigo.commons.script.ExpressionParameter)2 TaskAttribute (io.vertigo.dynamo.task.metamodel.TaskAttribute)1 ArrayList (java.util.ArrayList)1 IScriptEvaluator (org.codehaus.commons.compiler.IScriptEvaluator)1