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

Apply Activiti code style

上级 8467fd17
...@@ -47,16 +47,18 @@ public class JsonNodeELResolver extends ELResolver { ...@@ -47,16 +47,18 @@ public class JsonNodeELResolver extends ELResolver {
} }
/** /**
* Creates a new BeanELResolver whose read-only status is determined by the given parameter. * Creates a new BeanELResolver whose read-only status is determined by the
* given parameter.
*/ */
public JsonNodeELResolver(boolean readOnly) { public JsonNodeELResolver(boolean readOnly) {
this.readOnly = readOnly; this.readOnly = readOnly;
} }
/** /**
* If the base object is not null, returns the most general type that this resolver accepts for * If the base object is not null, returns the most general type that this
* the property argument. Otherwise, returns null. Assuming the base is not null, this method * resolver accepts for the property argument. Otherwise, returns null.
* will always return Object.class. This is because any object is accepted as a key and is * Assuming the base is not null, this method will always return
* Object.class. This is because any object is accepted as a key and is
* coerced into a string. * coerced into a string.
* *
* @param context * @param context
...@@ -71,13 +73,15 @@ public class JsonNodeELResolver extends ELResolver { ...@@ -71,13 +73,15 @@ public class JsonNodeELResolver extends ELResolver {
} }
/** /**
* If the base object is not null, returns an Iterator containing the set of JavaBeans * If the base object is not null, returns an Iterator containing the set of
* properties available on the given object. Otherwise, returns null. The Iterator returned must * JavaBeans properties available on the given object. Otherwise, returns
* contain zero or more instances of java.beans.FeatureDescriptor. Each info object contains * null. The Iterator returned must contain zero or more instances of
* information about a property in the bean, as obtained by calling the * java.beans.FeatureDescriptor. Each info object contains information about
* BeanInfo.getPropertyDescriptors method. The FeatureDescriptor is initialized using the same * a property in the bean, as obtained by calling the
* fields as are present in the PropertyDescriptor, with the additional required named * BeanInfo.getPropertyDescriptors method. The FeatureDescriptor is
* attributes "type" and "resolvableAtDesignTime" set as follows: * initialized using the same fields as are present in the
* PropertyDescriptor, with the additional required named attributes "type"
* and "resolvableAtDesignTime" set as follows:
* <ul> * <ul>
* <li>{@link ELResolver#TYPE} - The runtime type of the property, from * <li>{@link ELResolver#TYPE} - The runtime type of the property, from
* PropertyDescriptor.getPropertyType().</li> * PropertyDescriptor.getPropertyType().</li>
...@@ -88,8 +92,9 @@ public class JsonNodeELResolver extends ELResolver { ...@@ -88,8 +92,9 @@ public class JsonNodeELResolver extends ELResolver {
* The context of this evaluation. * The context of this evaluation.
* @param base * @param base
* The bean to analyze. * The bean to analyze.
* @return An Iterator containing zero or more FeatureDescriptor objects, each representing a * @return An Iterator containing zero or more FeatureDescriptor objects,
* property on this bean, or null if the base object is null. * each representing a property on this bean, or null if the base
* object is null.
*/ */
@Override @Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) { public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
...@@ -97,9 +102,12 @@ public class JsonNodeELResolver extends ELResolver { ...@@ -97,9 +102,12 @@ public class JsonNodeELResolver extends ELResolver {
JsonNode node = (JsonNode) base; JsonNode node = (JsonNode) base;
final Iterator<String> keys = node.fieldNames(); final Iterator<String> keys = node.fieldNames();
return new Iterator<FeatureDescriptor>() { return new Iterator<FeatureDescriptor>() {
@Override
public boolean hasNext() { public boolean hasNext() {
return keys.hasNext(); return keys.hasNext();
} }
@Override
public FeatureDescriptor next() { public FeatureDescriptor next() {
Object key = keys.next(); Object key = keys.next();
FeatureDescriptor feature = new FeatureDescriptor(); FeatureDescriptor feature = new FeatureDescriptor();
...@@ -114,6 +122,8 @@ public class JsonNodeELResolver extends ELResolver { ...@@ -114,6 +122,8 @@ public class JsonNodeELResolver extends ELResolver {
return feature; return feature;
} }
@Override
public void remove() { public void remove() {
throw new UnsupportedOperationException("cannot remove"); throw new UnsupportedOperationException("cannot remove");
} }
...@@ -123,27 +133,30 @@ public class JsonNodeELResolver extends ELResolver { ...@@ -123,27 +133,30 @@ public class JsonNodeELResolver extends ELResolver {
} }
/** /**
* If the base object is a map, returns the most general acceptable type for a value in this * If the base object is a map, returns the most general acceptable type for
* map. If the base is a Map, the propertyResolved property of the ELContext object must be set * a value in this map. If the base is a Map, the propertyResolved property
* to true by this resolver, before returning. If this property is not true after this method is * of the ELContext object must be set to true by this resolver, before
* called, the caller should ignore the return value. Assuming the base is a Map, this method * returning. If this property is not true after this method is called, the
* will always return Object.class. This is because Maps accept any object as the value for a * caller should ignore the return value. Assuming the base is a Map, this
* given key. * method will always return Object.class. This is because Maps accept any
* object as the value for a given key.
* *
* @param context * @param context
* The context of this evaluation. * The context of this evaluation.
* @param base * @param base
* The map to analyze. Only bases of type Map are handled by this resolver. * The map to analyze. Only bases of type Map are handled by this
* resolver.
* @param property * @param property
* The key to return the acceptable type for. Ignored by this resolver. * The key to return the acceptable type for. Ignored by this
* @return If the propertyResolved property of ELContext was set to true, then the most general * resolver.
* acceptable type; otherwise undefined. * @return If the propertyResolved property of ELContext was set to true,
* then the most general acceptable type; otherwise undefined.
* @throws NullPointerException * @throws NullPointerException
* if context is null * if context is null
* @throws ELException * @throws ELException
* if an exception was thrown while performing the property or variable resolution. * if an exception was thrown while performing the property or
* The thrown exception must be included as the cause property of this exception, if * variable resolution. The thrown exception must be included as
* available. * the cause property of this exception, if available.
*/ */
@Override @Override
public Class<?> getType(ELContext context, Object base, Object property) { public Class<?> getType(ELContext context, Object base, Object property) {
...@@ -159,32 +172,38 @@ public class JsonNodeELResolver extends ELResolver { ...@@ -159,32 +172,38 @@ public class JsonNodeELResolver extends ELResolver {
} }
/** /**
* If the base object is a map, returns the value associated with the given key, as specified by * If the base object is a map, returns the value associated with the given
* the property argument. If the key was not found, null is returned. If the base is a Map, the * key, as specified by the property argument. If the key was not found,
* propertyResolved property of the ELContext object must be set to true by this resolver, * null is returned. If the base is a Map, the propertyResolved property of
* before returning. If this property is not true after this method is called, the caller should * the ELContext object must be set to true by this resolver, before
* ignore the return value. Just as in java.util.Map.get(Object), just because null is returned * returning. If this property is not true after this method is called, the
* doesn't mean there is no mapping for the key; it's also possible that the Map explicitly maps * caller should ignore the return value. Just as in
* the key to null. * java.util.Map.get(Object), just because null is returned doesn't mean
* there is no mapping for the key; it's also possible that the Map
* explicitly maps the key to null.
* *
* @param context * @param context
* The context of this evaluation. * The context of this evaluation.
* @param base * @param base
* The map to analyze. Only bases of type Map are handled by this resolver. * The map to analyze. Only bases of type Map are handled by this
* resolver.
* @param property * @param property
* The key to return the acceptable type for. Ignored by this resolver. * The key to return the acceptable type for. Ignored by this
* @return If the propertyResolved property of ELContext was set to true, then the value * resolver.
* associated with the given key or null if the key was not found. Otherwise, undefined. * @return If the propertyResolved property of ELContext was set to true,
* then the value associated with the given key or null if the key
* was not found. Otherwise, undefined.
* @throws ClassCastException * @throws ClassCastException
* if the key is of an inappropriate type for this map (optionally thrown by the * if the key is of an inappropriate type for this map
* underlying Map). * (optionally thrown by the underlying Map).
* @throws NullPointerException * @throws NullPointerException
* if context is null, or if the key is null and this map does not permit null keys * if context is null, or if the key is null and this map does
* (the latter is optionally thrown by the underlying Map). * not permit null keys (the latter is optionally thrown by the
* underlying Map).
* @throws ELException * @throws ELException
* if an exception was thrown while performing the property or variable resolution. * if an exception was thrown while performing the property or
* The thrown exception must be included as the cause property of this exception, if * variable resolution. The thrown exception must be included as
* available. * the cause property of this exception, if available.
*/ */
@Override @Override
public Object getValue(ELContext context, Object base, Object property) { public Object getValue(ELContext context, Object base, Object property) {
...@@ -209,7 +228,8 @@ public class JsonNodeELResolver extends ELResolver { ...@@ -209,7 +228,8 @@ public class JsonNodeELResolver extends ELResolver {
} else { } else {
if (resultNode.isArray()) { if (resultNode.isArray()) {
result = Context.getProcessEngineConfiguration().getObjectMapper().convertValue(resultNode, List.class); result = Context.getProcessEngineConfiguration().getObjectMapper().convertValue(resultNode,
List.class);
} else { } else {
result = resultNode; result = resultNode;
} }
...@@ -221,30 +241,36 @@ public class JsonNodeELResolver extends ELResolver { ...@@ -221,30 +241,36 @@ public class JsonNodeELResolver extends ELResolver {
/** /**
* If the base object is a map, returns whether a call to * If the base object is a map, returns whether a call to
* {@link #setValue(ELContext, Object, Object, Object)} will always fail. If the base is a Map, * {@link #setValue(ELContext, Object, Object, Object)} will always fail. If
* the propertyResolved property of the ELContext object must be set to true by this resolver, * the base is a Map, the propertyResolved property of the ELContext object
* before returning. If this property is not true after this method is called, the caller should * must be set to true by this resolver, before returning. If this property
* ignore the return value. If this resolver was constructed in read-only mode, this method will * is not true after this method is called, the caller should ignore the
* always return true. If a Map was created using java.util.Collections.unmodifiableMap(Map), * return value. If this resolver was constructed in read-only mode, this
* this method must return true. Unfortunately, there is no Collections API method to detect * method will always return true. If a Map was created using
* this. However, an implementation can create a prototype unmodifiable Map and query its * java.util.Collections.unmodifiableMap(Map), this method must return true.
* runtime type to see if it matches the runtime type of the base object as a workaround. * Unfortunately, there is no Collections API method to detect this.
* However, an implementation can create a prototype unmodifiable Map and
* query its runtime type to see if it matches the runtime type of the base
* object as a workaround.
* *
* @param context * @param context
* The context of this evaluation. * The context of this evaluation.
* @param base * @param base
* The map to analyze. Only bases of type Map are handled by this resolver. * The map to analyze. Only bases of type Map are handled by this
* resolver.
* @param property * @param property
* The key to return the acceptable type for. Ignored by this resolver. * The key to return the acceptable type for. Ignored by this
* @return If the propertyResolved property of ELContext was set to true, then true if calling * resolver.
* the setValue method will always fail or false if it is possible that such a call may * @return If the propertyResolved property of ELContext was set to true,
* succeed; otherwise undefined. * then true if calling the setValue method will always fail or
* false if it is possible that such a call may succeed; otherwise
* undefined.
* @throws NullPointerException * @throws NullPointerException
* if context is null. * if context is null.
* @throws ELException * @throws ELException
* if an exception was thrown while performing the property or variable resolution. * if an exception was thrown while performing the property or
* The thrown exception must be included as the cause property of this exception, if * variable resolution. The thrown exception must be included as
* available. * the cause property of this exception, if available.
*/ */
@Override @Override
public boolean isReadOnly(ELContext context, Object base, Object property) { public boolean isReadOnly(ELContext context, Object base, Object property) {
...@@ -258,40 +284,45 @@ public class JsonNodeELResolver extends ELResolver { ...@@ -258,40 +284,45 @@ public class JsonNodeELResolver extends ELResolver {
} }
/** /**
* If the base object is a map, attempts to set the value associated with the given key, as * If the base object is a map, attempts to set the value associated with
* specified by the property argument. If the base is a Map, the propertyResolved property of * the given key, as specified by the property argument. If the base is a
* the ELContext object must be set to true by this resolver, before returning. If this property * Map, the propertyResolved property of the ELContext object must be set to
* is not true after this method is called, the caller can safely assume no value was set. If * true by this resolver, before returning. If this property is not true
* this resolver was constructed in read-only mode, this method will always throw * after this method is called, the caller can safely assume no value was
* PropertyNotWritableException. If a Map was created using * set. If this resolver was constructed in read-only mode, this method will
* always throw PropertyNotWritableException. If a Map was created using
* java.util.Collections.unmodifiableMap(Map), this method must throw * java.util.Collections.unmodifiableMap(Map), this method must throw
* PropertyNotWritableException. Unfortunately, there is no Collections API method to detect * PropertyNotWritableException. Unfortunately, there is no Collections API
* this. However, an implementation can create a prototype unmodifiable Map and query its * method to detect this. However, an implementation can create a prototype
* runtime type to see if it matches the runtime type of the base object as a workaround. * unmodifiable Map and query its runtime type to see if it matches the
* runtime type of the base object as a workaround.
* *
* @param context * @param context
* The context of this evaluation. * The context of this evaluation.
* @param base * @param base
* The map to analyze. Only bases of type Map are handled by this resolver. * The map to analyze. Only bases of type Map are handled by this
* resolver.
* @param property * @param property
* The key to return the acceptable type for. Ignored by this resolver. * The key to return the acceptable type for. Ignored by this
* resolver.
* @param value * @param value
* The value to be associated with the specified key. * The value to be associated with the specified key.
* @throws ClassCastException * @throws ClassCastException
* if the class of the specified key or value prevents it from being stored in this * if the class of the specified key or value prevents it from
* map. * being stored in this map.
* @throws NullPointerException * @throws NullPointerException
* if context is null, or if this map does not permit null keys or values, and the * if context is null, or if this map does not permit null keys
* specified key or value is null. * or values, and the specified key or value is null.
* @throws IllegalArgumentException * @throws IllegalArgumentException
* if some aspect of this key or value prevents it from being stored in this map. * if some aspect of this key or value prevents it from being
* stored in this map.
* @throws PropertyNotWritableException * @throws PropertyNotWritableException
* if this resolver was constructed in read-only mode, or if the put operation is * if this resolver was constructed in read-only mode, or if the
* not supported by the underlying map. * put operation is not supported by the underlying map.
* @throws ELException * @throws ELException
* if an exception was thrown while performing the property or variable resolution. * if an exception was thrown while performing the property or
* The thrown exception must be included as the cause property of this exception, if * variable resolution. The thrown exception must be included as
* available. * the cause property of this exception, if available.
*/ */
@Override @Override
public void setValue(ELContext context, Object base, Object property, Object value) { public void setValue(ELContext context, Object base, Object property, Object value) {
...@@ -331,7 +362,8 @@ public class JsonNodeELResolver extends ELResolver { ...@@ -331,7 +362,8 @@ public class JsonNodeELResolver extends ELResolver {
* @param base * @param base
* The bean to analyze. * The bean to analyze.
* @param property * @param property
* The name of the property to analyze. Will be coerced to a String. * The name of the property to analyze. Will be coerced to a
* String.
* @return base != null * @return base != null
*/ */
private final boolean isResolvable(Object base) { private final boolean isResolvable(Object base) {
......
...@@ -28,14 +28,14 @@ import org.activiti.engine.impl.persistence.entity.VariableInstance; ...@@ -28,14 +28,14 @@ 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 {
...@@ -49,12 +49,15 @@ public class VariableScopeElResolver extends ELResolver { ...@@ -49,12 +49,15 @@ public class VariableScopeElResolver extends ELResolver {
this.variableScope = variableScope; this.variableScope = variableScope;
} }
@Override
public Object getValue(ELContext context, Object base, Object property) { public Object getValue(ELContext context, Object base, Object property) {
if (base == null) { if (base == null) {
String variable = (String) property; // according to javadoc, can only be a String String variable = (String) property; // according to javadoc, can
// only be a String
if ((EXECUTION_KEY.equals(property) && variableScope instanceof ExecutionEntity) || (TASK_KEY.equals(property) && variableScope instanceof TaskEntity)) { if ((EXECUTION_KEY.equals(property) && variableScope instanceof ExecutionEntity)
|| (TASK_KEY.equals(property) && variableScope instanceof TaskEntity)) {
context.setPropertyResolved(true); context.setPropertyResolved(true);
return variableScope; return variableScope;
} else if (EXECUTION_KEY.equals(property) && variableScope instanceof TaskEntity) { } else if (EXECUTION_KEY.equals(property) && variableScope instanceof TaskEntity) {
...@@ -65,11 +68,17 @@ public class VariableScopeElResolver extends ELResolver { ...@@ -65,11 +68,17 @@ public class VariableScopeElResolver extends ELResolver {
return Authentication.getAuthenticatedUserId(); return Authentication.getAuthenticatedUserId();
} else { } else {
if (variableScope.hasVariable(variable)) { if (variableScope.hasVariable(variable)) {
context.setPropertyResolved(true); // if not set, the next elResolver in the CompositeElResolver will be called context.setPropertyResolved(true); // if not set, the next
// elResolver in the
// CompositeElResolver
// will be called
VariableInstance variableInstance = variableScope.getVariableInstance(variable); VariableInstance variableInstance = variableScope.getVariableInstance(variable);
Object value = variableInstance.getValue(); Object value = variableInstance.getValue();
if ( ("json".equals(variableInstance.getTypeName()) || "longJson".equals(variableInstance.getTypeName())) && (value instanceof JsonNode) && ((JsonNode)value).isArray() ) { if (("json".equals(variableInstance.getTypeName())
return Context.getProcessEngineConfiguration().getObjectMapper().convertValue(value, List.class); || "longJson".equals(variableInstance.getTypeName())) && (value instanceof JsonNode)
&& ((JsonNode) value).isArray()) {
return Context.getProcessEngineConfiguration().getObjectMapper().convertValue(value,
List.class);
} else { } else {
return value; return value;
} }
...@@ -84,6 +93,7 @@ public class VariableScopeElResolver extends ELResolver { ...@@ -84,6 +93,7 @@ public class VariableScopeElResolver extends ELResolver {
return null; return null;
} }
@Override
public boolean isReadOnly(ELContext context, Object base, Object property) { public boolean isReadOnly(ELContext context, Object base, Object property) {
if (base == null) { if (base == null) {
String variable = (String) property; String variable = (String) property;
...@@ -92,6 +102,7 @@ public class VariableScopeElResolver extends ELResolver { ...@@ -92,6 +102,7 @@ public class VariableScopeElResolver extends ELResolver {
return true; return true;
} }
@Override
public void setValue(ELContext context, Object base, Object property, Object value) { public void setValue(ELContext context, Object base, Object property, Object value) {
if (base == null) { if (base == null) {
String variable = (String) property; String variable = (String) property;
...@@ -101,14 +112,17 @@ public class VariableScopeElResolver extends ELResolver { ...@@ -101,14 +112,17 @@ public class VariableScopeElResolver extends ELResolver {
} }
} }
@Override
public Class<?> getCommonPropertyType(ELContext arg0, Object arg1) { public Class<?> getCommonPropertyType(ELContext arg0, Object arg1) {
return Object.class; return Object.class;
} }
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext arg0, Object arg1) { public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext arg0, Object arg1) {
return null; return null;
} }
@Override
public Class<?> getType(ELContext arg0, Object arg1, Object arg2) { public Class<?> getType(ELContext arg0, Object arg1, Object arg2) {
return Object.class; return Object.class;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册