ActivitiUEL表达式是如何与Spring的容器整合起来的

更新时间:2023-07-04 14:47:26 阅读: 评论:0

ActivitiUEL表达式是如何与Spring的容器整合起来的
Activiti UEL 表达式
UEL表达式到底是什么呢?
UEL是java EE6规范的⼀部分,UEL(Unified Expression Language)即统⼀表达式语⾔,activiti⽀持两个UEL表达式:UEL-value和UEL-method
Activiti使⽤UEL进⾏表达式解析(有关详细信息,请参阅)
Activiti 如何使⽤UEL表达式获取Spring 容器中的bean?
答案在activiti-spring.jar中
SpringExpressionManager.java //spring表达式管理类
public class SpringExpressionManager extends ExpressionManager {
//应⽤上下⽂
protected ApplicationContext applicationContext;脸上肝斑
public SpringExpressionManager(ApplicationContext applicationContext, Map<Object, Object> beans) {
super(beans);//这个beans是流程引擎中的beans
this.applicationContext = applicationContext;
}
@Override
protected ELResolver createElResolver(VariableScope variableScope) {
//复合el表达式
CompositeELResolver compositeElResolver = new CompositeELResolver();
compositeElResolver.add(new VariableScopeElResolver(variableScope));
苹果手机充电器
//判断beans是否为空
if (beans != null) {
// 在表达式中只暴露流程引擎中的beans
compositeElResolver.add(new ReadOnlyMapELResolver(beans));
} el {
// 在表达式中暴露整个application-context
compositeElResolver.add(new ApplicationContextElResolver(applicationContext));
}
//添加数组解析器
compositeElResolver.add(new ArrayELResolver());
//添加集合解析器
compositeElResolver.add(new ListELResolver());
//添加map解析器
compositeElResolver.add(new MapELResolver());
//添加json格式的数据解析器 like {key:value,...} or [1,2,3,4,...]
compositeElResolver.add(new JsonNodeELResolver());
//添加bean解析器
compositeElResolver.add(new BeanELResolver());
return compositeElResolver;
}
在ProcessEngineConfigurationImpl.java中调⽤
public class ProcessEngineFactoryBean implements FactoryBean<ProcessEngine>, DisposableBean, ApplicationContextAware {
...
protected void configureExpressionManager() {
if (ExpressionManager() == null && applicationContext != null) {
processEngineConfiguration.tExpressionManager(new SpringExpressionManager(applicationContext, Beans()));
}
}
...
}
使⽤表达式
Activiti的Expression 接⼝
public interface Expression extends Serializable {
// variableScope 为变量作⽤域
和爸爸Object getValue(VariableScope variableScope);
void tValue(Object value, VariableScope variableScope);
String getExpressionText();
}
在代码中的具体使⽤
//获取表达式对象
//execution 为 VariableScope 的实现类⽤于从不同的变量作⽤域中取变量
Expression expression = ateExpression("${bean.id}");
businessKey = Value(execution).toString();
为什么有VariableScope
因为Activiti中有很多流程,每⼀个流程都有很多变量,使⽤变量的时候肯定不能去拿其他流程的变量,为了更好的管理在表达式中使⽤变
量,所以这⾥就有了⼀个变量作⽤域的概念
通过变量作⽤域获得EL上下⽂
public class ExpressionManager {
...
public ELContext getElContext(VariableScope variableScope) {
拇指猴>川崎玫瑰花怎么折ELContext elContext = null;
if (variableScope instanceof VariableScopeImpl) {
VariableScopeImpl variableScopeImpl = (VariableScopeImpl) variableScope;
elContext = CachedElContext();
}
if (elContext == null) {
//如果没有就创建⼀个EL上下⽂
elContext = createElContext(variableScope);
if (variableScope instanceof VariableScopeImpl) {
((VariableScopeImpl) variableScope).tCachedElContext(elContext);
}
}
return elContext;
}
...
}
VariableScope 的实现类
实现类就只要有三个类NoExecutionVariableScope.java
TaskEntityImpl.java
ExecutionEntityImpl.java
其中VariableScopeImpl 是个抽象类,这⾥使⽤了模板模式
需要⼦类实现的⽅法JUEL 实现类
protected  abstract  Collection<VariableInstanceEntity> loadVariableInstances ();
protected  abstract  VariableScopeImpl getParentVariableScope ();
protected  abstract  void  initializeVariableInstanceBackPointer (VariableInstanceEntity variableInstance);
protected  abstract  VariableInstanceEntity getSpecificVariable (String variableName);
public class JuelExpression implements Expression {
protected String expressionText;
protected ValueExpression valueExpression;
public JuelExpression(ValueExpression valueExpression, String expressionText) {
this.valueExpression = valueExpression;
}
public Object getValue(VariableScope variableScope) {
//获取值的时候都要通过variableScope获取上下⽂
ELContext elContext = ProcessEngineConfiguration().getExpressionManager().getElContext(variableScope); try {
ExpressionGetInvocation invocation = new ExpressionGetInvocation(valueExpression, elContext);
InvocationResult();
} catch (PropertyNotFoundException pnfe) {
throw new ActivitiException("Unknown property ud in expression: " + expressionText, pnfe);
} catch (MethodNotFoundException mnfe) {
throw new ActivitiException("Unknown method ud in expression: " + expressionText, mnfe);
} catch (ELException ele) {
throw new ActivitiException("Error while evaluating expression: " + expressionText, ele);
} catch (Exception e) {
throw new ActivitiException("Error while evaluating expression: " + expressionText, e);
}
}哈姆雷特人物性格分析
public void tValue(Object value, VariableScope variableScope) {
ELContext elContext = ProcessEngineConfiguration().getExpressionManager().getElContext(variableScope); try {
ExpressionSetInvocation invocation = new ExpressionSetInvocation(valueExpression, elContext, value);
} catch (Exception e) {
throw new ActivitiException("Error while evaluating expression: " + expressionText, e);
}
}
超级恋人第二季@Override
public String toString() {
if (valueExpression != null) {
ExpressionString();左手无名指长痣
}
String();
}
public String getExpressionText() {
return expressionText;
}
}

本文发布于:2023-07-04 14:47:26,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1067560.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:表达式   变量   解析器   添加   流程   获取
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图