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

📄 whenexpression.java

📁 一个工作流设计及定义的系统,可以直接与数据库结合进行系统工作流程的定义及应用.
💻 JAVA
字号:
/* * Copyright (c) 2005, John Mettraux, OpenWFE.org * All rights reserved. *  * Redistribution and use in source and binary forms, with or without  * modification, are permitted provided that the following conditions are met: *  * . Redistributions of source code must retain the above copyright notice, this *   list of conditions and the following disclaimer.   *  * . Redistributions in binary form must reproduce the above copyright notice,  *   this list of conditions and the following disclaimer in the documentation  *   and/or other materials provided with the distribution. *  * . Neither the name of the "OpenWFE" nor the names of its contributors may be *   used to endorse or promote products derived from this software without *   specific prior written permission. *  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  * POSSIBILITY OF SUCH DAMAGE. * * $Id: WhenExpression.java,v 1.24 2005/05/17 16:40:23 jmettraux Exp $ *///// WhenExpression.java//// john.mettraux@openwfe.org//// generated with // jtmpl 1.1.01 2004/05/19 (john.mettraux@openwfe.org)//package openwfe.org.engine.expressions;import openwfe.org.OpenWfeException;import openwfe.org.ApplicationContext;import openwfe.org.time.Time;import openwfe.org.engine.expool.ExpressionPool;import openwfe.org.engine.history.History;import openwfe.org.engine.workitem.InFlowWorkItem;/** * An if expression that blocks until its condition realizes or until * it times out. * There is no else clause for a 'when' expression. * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Id: WhenExpression.java,v 1.24 2005/05/17 16:40:23 jmettraux Exp $ </font> * * @author john.mettraux@openwfe.org */public class WhenExpression    extends AbstractCompositeFlowExpression    implements ExpressionWithTimeOut, ExpressionWithTimer{    private final static org.apache.log4j.Logger log = org.apache.log4j.Logger        .getLogger(WhenExpression.class.getName());    //    // CONSTANTS & co    //    // FIELDS    private InFlowWorkItem workitem = null;    private boolean conditionTreated = false;    //    // CONSTRUCTORS    //    // BEAN METHODS    /**     * When this expression gets applied, it 'traps' its workitem     * until reply...     */    public InFlowWorkItem getWorkitem () { return this.workitem; }    /**     * Set to true when the condition got treated (before) the second and     * last reply.     */    public boolean isConditionTreated ()     {         //log.debug("isConditionTreated() returning "+this.conditionTreated);        return this.conditionTreated;     }    public void setWorkitem (final InFlowWorkItem wi)     {         if (wi == null) return;        this.workitem = (InFlowWorkItem)wi.clone();     }    public void setConditionTreated (final boolean b)     {         //log.debug("setConditionTreated("+b+")");        this.conditionTreated = b;     }    //    // METHODS    /**     * This method is used to poll the conditional clause to     * see wether it's possible to apply the child     */    public void check ()        throws OpenWfeException    {        log.debug("check()");        if (this.workitem == null)        {            log.debug("check() workitem is null. 'when' Skipped.");            return;        }        if (isConditionTreated())        {            log.debug                ("check() condition already treated. Returning");            return;        }        tag(this.workitem);        log.debug("check() workitem got tagged");        /*final FlowExpressionId rootExpressionId =*/         getLauncher().launchSub            (this.workitem,              getId(),              (FlowExpressionId)getChildren().get(0));             //""+(checkCounter++)+"."+getId().getWorkflowInstanceId());             //false);        // getId() indicates here that the parent id of the newly         // launched scope parent is this when expression...        //log.debug("check() launched conditional subprocess.");    }    /**     * Returns the name of this expression as used     * in the author field of the generated workitems     */    protected String getNameInHistory ()    {        return this.getClass().getName()+" $Revision: 1.24 $";    }    //    // METHODS from FlowExpression    public void apply (final InFlowWorkItem wi)         throws ApplyException    {        log.debug("apply()");        this.setWorkitem(wi);        this.storeItself();        try        {            check();        }        catch (final OpenWfeException owe)        {            throw new ApplyException                ("apply() checkCondition() failed", owe);        }    }    /**     * This override takes care of removing the conditional subexpression     * before the flow leaves this when expression.     */    public void replyToParent (final InFlowWorkItem wi)        throws ReplyException    {        if (getChildren() != null && getChildren().size() > 0)        {            getExpressionPool()                .removeExpression((FlowExpressionId)getChildren().get(0));        }        super.replyToParent(wi);    }    public void reply (final InFlowWorkItem wi)        throws ReplyException    {        log.debug("reply()");        if (isConditionTreated())        {            log.debug("reply() condition is treated - replying to parent");            replyToParent(wi);            return;        }        if (lookupLocalBooleanResult())        {            //            // add history to workitem            this.workitem.addHistoryItem                (getNameInHistory(),                 "triggered");            //            // log to history service            historyLog                (wi,                 History.EVT_INFO,                  null,                 getNameInHistory());                    // participantName is set to null            //            // do the rest            if (getChildren().size() < 2)            {                log.info                    ("reply() condition realized but no child to apply");                replyToParent(wi);                return;            }            //            // apply child            log.debug("reply() setting conditionTreated to true");            setConditionTreated(true);            try            {                this.storeItself();                getExpressionPool().apply                    ((FlowExpressionId)getChildren().get(1), this.workitem);            }            catch (ApplyException ae)            {                throw new ReplyException("reply() failure", ae);            }        }        // else do nothing                log.info("reply() conditional clause returned with 'false'");    }    //    // METHODS from ExpressionWithTimeOut    /**     * This method should return false if the purge daemon should not     * consider the implemented and instantiated Expression during its run.     */    public boolean isTimeOutActivated ()    {        return true;    }    public long determineTimeOut ()    {        long timeOut = -1;        //        // determine time out at engine level                timeOut = context().getTime(ExpressionPool.DEFAULT_EXPRESSION_TIMEOUT);                //        // determine time out at expression level (highest priority)        String sTimeOut =             this.getAttributeValue(TIMEOUT);        if (sTimeOut != null)            timeOut = Time.parseTimeString(sTimeOut);        //        // return        if (timeOut < 1)            timeOut = ExpressionPool.DEFAULT_EXPRESSION_TIMEOUT_VALUE;                return timeOut;    }    /**     * This method is called by the ExpressionStore when it notices that the     * WhenExpression expired.     */    public void timeOutReply ()        throws ReplyException    {        this.getWorkitem().addHistoryItem            (getNameInHistory(),              "timed out");                //        // log timeout in history        historyLog            (null, EVT_TIMED_OUT, null, getNameInHistory());                // participantName is set to null        //        // resume flow                log.debug("timeOutReply() resuming flow");        //super.reply(this.getWorkitem());        reply(this.getWorkitem());    }    //    // STATIC METHODS}

⌨️ 快捷键说明

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