提交 8cbdec9e 编写于 作者: Y yoshimoto

Apply Activiti code style

上级 8467fd17
/* Licensed under the Apache License, Version 2.0 (the "License"); /* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...@@ -28,89 +28,103 @@ import org.activiti.engine.impl.persistence.entity.VariableInstance; ...@@ -28,89 +28,103 @@ import org.activiti.engine.impl.persistence.entity.VariableInstance;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
/** /**
* Implementation of an {@link ELResolver} that resolves expressions with the process variables of a given {@link VariableScope} as context. <br> * Implementation of an {@link ELResolver} that resolves expressions with the
* Also exposes the currently logged in username to be used in expressions (if any) * process variables of a given {@link VariableScope} as context. <br>
* Also exposes the currently logged in username to be used in expressions (if
* any)
*
*
* *
*/ */
public class VariableScopeElResolver extends ELResolver { public class VariableScopeElResolver extends ELResolver {
public static final String EXECUTION_KEY = "execution"; public static final String EXECUTION_KEY = "execution";
public static final String TASK_KEY = "task"; public static final String TASK_KEY = "task";
public static final String LOGGED_IN_USER_KEY = "authenticatedUserId"; public static final String LOGGED_IN_USER_KEY = "authenticatedUserId";
protected VariableScope variableScope; protected VariableScope variableScope;
public VariableScopeElResolver(VariableScope variableScope) { public VariableScopeElResolver(VariableScope variableScope) {
this.variableScope = variableScope; this.variableScope = variableScope;
} }
public Object getValue(ELContext context, Object base, Object property) { @Override
public Object getValue(ELContext context, Object base, Object property) {
if (base == null) {
String variable = (String) property; // according to javadoc, can only be a String if (base == null) {
String variable = (String) property; // according to javadoc, can
if ((EXECUTION_KEY.equals(property) && variableScope instanceof ExecutionEntity) || (TASK_KEY.equals(property) && variableScope instanceof TaskEntity)) { // only be a String
context.setPropertyResolved(true);
return variableScope; if ((EXECUTION_KEY.equals(property) && variableScope instanceof ExecutionEntity)
} else if (EXECUTION_KEY.equals(property) && variableScope instanceof TaskEntity) { || (TASK_KEY.equals(property) && variableScope instanceof TaskEntity)) {
context.setPropertyResolved(true); context.setPropertyResolved(true);
return ((TaskEntity) variableScope).getExecution(); return variableScope;
} else if (LOGGED_IN_USER_KEY.equals(property)) { } else if (EXECUTION_KEY.equals(property) && variableScope instanceof TaskEntity) {
context.setPropertyResolved(true); context.setPropertyResolved(true);
return Authentication.getAuthenticatedUserId(); return ((TaskEntity) variableScope).getExecution();
} else { } else if (LOGGED_IN_USER_KEY.equals(property)) {
if (variableScope.hasVariable(variable)) { context.setPropertyResolved(true);
context.setPropertyResolved(true); // if not set, the next elResolver in the CompositeElResolver will be called return Authentication.getAuthenticatedUserId();
VariableInstance variableInstance = variableScope.getVariableInstance(variable); } else {
Object value = variableInstance.getValue(); if (variableScope.hasVariable(variable)) {
if ( ("json".equals(variableInstance.getTypeName()) || "longJson".equals(variableInstance.getTypeName())) && (value instanceof JsonNode) && ((JsonNode)value).isArray() ) { context.setPropertyResolved(true); // if not set, the next
return Context.getProcessEngineConfiguration().getObjectMapper().convertValue(value, List.class); // elResolver in the
} else { // CompositeElResolver
return value; // will be called
} VariableInstance variableInstance = variableScope.getVariableInstance(variable);
} Object value = variableInstance.getValue();
} if (("json".equals(variableInstance.getTypeName())
} || "longJson".equals(variableInstance.getTypeName())) && (value instanceof JsonNode)
&& ((JsonNode) value).isArray()) {
// property resolution (eg. bean.value) will be done by the return Context.getProcessEngineConfiguration().getObjectMapper().convertValue(value,
// BeanElResolver (part of the CompositeElResolver) List.class);
// It will use the bean resolved in this resolver as base. } else {
return value;
return null; }
} }
}
public boolean isReadOnly(ELContext context, Object base, Object property) { }
if (base == null) {
String variable = (String) property; // property resolution (eg. bean.value) will be done by the
return !variableScope.hasVariable(variable); // BeanElResolver (part of the CompositeElResolver)
} // It will use the bean resolved in this resolver as base.
return true;
} return null;
}
public void setValue(ELContext context, Object base, Object property, Object value) {
if (base == null) { @Override
String variable = (String) property; public boolean isReadOnly(ELContext context, Object base, Object property) {
if (variableScope.hasVariable(variable)) { if (base == null) {
variableScope.setVariable(variable, value); String variable = (String) property;
} return !variableScope.hasVariable(variable);
} }
} return true;
}
public Class<?> getCommonPropertyType(ELContext arg0, Object arg1) {
return Object.class; @Override
} public void setValue(ELContext context, Object base, Object property, Object value) {
if (base == null) {
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext arg0, Object arg1) { String variable = (String) property;
return null; if (variableScope.hasVariable(variable)) {
} variableScope.setVariable(variable, value);
}
public Class<?> getType(ELContext arg0, Object arg1, Object arg2) { }
return Object.class; }
}
@Override
public Class<?> getCommonPropertyType(ELContext arg0, Object arg1) {
return Object.class;
}
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext arg0, Object arg1) {
return null;
}
@Override
public Class<?> getType(ELContext arg0, Object arg1, Object arg2) {
return Object.class;
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册