Loading src/main/java/com/inteligr8/activiti/mq/MqServiceTask.java +46 −10 Original line number Diff line number Diff line Loading @@ -70,26 +70,62 @@ public class MqServiceTask { @SuppressWarnings("unchecked") protected <T> T getFieldValueFromModel(String fieldName, Class<T> type, VariableScope varscope, boolean forceExpressionProcessing) { Object value = this.getFieldValueFromModel(fieldName, varscope, forceExpressionProcessing); if (value == null) { return null; } else if (String.class.isAssignableFrom(type)) { if (value instanceof String) { return (T) value; } else { return (T) value.toString(); } } else { try { Method method = type.getMethod("valueOf", value.getClass()); return (T) method.invoke(null, value); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { String strvalue; if (value instanceof String) { strvalue = (String) value; } else { strvalue = value.toString(); } try { Method method = type.getMethod("valueOf", String.class); return (T) method.invoke(null, strvalue); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e2) { throw new IllegalArgumentException("The target type '" + type + "' has no 'valueOf' method for String or type: " + value.getClass()); } } } } protected Object getFieldValueFromModel(String fieldName, VariableScope varscope, boolean forceExpressionProcessing) { FieldExtension field = this.fieldMap.get(fieldName); if (field == null) { return null; } else if (field.getExpression() != null && field.getExpression().length() > 0) { this.logger.trace("Field value is recognized as an expression by the Activity framework: {}: {}", fieldName, field.getExpression()); ExpressionManager exprman = Context.getProcessEngineConfiguration().getExpressionManager(); Expression expr = exprman.createExpression(field.getExpression()); return (T) expr.getValue(varscope); return expr.getValue(varscope); } else if (field.getStringValue() == null) { this.logger.trace("Field value is null: {}", fieldName); return null; } else if (forceExpressionProcessing) { this.logger.trace("Field value will be processed as potentially having expression(s): {}", fieldName); ExpressionManager exprman = Context.getProcessEngineConfiguration().getExpressionManager(); Expression expr = exprman.createExpression(field.getStringValue()); return (T) expr.getValue(varscope); } else if (String.class.isAssignableFrom(type)) { return (T) field.getStringValue(); return expr.getValue(varscope); } else if (field.getStringValue().startsWith("${") && field.getStringValue().endsWith("}")) { this.logger.trace("Field value is recognized as an expression by the MQ extension: {}: {}", fieldName, field.getStringValue()); ExpressionManager exprman = Context.getProcessEngineConfiguration().getExpressionManager(); Expression expr = exprman.createExpression(field.getStringValue()); return expr.getValue(varscope); } else { try { Method method = type.getMethod("valueOf", String.class); return (T) method.invoke(null, field.getStringValue()); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new IllegalArgumentException(e); } return field.getStringValue(); } } Loading Loading
src/main/java/com/inteligr8/activiti/mq/MqServiceTask.java +46 −10 Original line number Diff line number Diff line Loading @@ -70,26 +70,62 @@ public class MqServiceTask { @SuppressWarnings("unchecked") protected <T> T getFieldValueFromModel(String fieldName, Class<T> type, VariableScope varscope, boolean forceExpressionProcessing) { Object value = this.getFieldValueFromModel(fieldName, varscope, forceExpressionProcessing); if (value == null) { return null; } else if (String.class.isAssignableFrom(type)) { if (value instanceof String) { return (T) value; } else { return (T) value.toString(); } } else { try { Method method = type.getMethod("valueOf", value.getClass()); return (T) method.invoke(null, value); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { String strvalue; if (value instanceof String) { strvalue = (String) value; } else { strvalue = value.toString(); } try { Method method = type.getMethod("valueOf", String.class); return (T) method.invoke(null, strvalue); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e2) { throw new IllegalArgumentException("The target type '" + type + "' has no 'valueOf' method for String or type: " + value.getClass()); } } } } protected Object getFieldValueFromModel(String fieldName, VariableScope varscope, boolean forceExpressionProcessing) { FieldExtension field = this.fieldMap.get(fieldName); if (field == null) { return null; } else if (field.getExpression() != null && field.getExpression().length() > 0) { this.logger.trace("Field value is recognized as an expression by the Activity framework: {}: {}", fieldName, field.getExpression()); ExpressionManager exprman = Context.getProcessEngineConfiguration().getExpressionManager(); Expression expr = exprman.createExpression(field.getExpression()); return (T) expr.getValue(varscope); return expr.getValue(varscope); } else if (field.getStringValue() == null) { this.logger.trace("Field value is null: {}", fieldName); return null; } else if (forceExpressionProcessing) { this.logger.trace("Field value will be processed as potentially having expression(s): {}", fieldName); ExpressionManager exprman = Context.getProcessEngineConfiguration().getExpressionManager(); Expression expr = exprman.createExpression(field.getStringValue()); return (T) expr.getValue(varscope); } else if (String.class.isAssignableFrom(type)) { return (T) field.getStringValue(); return expr.getValue(varscope); } else if (field.getStringValue().startsWith("${") && field.getStringValue().endsWith("}")) { this.logger.trace("Field value is recognized as an expression by the MQ extension: {}: {}", fieldName, field.getStringValue()); ExpressionManager exprman = Context.getProcessEngineConfiguration().getExpressionManager(); Expression expr = exprman.createExpression(field.getStringValue()); return expr.getValue(varscope); } else { try { Method method = type.getMethod("valueOf", String.class); return (T) method.invoke(null, field.getStringValue()); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new IllegalArgumentException(e); } return field.getStringValue(); } } Loading