Search in sources :

Example 1 with FunctionMapper

use of org.camunda.bpm.engine.impl.javax.el.FunctionMapper in project camunda-bpm-platform by camunda.

the class CustomExpressionManagerTest method testBuiltinFunctionMapperRegistration.

@Test
public void testBuiltinFunctionMapperRegistration() {
    // given a process engine configuration with a custom function mapper
    ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration().setJdbcUrl("jdbc:h2:mem:camunda" + getClass().getSimpleName());
    CustomExpressionManager customExpressionManager = new CustomExpressionManager();
    Assert.assertTrue(customExpressionManager.getFunctionMappers().isEmpty());
    config.setExpressionManager(customExpressionManager);
    // when the engine is initialized
    engine = config.buildProcessEngine();
    // then two default function mappers should be registered
    Assert.assertSame(customExpressionManager, config.getExpressionManager());
    Assert.assertEquals(2, customExpressionManager.getFunctionMappers().size());
    boolean commandContextMapperFound = false;
    boolean dateTimeMapperFound = false;
    for (FunctionMapper functionMapper : customExpressionManager.getFunctionMappers()) {
        if (functionMapper instanceof CommandContextFunctionMapper) {
            commandContextMapperFound = true;
        }
        if (functionMapper instanceof DateTimeFunctionMapper) {
            dateTimeMapperFound = true;
        }
    }
    Assert.assertTrue(commandContextMapperFound && dateTimeMapperFound);
}
Also used : DateTimeFunctionMapper(org.camunda.bpm.engine.impl.el.DateTimeFunctionMapper) CommandContextFunctionMapper(org.camunda.bpm.engine.impl.el.CommandContextFunctionMapper) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) CommandContextFunctionMapper(org.camunda.bpm.engine.impl.el.CommandContextFunctionMapper) FunctionMapper(org.camunda.bpm.engine.impl.javax.el.FunctionMapper) DateTimeFunctionMapper(org.camunda.bpm.engine.impl.el.DateTimeFunctionMapper) Test(org.junit.Test)

Example 2 with FunctionMapper

use of org.camunda.bpm.engine.impl.javax.el.FunctionMapper in project camunda-bpm-platform by camunda.

the class JuelScriptEngine method createElContext.

private ELContext createElContext(final ScriptContext scriptCtx) {
    // Check if the ELContext is already stored on the ScriptContext
    Object existingELCtx = scriptCtx.getAttribute("elcontext");
    if (existingELCtx instanceof ELContext) {
        return (ELContext) existingELCtx;
    }
    scriptCtx.setAttribute("context", scriptCtx, ScriptContext.ENGINE_SCOPE);
    // Built-in function are added to ScriptCtx
    scriptCtx.setAttribute("out:print", getPrintMethod(), ScriptContext.ENGINE_SCOPE);
    SecurityManager securityManager = System.getSecurityManager();
    if (securityManager == null) {
        scriptCtx.setAttribute("lang:import", getImportMethod(), ScriptContext.ENGINE_SCOPE);
    }
    ELContext elContext = new ELContext() {

        ELResolver resolver = createElResolver();

        VariableMapper varMapper = new ScriptContextVariableMapper(scriptCtx);

        FunctionMapper funcMapper = new ScriptContextFunctionMapper(scriptCtx);

        @Override
        public ELResolver getELResolver() {
            return resolver;
        }

        @Override
        public VariableMapper getVariableMapper() {
            return varMapper;
        }

        @Override
        public FunctionMapper getFunctionMapper() {
            return funcMapper;
        }
    };
    // Store the elcontext in the scriptContext to be able to reuse
    scriptCtx.setAttribute("elcontext", elContext, ScriptContext.ENGINE_SCOPE);
    return elContext;
}
Also used : ELContext(org.camunda.bpm.engine.impl.javax.el.ELContext) BeanELResolver(org.camunda.bpm.engine.impl.javax.el.BeanELResolver) ResourceBundleELResolver(org.camunda.bpm.engine.impl.javax.el.ResourceBundleELResolver) ListELResolver(org.camunda.bpm.engine.impl.javax.el.ListELResolver) CompositeELResolver(org.camunda.bpm.engine.impl.javax.el.CompositeELResolver) ELResolver(org.camunda.bpm.engine.impl.javax.el.ELResolver) ArrayELResolver(org.camunda.bpm.engine.impl.javax.el.ArrayELResolver) MapELResolver(org.camunda.bpm.engine.impl.javax.el.MapELResolver) VariableMapper(org.camunda.bpm.engine.impl.javax.el.VariableMapper) FunctionMapper(org.camunda.bpm.engine.impl.javax.el.FunctionMapper)

Aggregations

FunctionMapper (org.camunda.bpm.engine.impl.javax.el.FunctionMapper)2 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)1 CommandContextFunctionMapper (org.camunda.bpm.engine.impl.el.CommandContextFunctionMapper)1 DateTimeFunctionMapper (org.camunda.bpm.engine.impl.el.DateTimeFunctionMapper)1 ArrayELResolver (org.camunda.bpm.engine.impl.javax.el.ArrayELResolver)1 BeanELResolver (org.camunda.bpm.engine.impl.javax.el.BeanELResolver)1 CompositeELResolver (org.camunda.bpm.engine.impl.javax.el.CompositeELResolver)1 ELContext (org.camunda.bpm.engine.impl.javax.el.ELContext)1 ELResolver (org.camunda.bpm.engine.impl.javax.el.ELResolver)1 ListELResolver (org.camunda.bpm.engine.impl.javax.el.ListELResolver)1 MapELResolver (org.camunda.bpm.engine.impl.javax.el.MapELResolver)1 ResourceBundleELResolver (org.camunda.bpm.engine.impl.javax.el.ResourceBundleELResolver)1 VariableMapper (org.camunda.bpm.engine.impl.javax.el.VariableMapper)1 Test (org.junit.Test)1