class ActivitiHelper {

    public Boolean getExpressionVariableAsBoolean(Expression expression, DelegateExecution execution, String variableName, boolean isRequired,
        Boolean defaultValue) throws IllegalArgumentException
    {
        Boolean variableBoolean = defaultValue;
        String variableString = getExpressionVariableAsString(expression, execution);

        if (isRequired && StringUtils.isBlank(variableString))
        {
            throw new IllegalArgumentException("\"" + variableName + "\" must be specified.");
        }

        if (isRequired || StringUtils.isNotBlank(variableString))
        {
            String variableStringTrimmed = variableString.trim();
            if (variableStringTrimmed.equalsIgnoreCase(Boolean.TRUE.toString()) || variableStringTrimmed.equalsIgnoreCase(Boolean.FALSE.toString()))
            {
                variableBoolean = Boolean.valueOf(variableStringTrimmed);
            }
            else
            {
                throw new IllegalArgumentException("\"" + variableName + "\" must be a valid boolean value of \"true\" or \"false\".");
            }
        }

        return variableBoolean;
    }

}