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

📄 defineexpression.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: DefineExpression.java,v 1.21 2005/05/17 16:40:23 jmettraux Exp $ *///// DefineExpression.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.ApplicationContext;import openwfe.org.engine.Definitions;import openwfe.org.engine.expool.ExpressionPool;import openwfe.org.engine.history.History;import openwfe.org.engine.workitem.InFlowWorkItem;import openwfe.org.engine.expressions.map.ExpressionMap;import openwfe.org.engine.expressions.raw.RawExpression;/** * This expression may interpret 'workflow-definition', 'subprocess-definition' * and above all 'define' * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Id: DefineExpression.java,v 1.21 2005/05/17 16:40:23 jmettraux Exp $ </font> * * @author john.mettraux@openwfe.org */public class DefineExpression    extends AbstractCompositeFlowExpression    implements DefinitionExpression{    private final static org.apache.log4j.Logger log = org.apache.log4j.Logger        .getLogger(DefineExpression.class.getName());    //    // CONSTANTS & co    //    // FIELDS    //    // CONSTRUCTORS    //    // METHODS    //    // BEAN METHODS    //    // METHODS from DefinitionExpression    /**     * This expression's implementation of eval() will yield a      * FlowExpressionId pointing to the body of the definition     */    public Object eval (final InFlowWorkItem wi)        throws ApplyException    {        //        // interpret all the definitions                final java.util.Map vars = new java.util.HashMap();        RawExpression body = null;                final java.util.Iterator it = getChildren().iterator();        while (it.hasNext())        {            final FlowExpressionId fei =                 (FlowExpressionId)it.next();            final RawExpression exp =                 (RawExpression)getExpressionPool().fetch(fei);            log.debug("eval() child is "+fei);            if ( ! exp.isDefinition())            {                if (body == null)                {                    body = exp;                    body.getVariables().putAll(vars);                }                continue;            }            //            // then it's a definition            try            {                define(vars, body, exp, wi);            }            catch (final BuildException be)            {                throw new ApplyException                    ("Failed to bind definition", be);            }        }        //        // then apply the root (the body of the definition)                if (body == null)            throw new ApplyException("No body for definition "+getId());        final FlowExpressionId id = body.getId();        log.debug("eval() body is "+id);        return id;    }    private void define         (final java.util.Map vars,          final RawExpression body,         final RawExpression re,          final InFlowWorkItem wi)    throws         BuildException, ApplyException    {        //        // determine name                final String name = re.getDefinitionName();        //        // postulate : re points to a DefinitionExpression        final DefinitionExpression de =             (DefinitionExpression)re.resolveExpression(wi);        //        // get parent and set variable at its level                final Object value = de.eval(wi);                if (value != null)        {            if (body != null)                body.setLocalVariable(name, value);            else                vars.put(name, value);        }        //this.storeItself();        // not nessary anymore...    }    //    // METHODS from FlowExpression    /**     * Interprets all definitions, THEN applies the body...     */    public void apply (final InFlowWorkItem wi)         throws ApplyException    {        final FlowExpressionId fei = (FlowExpressionId)this.eval(wi);        this.setChildren(new java.util.ArrayList(1));        this.getChildren().add(fei);        //        // history logging                String message = "launching";        if (getParent() != null) message = "launching sub";        historyLog(wi, History.EVT_FLOW_START, null, message);        //        // history item        wi.addHistoryItem(getId(), this.getClass().getName(), message);        //        // launching        getExpressionPool().apply(fei, wi);    }    /**     * When the workflow is instantied, all expressions from root expression to     * all leaf expressions see their 'apply' method get called.     * When then leaf expressions (ParticipantExpressions) get answers from     * their participant, they communicate the modified workitem to their     * father expression with its 'reply' method.     */    public void reply (final InFlowWorkItem wi)         throws ReplyException    {        //        // [history] log the end of the [sub]flow                historyLog(wi, History.EVT_FLOW_END, null, "replying");        //        // if there is a parent, reply to it                if (getParent() != null)             replyToParent(wi);        else            //this.release();            getExpressionPool().removeExpression(this);    }    /* *     * Looks up for a variable value in the nearest 'process-definition' parent,     * or in its parents if not found there.     * This method overrides the one found in AbstractFlowExpression :      * this define expression ought to reply to the lookup.     * /    public Object lookupProcessVariable (final String variableName)    {        return lookupVariable(variableName);    }     */    /**     * Inits the expression.     */    public void init         (final ApplicationContext context,         final FlowExpressionId parentId,          final FlowExpressionId id,          final RawExpression generatingExpression,         final Object raw,         final InFlowWorkItem currentWi)    throws         BuildException    {        super.init            (context,              parentId,             id,             generatingExpression,             raw,             currentWi);        if (getChildren() == null) return;        int bodyCount = 0;                final java.util.Iterator it = getChildren().iterator();        while (it.hasNext())        {            final FlowExpressionId fei =                 (FlowExpressionId)it.next();            final Class childClass =                 getExpressionMap().getClass(fei.getExpressionName());            if (childClass == null)            {                log.warn                    ("init() "+id.getExpressionName()+                     " unknown expression '"+fei.getExpressionName()+"'");                continue;            }            if ( ! DefineExpression.class.isAssignableFrom(childClass))                bodyCount++;            if (bodyCount > 1)            {                log.warn                    ("init() "+id.getExpressionName()+                     " with more than one body");                break;            }        }    }    //    // STATIC METHODS}

⌨️ 快捷键说明

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