📄 xlobworkitemstorage.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: XlobWorkItemStorage.java,v 1.3 2005/07/28 16:33:10 jmettraux Exp $ *///// XlobWorkItemStorage.java//// john.mettraux@openwfe.org//// generated with // jtmpl 1.1.01 2004/05/19 (john.mettraux@openwfe.org)//package openwfe.org.xlob.worklist;import openwfe.org.Utils;import openwfe.org.MapUtils;import openwfe.org.ServiceException;import openwfe.org.ApplicationContext;import openwfe.org.xml.XmlUtils;import openwfe.org.engine.workitem.InFlowWorkItem;import openwfe.org.engine.workitem.CodingException;import openwfe.org.engine.expressions.FlowExpressionId;import openwfe.org.engine.impl.workitem.xml.XmlWorkItemCoder;import openwfe.org.worklist.store.StoreException;import openwfe.org.worklist.impl.store.AbstractStorage;import openwfe.org.worklist.impl.store.StoreStat;import openwfe.org.xlob.XlobSession;import openwfe.org.xlob.XlobException;/** * An implementation of WorkItemStorage that stores workitems in xlob. * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Id: XlobWorkItemStorage.java,v 1.3 2005/07/28 16:33:10 jmettraux Exp $ </font> * * @author john.mettraux@openwfe.org */public class XlobWorkItemStorage extends AbstractStorage { private final static org.apache.log4j.Logger log = org.apache.log4j.Logger .getLogger(XlobWorkItemStorage.class.getName()); // // CONSTANTS & co // // FIELDS /* * A session per store : storeName -> xlobSession */ private java.util.Map sessionMap = new java.util.HashMap(20); // // CONSTRUCTORS /* * not much to init... * public void init (final String serviceName, final ApplicationContext context, final java.util.Map serviceParams) throws ServiceException { super.init(serviceName, context, serviceParams); log.info("store ready."); } */ // // METHODS /** * Returns the XlobSession tied to a store. */ protected synchronized XlobSession getSession (final String storeName) throws ServiceException { XlobSession result = (XlobSession)this.sessionMap.get(storeName); if (result != null) return result; result = openwfe.org.xlob.XlobSessionImpl .createSession(getName()+"_"+storeName, getContext(), getParams()); this.sessionMap.put(storeName, result); return result; } /** * Always return the XmlCoder as found in the coder-configuration.xml */ protected XmlWorkItemCoder getCoder () { return (XmlWorkItemCoder)openwfe.org.engine.Definitions .getXmlCoder(getContext()); } /** * Encodes the given workitem to XML. */ protected org.jdom.Element encode (final InFlowWorkItem wi) throws CodingException { return getCoder().encodeAsXml(wi); } /** * Decodes a workitem from XML. */ protected InFlowWorkItem decode (final org.jdom.Document doc) throws CodingException { return (InFlowWorkItem)getCoder() .decode(doc, getContext(), getParams()); } // // METHODS from WorkItemStorage /** * Inserts a workitem into the storage for given store. */ public void storeWorkItem (final String storeName, final InFlowWorkItem wi) throws StoreException { try { getSession(storeName).store(wi.getLastExpressionId(), encode(wi)); } catch (final Exception e) { throw new StoreException ("failed to store workitem", e); } } /** * Removes the workitem from the storage for a given store. */ public void removeWorkItem (final String storeName, final FlowExpressionId fei) throws StoreException { try { getSession(storeName).remove(fei); } catch (final Exception e) { throw new StoreException ("failed to remove workitem", e); } } /** * Retrieves a workitem given the storename and the workitem id. */ public InFlowWorkItem retrieveWorkItem (final String storeName, final FlowExpressionId fei) throws StoreException { try { //return (InFlowWorkItem)getSession(storeName).findBean(fei); return decode(getSession(storeName).find(fei)); } catch (final Exception e) { throw new StoreException ("failed to retrieve workitem "+fei, e); } } /** * Returns the number of workitems in a store. */ public int countWorkItems (final String storeName) throws StoreException { try { return getSession(storeName).count(null); } catch (final Exception e) { throw new StoreException ("failed to count workitems", e); } } /** * Returns a list of workitems from a store. */ public java.util.List listWorkItems (final String storeName, final int limit) throws StoreException { try { final java.util.Set s = getSession(storeName).query(null, limit); final java.util.List l = new java.util.ArrayList(s.size()); final java.util.Iterator it = s.iterator(); while (it.hasNext()) { final org.jdom.Document d = (org.jdom.Document)it.next(); l.add(decode(d)); } return l; } catch (final Exception e) { throw new StoreException ("failed to list workitems", e); } } // // METHODS from Service /** * Status is outputted as a JDOM element. The status is various * information about a service activities and state. */ public org.jdom.Element getStatus () { org.jdom.Element result = new org.jdom.Element(getName()); result.addContent(XmlUtils.getClassElt(this)); result.addContent(XmlUtils.getRevisionElt("$Id: XlobWorkItemStorage.java,v 1.3 2005/07/28 16:33:10 jmettraux Exp $")); // // list file names to determine storage content java.util.List prefixes = null; try { prefixes = getSession("").listPrefixes(); } catch (final Throwable t) { log.warn("getStatus() couldn't list prefixes", t); } final StoreStat stat = new StoreStat(); final java.util.Iterator it = prefixes.iterator(); while (it.hasNext()) { final String s = (String)it.next(); final String storeName = s.substring(getName().length()+1); try { final java.util.Iterator lit = getSession(storeName).listExpressionIds().iterator(); while (lit.hasNext()) { final FlowExpressionId fei = (FlowExpressionId)lit.next(); final String flowDef = fei.getWorkflowDefinitionName() + " " + fei.getWorkflowDefinitionRevision(); final String flowId = fei.getParentWorkflowInstanceId(); stat.put(storeName, flowDef, flowId); } } catch (final Throwable t) { log.warn("failed to include stats for store '"+storeName+"'"); } } result.addContent(stat.render()); // // the end return result; } // // STATIC METHODS}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -