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

📄 simpleworkitemstore.java

📁 日常的办公系统 应用工作流框架等增加员工的基本信息、培训信息、奖罚信息、薪资信息
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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: SimpleWorkItemStore.java,v 1.14 2005/07/07 08:57:14 jmettraux Exp $ *///// SimpleWorkItemStore.java//// john.mettraux@openwfe.org//// generated with // jtmpl 1.1.01 2004/05/19 (john.mettraux@openwfe.org)//package openwfe.org.worklist.impl.store;import javax.security.auth.Subject;import openwfe.org.MapUtils;import openwfe.org.Application;import openwfe.org.AbstractService;import openwfe.org.ServiceException;import openwfe.org.ApplicationContext;import openwfe.org.auth.BasicPrincipal;import openwfe.org.engine.workitem.CancelItem;import openwfe.org.engine.workitem.InFlowWorkItem;import openwfe.org.engine.dispatch.DispatchingException;import openwfe.org.engine.expressions.FlowExpressionId;import openwfe.org.engine.participants.Participant;import openwfe.org.engine.participants.ParticipantMap;import openwfe.org.worklist.Header;import openwfe.org.worklist.HeaderFactory;import openwfe.org.worklist.WorkListException;import openwfe.org.worklist.auth.StorePermission;import openwfe.org.worklist.impl.LastModifiedHeaderComparator;import openwfe.org.worklist.store.Lock;import openwfe.org.worklist.store.PutStrategy;import openwfe.org.worklist.store.GetStrategy;import openwfe.org.worklist.store.StoreStrategy;import openwfe.org.worklist.store.WorkItemStore;import openwfe.org.worklist.store.StoreException;/** * 1.5.0's style store, complete with a put and a get strategy. * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Id: SimpleWorkItemStore.java,v 1.14 2005/07/07 08:57:14 jmettraux Exp $ </font> * * @author john.mettraux@openwfe.org */public class SimpleWorkItemStore    extends AbstractService    implements WorkItemStore{    private final static org.apache.log4j.Logger log = org.apache.log4j.Logger        .getLogger(SimpleWorkItemStore.class.getName());    //    // CONSTANTS & co    /**     * If the parameter 'default' for this store is set to 'true' or 'yes',      * the store will be a default store.     */    public final static String P_DEFAULT        = "default";    /**     * The 'storage' parameter indicates to this store which     * storage is should use.     */    public final static String P_STORAGE        = "storage";    /**     * If the param 'storage' is not set, the store will look for a     * storage service simply named 'storage'.     */    public final static String DEFAULT_STORAGE        = "storage";    /**     * The param 'putStrategyClass' sets the [put] strategy the store will     * use when asked to store workitems.     */    public final static String P_PUT_STRATEGY_CLASS        = "putStrategyClass";    /**     * The param 'getStrategyClass' sets the [get] strategy the store will     * use when asked for workitem retrieval.     */    public final static String P_GET_STRATEGY_CLASS        = "getStrategyClass";    /**     * Constant for the time parameter named 'lockTimeout' : how many     * time an idle lock should be maintained on a workitem ?     */    public final static String P_LOCK_TIMEOUT        = "lockTimeout";    /**     * Constant for the time parameter named 'unlockFrequency' : how      * frequently should the workitem store check for workitem whose     * locks did time out ?     */    public final static String P_UNLOCK_FREQUENCY        = "unlockFrequency";    /**      * Set to 15m     */    public final static String DEFAULT_LOCK_TIMEOUT        = "15m";    /**     * Set to 7m     */    public final static String DEFAULT_UNLOCK_FREQUENCY        = "7m";    /**     * Constant for the parameter named 'headerFactory' : a header is a      * summary of a workitem for display in a selection list, a header     * factory is a piece of code that creates a header for a workitem. Use     * this parameter to indicate the workitem store which header factory     * (an OpenWFE like an other) it should use.     */    public final static String P_HEADER_FACTORY        = "headerFactory";    //    // FIELDS    private String storageName = null;    private PutStrategy putStrategy = null;    private GetStrategy getStrategy = null;    // lock related fields    private java.util.Map lockMap = new java.util.HashMap();    private long lockTimeout = 0;    private UnlockDaemon unlockDaemon = null;    private HeaderFactory headerFactoryService = null;    private String[] acceptedParticipants = null;    //    // CONSTRUCTORS    public void init         (final String serviceName,          final ApplicationContext context,          final java.util.Map serviceParams)    throws         ServiceException    {        super.init(serviceName, context, serviceParams);        //        // set storage name                this.storageName = MapUtils.getAsString            (serviceParams, P_STORAGE, DEFAULT_STORAGE);        log.debug            ("init() store '"+getName()+             "' is using storage '"+this.storageName+"'");        //        // set putStrategy                String classname = MapUtils.getAsString            (serviceParams,              P_PUT_STRATEGY_CLASS,              DefaultPutStrategy.class.getName());        this.putStrategy = (PutStrategy)buildStrategy(classname);        //        // set getStrategy        classname = MapUtils.getAsString            (serviceParams,              P_GET_STRATEGY_CLASS,              DefaultGetStrategy.class.getName());        this.getStrategy = (GetStrategy)buildStrategy(classname);        //        // init accepted participants                initAcceptedParticipants();        //        // init UnlockDaemon                initUnlockDaemon();        //        // init done.        log.debug("init() store '"+getName()+"' ready.");    }    private StoreStrategy buildStrategy (final String strategyClassName)        throws ServiceException    {        try        {            final StoreStrategy ss =                 (StoreStrategy)Class.forName(strategyClassName).newInstance();            ss.init(getContext(), this, getParams(), getStorageName());            log.debug("buildStrategy() built one of class "+strategyClassName);            return ss;        }        catch (final Exception e)        {            throw new ServiceException                ("Failed to build strategy of class "+strategyClassName, e);        }    }    /**     * This method is called by the init() method, to determine how the     * unlock daemon should behave and to start it.     */    protected void initUnlockDaemon ()    {        this.lockTimeout = MapUtils.getAsTime            (getParams(), P_LOCK_TIMEOUT, DEFAULT_LOCK_TIMEOUT);        log.info("lockTimeout set to "+this.lockTimeout+" ms");        final long unlockFreq = MapUtils.getAsTime            (getParams(), P_UNLOCK_FREQUENCY, DEFAULT_UNLOCK_FREQUENCY);        this.unlockDaemon = new UnlockDaemon();        Application.getTimer().schedule            (this.unlockDaemon, 60, unlockFreq);        log.info("UnlockDaemon invoked. Will wake up every "+unlockFreq+" ms");    }    /**     * Establishes a list of participant names that this workitem     * stores is going to accept when the worklist will iterator     * among its stores.     */    protected void initAcceptedParticipants ()    {        final String rawString = (String)getParams().get(P_PARTICIPANTS);                if (rawString == null)             this.acceptedParticipants = new String[] {};        else            this.acceptedParticipants = rawString.split(", *");    }    //    // GETTERS and SETTERS    /**     * Returns the name of the storage service this store works with.     */    public String getStorageName ()    {        return this.storageName;    }    /**     * Returns the 'input' strategy this store uses.     */    public PutStrategy getPutStrategy ()    {        return this.putStrategy;    }    /**     * Returns the 'retrieval' strategy this store uses.     */    public GetStrategy getGetStrategy ()    {        return this.getStrategy;    }    //    // METHODS    /**     * Unlocks the given workitem id.     */    protected void unlock (final FlowExpressionId workitemId)        throws StoreException    {        log.debug("unlock() for "+workitemId);        this.lockMap.remove(workitemId);    }    /**     * Returns the header factory this store works with.     */    protected HeaderFactory getHeaderFactory ()    {        if (this.headerFactoryService == null)        {            final String serviceName = MapUtils.getAsString                (getParams(),                  P_HEADER_FACTORY,                  openwfe.org.worklist.Definitions.HEADER_FACTORY);            this.headerFactoryService = (HeaderFactory)getContext()                .get(serviceName);        }        return this.headerFactoryService;    }    /**     * Locks a workitem. Internal usage.     */    protected void lockWorkItem         (final Subject s, final FlowExpressionId workitemId)    {        this.lockMap.put(workitemId, new Lock(s, this.lockTimeout));        log.debug("lockWorkItem() locked "+workitemId);    }    //    // METHODS from WorkItemStore    /**     * Returns true if the given workitem is locked.     */    public boolean isLocked (final FlowExpressionId workitemId)    {        return this.lockMap.keySet().contains(workitemId);    }    /**     * Returns true if the given workitem (id) has been locked by another     * subject (principal).     */    public boolean isLockedBySomeoneElse         (final Subject s, final FlowExpressionId workitemId)    {        final Lock l = getLock(workitemId);        if (l == null) return false;        return ! l.getLocker().equals(s);    }    /**     * Returns the lock set on the workitem, will return null if no lock is set     * on the workitem.     */    public Lock getLock (final FlowExpressionId workitemId)    {        return (Lock)this.lockMap.get(workitemId);    }    /**     * Returns the name of the locker of this workitem, or null if the     * workitem is not locked.     */    public String getLockerName (final FlowExpressionId workitemId)    {        final Lock l = getLock(workitemId);        if (l == null) return null;        return            BasicPrincipal.getBasicPrincipal(l.getLocker()).getName();    }    /**     * Inserts a workitem in the store.     * This method takes no Subject as parameter because it is used     * by listeners, not clients.     */    public void store (final InFlowWorkItem wi)        throws StoreException    {        this.putStrategy.put(wi);    }    /**     * 'Cancels' a workitem, either remove it, either flags it as cancelled     */    public void cancel (final CancelItem ci)        throws StoreException    {        this.putStrategy.remove(ci.getLastExpressionId());    }    /**     * Delegate works to this workitem store     */    public void delegate (final InFlowWorkItem wi)        throws StoreException    {        java.security.AccessController.checkPermission            (StorePermission.newStorePermission(getName(), "delegate"));        log.debug            ("delegate() store '"+getName()+"' received delegated wi "+             wi.getLastExpressionId());        this.putStrategy.put(wi);    }    /**     * Delegate works to this workitem store     */    public void delegateToParticipant         (final Subject s, final InFlowWorkItem wi, final String participantName)    throws         StoreException    {        //        // find participant                final ParticipantMap pMap = openwfe.org.engine.Definitions            .getParticipantMap(getContext());        final Participant p = pMap.get(participantName);        if (p == null)        {            throw new StoreException                ("Cannot delegate to unknown participant '"+                 participantName+"'");        }        //        // remove from store        this.remove(s, wi.getLastExpressionId());        //        // tag history

⌨️ 快捷键说明

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