📄 jaxp_fpdl_parser.java.svn-base
字号:
/** * Copyright 2003-2008 陈乜云(非也,Chen Nieyun) * All rights reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation。 * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses. * */package org.fireflow.model.io;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.UUID;import java.util.logging.Level;import java.util.logging.Logger;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.ParserConfigurationException;import org.fireflow.model.DataField;import org.fireflow.model.Duration;import org.fireflow.model.EventListener;import org.fireflow.model.IWFElement;import org.fireflow.model.Task;import org.fireflow.model.WorkflowProcess;import org.fireflow.model.net.Activity;import org.fireflow.model.net.EndNode;import org.fireflow.model.net.Node;import org.fireflow.model.net.StartNode;import org.fireflow.model.net.Synchronizer;import org.fireflow.model.net.Transition;import org.fireflow.model.reference.Application;import org.fireflow.model.reference.Form;import org.fireflow.model.reference.Participant;import org.fireflow.model.reference.SubWorkflowProcess;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.xml.sax.EntityResolver;import org.xml.sax.InputSource;import org.xml.sax.SAXException;/** * * @author chennieyun */public class JAXP_FPDL_Parser implements FPDLNames { public WorkflowProcess parse(InputStream in) throws IOException, FPDLParserException { try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setValidating(false); docBuilderFactory.setNamespaceAware(true); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); docBuilder.setEntityResolver(new EntityResolver() { String emptyDtd = ""; ByteArrayInputStream bytels = new ByteArrayInputStream(emptyDtd.getBytes()); public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return new InputSource(bytels); } }); Document w3cDoc = docBuilder.parse(in); return parse(w3cDoc); } catch (SAXException ex) { Logger.getLogger(JAXP_FPDL_Parser.class.getName()).log(Level.SEVERE, null, ex); throw new FPDLParserException(ex.getMessage()); } catch (ParserConfigurationException ex) { Logger.getLogger(JAXP_FPDL_Parser.class.getName()).log(Level.SEVERE, null, ex); throw new FPDLParserException(ex.getMessage()); } } public WorkflowProcess parse(Document document) throws FPDLParserException { Element workflowProcessElement = document.getDocumentElement(); WorkflowProcess wp = new WorkflowProcess(workflowProcessElement.getAttribute(NAME)); wp.setDescription(Util4JAXPParser.elementAsString(workflowProcessElement, DESCRIPTION)); wp.setDisplayName(workflowProcessElement.getAttribute(DISPLAY_NAME)); wp.setResourceFile(workflowProcessElement.getAttribute(RESOURCE_FILE)); wp.setResourceManager(workflowProcessElement.getAttribute(RESOURCE_MANAGER)); this.loadDataFields(wp, wp.getDataFields(), Util4JAXPParser.child( workflowProcessElement, DATA_FIELDS)); loadStartNode(wp, Util4JAXPParser.child(workflowProcessElement, START_NODE)); loadActivities(wp, wp.getActivities(), Util4JAXPParser.child( workflowProcessElement, ACTIVITIES)); loadSynchronizers(wp, wp.getSynchronizers(), Util4JAXPParser.child( workflowProcessElement, SYNCHRONIZERS)); loadEndNodes(wp, wp.getEndNodes(), Util4JAXPParser.child( workflowProcessElement, END_NODES)); loadTransitions(wp, Util4JAXPParser.child(workflowProcessElement, TRANSITIONS)); loadEventListeners(wp.getEventListeners(), Util4JAXPParser.child(workflowProcessElement, EVENT_LISTENERS)); Map<String, String> extAttrs = wp.getExtendedAttributes(); loadExtendedAttributes(extAttrs, Util4JAXPParser.child( workflowProcessElement, EXTENDED_ATTRIBUTES)); return wp; } protected void loadEventListeners(List listeners, Element element) { listeners.clear(); if (element == null) { return; } if (element == null) { return; } List listenerElms = Util4JAXPParser.children(element, EVENT_LISTENER); Iterator iter = listenerElms.iterator(); while (iter.hasNext()) { Element elm = (Element) iter.next(); EventListener listener = new EventListener(); listener.setClassName(elm.getAttribute(CLASS_NAME)); listeners.add(listener); } } protected void loadStartNode(WorkflowProcess wp, Element element) throws FPDLParserException { if (element == null) { return; } StartNode startNode = new StartNode(wp); startNode.setSn(UUID.randomUUID().toString()); startNode.setDescription(Util4JAXPParser.elementAsString(element, DESCRIPTION)); startNode.setDisplayName(element.getAttribute(DISPLAY_NAME)); loadExtendedAttributes(startNode.getExtendedAttributes(), Util4JAXPParser.child(element, EXTENDED_ATTRIBUTES)); wp.setStartNode(startNode); } protected void loadEndNodes(WorkflowProcess wp, List<EndNode> endNodes, Element element) throws FPDLParserException { endNodes.clear(); if (element == null) { return; } List endNodesElms = Util4JAXPParser.children(element, END_NODE); Iterator iter = endNodesElms.iterator(); while (iter.hasNext()) { Element elm = (Element) iter.next(); EndNode endNode = new EndNode(wp, elm.getAttribute(NAME)); endNode.setSn(UUID.randomUUID().toString()); endNode.setDescription(Util4JAXPParser.elementAsString(element, DESCRIPTION)); endNode.setDisplayName(element.getAttribute(DISPLAY_NAME)); loadExtendedAttributes(endNode.getExtendedAttributes(), Util4JAXPParser.child(elm, EXTENDED_ATTRIBUTES)); endNodes.add(endNode); } } protected void loadSynchronizers(WorkflowProcess wp, List<Synchronizer> synchronizers, Element element) throws FPDLParserException { synchronizers.clear(); if (element == null) { return; } List synchronizerElms = Util4JAXPParser.children(element, SYNCHRONIZER); Iterator iter = synchronizerElms.iterator(); while (iter.hasNext()) { Element elm = (Element) iter.next(); Synchronizer synchronizer = new Synchronizer(wp, elm.getAttribute(NAME)); synchronizer.setSn(UUID.randomUUID().toString()); synchronizer.setDescription(Util4JAXPParser.elementAsString(element, DESCRIPTION)); synchronizer.setDisplayName(element.getAttribute(DISPLAY_NAME)); loadExtendedAttributes(synchronizer.getExtendedAttributes(), Util4JAXPParser.child(elm, EXTENDED_ATTRIBUTES)); synchronizers.add(synchronizer); } } protected void loadActivities(WorkflowProcess wp, List<Activity> activities, Element element) throws FPDLParserException { if (element == null) { // log.debug("Activites element was null"); return; } List activitElements = Util4JAXPParser.children(element, ACTIVITY); activities.clear(); Iterator iter = activitElements.iterator(); while (iter.hasNext()) { Element activityElement = (Element) iter.next(); Activity activity = new Activity(wp, activityElement.getAttribute(NAME)); activity.setSn(UUID.randomUUID().toString()); activity.setDisplayName(activityElement.getAttribute(DISPLAY_NAME)); activity.setDescription(Util4JAXPParser.elementAsString( activityElement, DESCRIPTION)); activity.setCompletionStrategy(activityElement.getAttribute(COMPLETION_STRATEGY)); loadEventListeners(activity.getEventListeners(), Util4JAXPParser.child(activityElement, EVENT_LISTENERS)); loadExtendedAttributes(activity.getExtendedAttributes(), Util4JAXPParser.child(activityElement, EXTENDED_ATTRIBUTES)); loadTasks(activity, activity.getTasks(), Util4JAXPParser.child( activityElement, TASKS)); activities.add(activity); } } protected void loadTasks(Activity activity, List<Task> tasks, Element element) throws FPDLParserException { tasks.clear(); if (element == null) { return; } List tasksElms = Util4JAXPParser.children(element, TASK); Iterator iter = tasksElms.iterator(); while (iter.hasNext()) { Element elm = (Element) iter.next(); tasks.add(createTask(activity, elm)); } } protected Task createTask(Activity activity, Element taskElement) throws FPDLParserException { Task task = new Task(activity, taskElement.getAttribute(NAME)); task.setSn(UUID.randomUUID().toString()); task.setDisplayName(taskElement.getAttribute(DISPLAY_NAME));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -