⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 valueutils.java

📁 一个工作流设计及定义的系统,可以直接与数据库结合进行系统工作流程的定义及应用.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            variableValue = functionValue;        }        log.debug("value is       >"+variableValue+"<");        if (value != null)            log.debug("value.class is >"+variableValue.getClass()+"<");        //        // the end        return variableValue;    }    /**     * This method determines and sets a value in a workitem field or     * in the expression variable.     */    public static void determineAndSetTarget        (final FlowExpression expression,         final InFlowWorkItem workItem,         final Object value)    throws        ValueException    {        doDetermineAndSetTarget            ("",             expression,             null,             workItem,             value);    }    /**     * This method determines and sets a value in a workitem field or     * in the expression variable, a prefix dictates which key in the      * expression params is used for the determination     */    public static void determineAndSetTarget        (final String prefix,         final FlowExpression launchingExpression,         final FlowExpressionId targetExpressionId,         final InFlowWorkItem workItem,         final Object value)    throws        ValueException    {        final ExpressionPool pool = Definitions            .getExpressionPool(launchingExpression.context());        final FlowExpression targetExpression = pool            .fetch(targetExpressionId);        doDetermineAndSetTarget            (prefix,             launchingExpression,             targetExpression,             workItem,             value);    }    /**     * This method determines and sets a value in a workitem field or     * in the expression variable, a prefix dictates which key in the      * expression params is used for the determination.     */    public static void determineAndSetTarget        (final String prefix,         final FlowExpression expression,         final InFlowWorkItem workItem,         final Object value)    throws        ValueException    {        doDetermineAndSetTarget            (prefix,             expression,             null,             workItem,             value);    }    /*     * This method determines and sets a value in a workitem field or     * in the expression variable, a prefix dictates which key in the      * expression params is used for the determination.     * This one does the real job, if it's about setting a variable, and if     * targetExpression is not null, targetExpression will get the variable      * set, if targetExpression is null, expression will get the target set.     */    private static void doDetermineAndSetTarget        (String prefix,         final FlowExpression expression,         final FlowExpression targetExpression,         final InFlowWorkItem workItem,         final Object value)    throws        ValueException    {        //if (value == null) return;        //        // unset value is now possible through this method...        if (prefix == null) prefix = "";        String fieldName =             expression.lookupAttribute(prefix+FIELD_TARGET, workItem);        String variableName =             expression.lookupAttribute(prefix+VARIABLE_TARGET, workItem);        if (fieldName == null &&            variableName == null)        {            throw new ValueException                ("Expression should set a value but which one ? "+                 "there is no paremeter '"+prefix+FIELD_TARGET+                 "' or '"+prefix+VARIABLE_TARGET+"' given.");        }        if (variableName != null)        {            if (targetExpression != null)            {                //targetExpression.setVariable(variableName, value);                expression.getExpressionPool()                    .setVariable(targetExpression, variableName, value);            }            else            {                //expression.setVariable(variableName, value);                                expression.getExpressionPool()                    .setVariable(expression, variableName, value);            }            return;        }        //        // fieldName != null        //                //        // determine if field value can be overriden        boolean override = true;        String sOverride = expression.lookupAttribute(OVERRIDE, workItem);        if (sOverride != null &&            sOverride.trim().toLowerCase().equals("false"))        {            override = false;        }        //         // determine if field currently has a value        Object currentValue = workItem.getAttributes().get(fieldName);        if (currentValue != null && ! override)        {            log.debug("Cannot override workitem's field value");            return;        }        //        // set value        if (value == null)        {            workItem.getAttributes().remove(fieldName);        }        else        {            Attribute aValue = null;            if (value instanceof Attribute)                aValue = (Attribute)value;            else                aValue = new StringAttribute(value.toString());            workItem.getAttributes().put(fieldName, aValue);        }    }    /**     * Determines which expression variable or workitem field should     * be incremented and increments it with the given value.     */    public static void determineAndIncrementTarget        (FlowExpression expression,         InFlowWorkItem workItem,         Object value)    throws        ValueException    {        if (value == null) return;        String fieldName =             expression.lookupAttribute(FIELD_TARGET, workItem);        String variableName =             expression.lookupAttribute(VARIABLE_TARGET, workItem);        if (fieldName == null &&            variableName == null)        {            throw new ValueException                ("Expression should set a value but which one ? "+                 "there is no paremeter '"+FIELD_TARGET+                 "' or '"+VARIABLE_TARGET+"' given.");        }        if (variableName != null)        {            Object currentValue = expression.lookupVariable(variableName);            value = increment(currentValue, value);            //expression.setVariable(variableName, value);            expression.getExpressionPool()                .setVariable(expression, variableName, value);        }        else if (fieldName != null)        {            Object currentValue = workItem.getAttributes().get(fieldName);            value = increment(currentValue, value);            workItem.getAttributes().put(fieldName, (Attribute)value);        }    }    private static Object increment (Object val, Object inc)    {        Object originalVal = val;        val = refineValue(val);        inc = refineValue(inc);        Object result = refinedIncrement(val, inc);        if (originalVal instanceof Attribute)        {            if (result instanceof Long)                return new LongAttribute((Long)result);            if (result instanceof Double)                return new DoubleAttribute((Double)result);            return new StringAttribute(result.toString());        }        return result;    }    private static Object refineValue (final Object o)    {        if (o == null) return "";        try        {            long l = Long.parseLong(o.toString());            return new Long(l);        }        catch (NumberFormatException nfe)        {            // ignore        }        try        {            double d = Double.parseDouble(o.toString());            return new Double(d);        }        catch (NumberFormatException nfe)        {            // ignore        }        return o.toString();    }    private static double toDouble (Object o)    {        return Double.parseDouble(o.toString());    }    private static int toInt (Object o)    {        return Integer.parseInt(o.toString());    }    private static Object refinedIncrement (Object val, Object inc)    {        if (val instanceof String || inc instanceof String)            return val.toString() + inc.toString();        if (val instanceof Double || inc instanceof Double)            return new Double(toDouble(val) + toDouble(inc));        return new Integer(toInt(val) + toInt(inc));    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -