📄 xmlworkitemcoder.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: XmlWorkItemCoder.java,v 1.16 2005/06/30 12:05:14 jmettraux Exp $ *///// XmlWorkItemCoder.java//// john.mettraux@openwfe.org//// generated with // jtmpl 1.0.04 31.10.2002 John Mettraux (jmettraux@openwfe.org)//package openwfe.org.engine.impl.workitem.xml;import openwfe.org.Utils;import openwfe.org.ApplicationContext;import openwfe.org.xml.XmlUtils;import openwfe.org.time.Time;import openwfe.org.engine.listen.reply.ListenerReplyCoder;import openwfe.org.engine.workitem.WorkItem;import openwfe.org.engine.workitem.CancelItem;import openwfe.org.engine.workitem.LaunchItem;import openwfe.org.engine.workitem.InFlowWorkItem;import openwfe.org.engine.workitem.WorkItemCoder;import openwfe.org.engine.workitem.CodingException;import openwfe.org.engine.workitem.HistoryItem;import openwfe.org.engine.workitem.Attribute;import openwfe.org.engine.workitem.AttributeCoder;import openwfe.org.engine.workitem.StringMapAttribute;import openwfe.org.engine.expressions.FlowExpressionId;import openwfe.org.engine.participants.Filter;import openwfe.org.engine.participants.FilterEntry;import openwfe.org.engine.impl.workitem.AbstractWorkItemCoder;/** * Sharing knowledge about xml {en|de}coding in the class * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Date: 2005/06/30 12:05:14 $ * <br>$Id: XmlWorkItemCoder.java,v 1.16 2005/06/30 12:05:14 jmettraux Exp $ </font> * * @author john.mettraux@openwfe.org */public class XmlWorkItemCoder extends AbstractWorkItemCoder{ private final static org.apache.log4j.Logger log = org.apache.log4j.Logger .getLogger(XmlWorkItemCoder.class.getName()); // // CONSTANTS & co public final static String WORKFLOW_DEFINITION_URL = "workflow-definition-url"; public final static String WORKFLOW_DEFINITION_NAME = "workflow-definition-name"; public final static String WORKFLOW_DEFINITION_REVISION = "workflow-definition-revision"; public final static String WORKFLOW_INSTANCE_ID = "workflow-instance-id"; public final static String LAST_MODIFIED = "last-modified"; public final static String SIGNER = "signer"; public final static String SIGNATURE = "signature"; public final static String ATTRIBUTES = "attributes"; public final static String PARTICIPANT_NAME = "participant-name"; public final static String DISPATCH_TIME = "dispatch-time"; public final static String LAST_EXPRESSION_ID = "last-expression-id"; public final static String LAUNCHITEM = "launchitem"; public final static String CANCELITEM = "cancelitem"; public final static String WORKITEM = "workitem"; public final static String DESCRIPTION_MAP = "description-map"; public final static String FLOW_EXPRESSION_ID = "flow-expression-id"; public final static String ENGINE_ID = "engine-id"; public final static String INITIAL_ENGINE_ID = "initial-engine-id"; public final static String EXPRESSION_NAME = "expression-name"; public final static String EXPRESSION_ID = "expression-id"; public final static String OPEN_FILTER = "open-filter"; public final static String CLOSED_FILTER = "closed-filter"; public final static String REGEX = "regex"; public final static String PERMISSIONS = "permissions"; public final static String TYPE = "type"; public final static String NAME = "name"; public final static String ADD_ALLOWED = "add-allowed"; public final static String REMOVE_ALLOWED = "remove-allowed"; public final static String READ_WRITE = "read-write"; public final static String READ_ONLY = "read-only"; public final static String HIDE = "hide"; public final static String FIELD = "field"; public final static String HISTORY = "history"; public final static String HISTORY_ITEM = "history-item"; public final static String DATE = "date"; public final static String AUTHOR = "author"; public final static String HOST = "host"; public final static int BUFFER_SIZE = 128 * 1024; /** * The short name (encoded name) for StringMapAttribute */ public final static String SMAP = "smap"; // // FIELDS protected ApplicationContext applicationContext = null; protected java.util.Map perRepresentationMap = null; // // CONSTRUCTORS public void init (final String name, final java.util.List attributeCoders, final ListenerReplyCoder replyCoder) { super.init(name, attributeCoders, replyCoder); this.perRepresentationMap = new java.util.HashMap(attributeCoders.size()); java.util.Iterator it = attributeCoders.iterator(); while (it.hasNext()) { AbstractXmlAttributeCoder coder = (AbstractXmlAttributeCoder)it.next(); this.perRepresentationMap.put (coder.getRepresentationName(), coder); log.debug ("init() put '"+coder.getClass().getName()+ "' for '"+coder.getRepresentationName()+"'"); } } // // METHODS public AbstractXmlAttributeCoder getAttributeCoder (final String representationName) { return (AbstractXmlAttributeCoder)perRepresentationMap .get(representationName); } // // ENCODING // public Object encode (final WorkItem wi, final ApplicationContext context, final java.util.Map serviceParams) throws CodingException { this.applicationContext = context; org.jdom.Element eWi = encodeAsXml(wi); try { return XmlUtils.toByteArray(eWi); } catch (openwfe.org.OpenWfeException owe) { throw new CodingException ("Failed to turn encoded workitem into a byte array", owe); } } protected org.jdom.Element encodeSuper (WorkItem wi) throws CodingException { org.jdom.Element elt = new org.jdom.Element(WORKITEM); /* WicUtils.setAttribute (elt, WORKFLOW_DEFINITION_URL, wi.getWorkflowDefinitionUrl()); */ if (wi.getLastModified() != null) WicUtils.setAttribute(elt, LAST_MODIFIED, wi.getLastModified()); //elt.addContent(encodeFlowStack(wi.getFlowStack())); // // attributes org.jdom.Element as = new org.jdom.Element(ATTRIBUTES); org.jdom.Element smap = encodeAttribute(wi.getAttributes()); if (smap != null) as.addContent(smap); elt.addContent(as); // // the end return elt; } public org.jdom.Element encodeAsXml (final WorkItem wi) throws CodingException { if (wi instanceof InFlowWorkItem) return encodeAsXml((InFlowWorkItem)wi); if (wi instanceof LaunchItem) return encodeAsXml((LaunchItem)wi); else return encodeCancelItemAsXml((CancelItem)wi); } protected org.jdom.Element encodeCancelItemAsXml (CancelItem ci) throws CodingException { org.jdom.Element elt = encodeSuper(ci); elt.setName(CANCELITEM); // // expressionId org.jdom.Element ei = new org.jdom.Element(LAST_EXPRESSION_ID); ei.addContent(encode(ci.getLastExpressionId())); elt.addContent(ei); // // participant name WicUtils.setAttribute (elt, PARTICIPANT_NAME, ci.getParticipantName()); // // done return elt; } protected org.jdom.Element encodeAsXml (InFlowWorkItem wi) throws CodingException { org.jdom.Element elt = encodeSuper(wi); //elt.setName(WORKITEM); WicUtils.setAttribute (elt, PARTICIPANT_NAME, wi.getParticipantName()); WicUtils.setAttribute (elt, DISPATCH_TIME, ""+wi.getDispatchTime()); // // lastExpressionId if (wi.getLastExpressionId() != null) { org.jdom.Element lei = new org.jdom.Element(LAST_EXPRESSION_ID); lei.addContent(encode(wi.getLastExpressionId())); elt.addContent(lei); } // // filter if (wi.getFilter() != null) { elt.addContent(encode(wi.getFilter())); } // // history org.jdom.Element his = new org.jdom.Element(HISTORY); if (wi.getHistory() != null) { java.util.Iterator it = wi.getHistory().iterator(); while (it.hasNext()) his.addContent(encodeAsXml((HistoryItem)it.next())); } elt.addContent(his); return elt; } public org.jdom.Element encodeAsXml (HistoryItem hi) { org.jdom.Element elt = new org.jdom.Element(HISTORY_ITEM); elt.setAttribute (DATE, ""+hi.getDate()); elt.setAttribute (AUTHOR, ""+hi.getAuthor()); elt.setAttribute (HOST, ""+hi.getHost()); elt.setAttribute (WORKFLOW_DEFINITION_NAME, ""+hi.getWorkflowDefinitionName()); elt.setAttribute (WORKFLOW_DEFINITION_REVISION, ""+hi.getWorkflowDefinitionRevision()); elt.setAttribute (WORKFLOW_INSTANCE_ID, ""+hi.getWorkflowInstanceId()); elt.setAttribute (EXPRESSION_ID, ""+hi.getExpressionId()); elt.setText(hi.getText()); return elt; } protected org.jdom.Element encodeAsXml (LaunchItem li) throws CodingException { org.jdom.Element elt = encodeSuper(li); elt.setName(LAUNCHITEM); // // wfdUrl elt.setAttribute (WORKFLOW_DEFINITION_URL, li.getWorkflowDefinitionUrl()); // // description map org.jdom.Element dm = new org.jdom.Element(DESCRIPTION_MAP); if (li.getDescriptionMap() != null) dm.addContent(encodeAttribute(li.getDescriptionMap())); elt.addContent(dm); return elt; } protected org.jdom.Element encodeAttribute (Attribute a) throws CodingException { if (a == null) return null; AttributeCoder coder = (AttributeCoder)this.perClassMap .get(a.getClass().getName()); if (coder == null) { org.jdom.Element elt = new org.jdom.Element("error"); org.jdom.Comment cmt = new org.jdom.Comment ("No coder for Attribute of class '"+ a.getClass().getName()+"'"); elt.addContent(cmt); return elt; } return (org.jdom.Element)coder.encode(a, null); } public org.jdom.Element encode (final FlowExpressionId fei) { final org.jdom.Element elt = new org.jdom.Element(FLOW_EXPRESSION_ID); WicUtils.setAttribute (elt, ENGINE_ID, fei.getEngineId()); WicUtils.setAttribute (elt, INITIAL_ENGINE_ID, fei.getInitialEngineId()); WicUtils.setAttribute (elt, WORKFLOW_DEFINITION_URL, fei.getWorkflowDefinitionUrl()); WicUtils.setAttribute (elt, WORKFLOW_DEFINITION_NAME, fei.getWorkflowDefinitionName()); WicUtils.setAttribute (elt, WORKFLOW_DEFINITION_REVISION, fei.getWorkflowDefinitionRevision()); WicUtils.setAttribute (elt, WORKFLOW_INSTANCE_ID, ""+fei.getWorkflowInstanceId()); WicUtils.setAttribute (elt, EXPRESSION_NAME, fei.getExpressionName()); WicUtils.setAttribute (elt, EXPRESSION_ID, ""+fei.getExpressionId()); return elt; } /** * This method is public because it is used by * openwfe.org.wfibuilder.WorkflowDefinition.outputAsXml() */ public org.jdom.Element encode (Filter f) { org.jdom.Element elt = null; if (f.getType() == Filter.TYPE_OPEN) elt = new org.jdom.Element(OPEN_FILTER);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -