All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.activiti.engine.impl.el.ExpressionManager Maven / Gradle / Ivy

The newest version!
/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.activiti.engine.impl.el;

import java.util.HashMap;
import java.util.Map;

import javax.el.ArrayELResolver;
import javax.el.BeanELResolver;
import javax.el.CompositeELResolver;
import javax.el.ELContext;
import javax.el.ELResolver;
import javax.el.ExpressionFactory;
import javax.el.ListELResolver;
import javax.el.MapELResolver;
import javax.el.ValueExpression;

import de.odysseus.el.ExpressionFactoryImpl;
import org.activiti.engine.delegate.Expression;
import org.activiti.engine.delegate.VariableScope;
import org.activiti.engine.impl.bpmn.data.ItemInstance;
import org.activiti.engine.impl.persistence.entity.VariableScopeImpl;

/**
 * 

* Central manager for all expressions. *

*

* Process parsers will use this to build expression objects that are stored in the process definitions. *

*

* Then also this class is used as an entry point for runtime evaluation of the expressions. *

*/ public class ExpressionManager { protected ExpressionFactory expressionFactory; // Default implementation (does nothing) protected ELContext parsingElContext = new ParsingElContext(); protected Map beans; public ExpressionManager() { this(null); } public ExpressionManager(boolean initFactory) { this(null, initFactory); } public ExpressionManager(Map beans) { this(beans, true); } public ExpressionManager(Map beans, boolean initFactory) { // Use the ExpressionFactoryImpl in activiti build in version of juel, // with parametrised method expressions enabled if (initFactory) { expressionFactory = new ExpressionFactoryImpl(); } this.beans = beans; } public Expression createExpression(String expression) { ValueExpression valueExpression = expressionFactory.createValueExpression(parsingElContext, expression.trim(), Object.class); return new JuelExpression(valueExpression, expression); } public void setExpressionFactory(ExpressionFactory expressionFactory) { this.expressionFactory = expressionFactory; } public ELContext getElContext(VariableScope variableScope) { ELContext elContext = null; if (variableScope instanceof VariableScopeImpl) { VariableScopeImpl variableScopeImpl = (VariableScopeImpl) variableScope; elContext = variableScopeImpl.getCachedElContext(); } if (elContext == null) { elContext = createElContext(variableScope); if (variableScope instanceof VariableScopeImpl) { ((VariableScopeImpl) variableScope).setCachedElContext(elContext); } } return elContext; } protected ActivitiElContext createElContext(VariableScope variableScope) { ELResolver elResolver = createElResolver(variableScope); return new ActivitiElContext(elResolver); } protected ELResolver createElResolver(VariableScope variableScope) { CompositeELResolver elResolver = new CompositeELResolver(); elResolver.add(new VariableScopeElResolver(variableScope)); if (beans != null) { // ACT-1102: Also expose all beans in configuration when using // standalone activiti, not // in spring-context elResolver.add(new ReadOnlyMapELResolver(beans)); } addBaseResolvers(elResolver); return elResolver; } private void addBaseResolvers(CompositeELResolver elResolver) { elResolver.add(new ArrayELResolver()); elResolver.add(new ListELResolver()); elResolver.add(new MapELResolver()); elResolver.add(new JsonNodeELResolver()); elResolver.add(new DynamicBeanPropertyELResolver(ItemInstance.class, "getFieldValue", "setFieldValue")); // TODO: needs verification elResolver.add(new BeanELResolver()); } public Map getBeans() { return beans; } public void setBeans(Map beans) { this.beans = beans; } public ELContext getElContext(Map availableVariables) { CompositeELResolver elResolver = new CompositeELResolver(); elResolver.add(new ReadOnlyMapELResolver(new HashMap<>(availableVariables))); addBaseResolvers(elResolver); return new ActivitiElContext(elResolver); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy