All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jbpm.bpmn2.xml.WorkItemNodeHandler Maven / Gradle / Ivy

There is a newer version: 7.74.1.Final
Show newest version
/**
 * Copyright 2010 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jbpm.bpmn2.xml;

import java.util.Map;

import org.drools.compiler.compiler.xml.XmlDumper;
import org.jbpm.workflow.core.Node;
import org.jbpm.workflow.core.node.WorkItemNode;
import org.xml.sax.Attributes;

public class WorkItemNodeHandler extends AbstractNodeHandler {
    
    protected Node createNode(Attributes attrs) {
        throw new IllegalArgumentException("Reading in should be handled by specific handlers");
    }
    
    @SuppressWarnings("unchecked")
	public Class generateNodeFor() {
        return WorkItemNode.class;
    }

	public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
		WorkItemNode workItemNode = (WorkItemNode) node;
		String type = workItemNode.getWork().getName();
		if ("Manual Task".equals(type)) {
		    writeNode("manualTask", workItemNode, xmlDump, metaDataType);
		    xmlDump.append(">" + EOL);
			writeExtensionElements(workItemNode, xmlDump);
	        endNode("manualTask", xmlDump);
	        return;
		} 
        if ("Service Task".equals(type)) {
            writeNode("serviceTask", workItemNode, xmlDump, metaDataType);
            String impl = "Other";
            if (workItemNode.getWork().getParameter("implementation") != null) {
                impl = (String) workItemNode.getWork().getParameter("implementation");
            }
            xmlDump.append("operationRef=\"" + 
                XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_ServiceOperation\" implementation=\""+impl+"\" >" + EOL);
    		writeExtensionElements(workItemNode, xmlDump);
    		xmlDump.append(
                "      " + EOL +
                "        " + EOL +
                "        " + EOL +
                "        " + EOL +
                "          " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param" + EOL +
                "        " + EOL +
                "        " + EOL +
                "          " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result" + EOL +
                "        " + EOL +
                "      " + EOL);
            String inMapping = workItemNode.getInMapping("Parameter");
            if (inMapping != null) {
                xmlDump.append(
                    "      " + EOL +
                    "        " + XmlDumper.replaceIllegalChars(inMapping) + "" + EOL +
                    "        " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param" + EOL +
                    "      " + EOL);
            }
            String outMapping = workItemNode.getOutMapping("Result");
            if (outMapping != null) {
                xmlDump.append(
                    "      " + EOL +
                    "        " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result" + EOL +
                    "        " + XmlDumper.replaceIllegalChars(outMapping) + "" + EOL +
                    "      " + EOL);
            }
            endNode("serviceTask", xmlDump);
            return;
        } 
        if ("Send Task".equals(type)) {
            writeNode("sendTask", workItemNode, xmlDump, metaDataType);
            xmlDump.append("messageRef=\"" + 
                XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_Message\" implementation=\"Other\" >" + EOL);
    		writeExtensionElements(workItemNode, xmlDump);
    		xmlDump.append(
                "      " + EOL +
                "        " + EOL +
                "        " + EOL +
                "          " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param" + EOL +
                "        " + EOL +
                "        " + EOL +
                "      " + EOL);
            String inMapping = workItemNode.getInMapping("Message");
            if (inMapping != null) {
                xmlDump.append(
                    "      " + EOL +
                    "        " + XmlDumper.replaceIllegalChars(inMapping) + "" + EOL +
                    "        " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param" + EOL +
                    "      " + EOL);
            }
            endNode("sendTask", xmlDump);
            return;
        } 
        if ("Receive Task".equals(type)) {
            writeNode("receiveTask", workItemNode, xmlDump, metaDataType);
            String messageId = (String) workItemNode.getWork().getParameter("MessageId");
            xmlDump.append("messageRef=\"" + 
                messageId + "\" implementation=\"Other\" >" + EOL);
    		writeExtensionElements(workItemNode, xmlDump);
    		xmlDump.append(
                "      " + EOL +
                "        " + EOL +
                "        " + EOL +
                "        " + EOL +
                "          " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result" + EOL +
                "        " + EOL +
                "      " + EOL);
            String outMapping = workItemNode.getOutMapping("Message");
            if (outMapping != null) {
                xmlDump.append(
                    "      " + EOL +
                    "        " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result" + EOL +
                    "        " + XmlDumper.replaceIllegalChars(outMapping) + "" + EOL +
                    "      " + EOL);
            }
            endNode("receiveTask", xmlDump);
            return;
        } 
		writeNode("task", workItemNode, xmlDump, metaDataType);
		Object isForCompensationObject = workItemNode.getMetaData("isForCompensation");
        if( isForCompensationObject != null && ((Boolean) isForCompensationObject) ) { 
            xmlDump.append("isForCompensation=\"true\" ");
        }	
		xmlDump.append("tns:taskName=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\" >" + EOL);
		writeExtensionElements(workItemNode, xmlDump);
		writeIO(workItemNode, xmlDump);
		endNode("task", xmlDump);
	}
	
	protected void writeIO(WorkItemNode workItemNode, StringBuilder xmlDump) {
		xmlDump.append("      " + EOL);
		for (Map.Entry entry: workItemNode.getInMappings().entrySet()) {
			xmlDump.append("        " + EOL);
		}
		for (Map.Entry entry: workItemNode.getWork().getParameters().entrySet()) {
			if (entry.getValue() != null) {
				xmlDump.append("        " + EOL);
			}
		}
		for (Map.Entry entry: workItemNode.getOutMappings().entrySet()) {
			xmlDump.append("        " + EOL);
		}
		xmlDump.append("        " + EOL);
		for (Map.Entry entry: workItemNode.getInMappings().entrySet()) {
			xmlDump.append("          " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(entry.getKey()) + "Input" + EOL);
		}
		for (Map.Entry entry: workItemNode.getWork().getParameters().entrySet()) {
			if (entry.getValue() != null) {
				xmlDump.append("          " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + XmlDumper.replaceIllegalChars(entry.getKey()) + "Input" + EOL);
			}
		}
		xmlDump.append(
			"        " + EOL);
		xmlDump.append("        " + EOL);
		for (Map.Entry entry: workItemNode.getOutMappings().entrySet()) {
			xmlDump.append("          " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + XmlDumper.replaceIllegalChars(entry.getKey()) + "Output" + EOL);
		}
		xmlDump.append(
			"        " + EOL);
		xmlDump.append(
			"      " + EOL);
		writeInputAssociation(workItemNode, xmlDump);
        writeOutputAssociation(workItemNode, xmlDump);
	}
	
	protected void writeInputAssociation(WorkItemNode workItemNode, StringBuilder xmlDump) {
		for (Map.Entry entry: workItemNode.getInMappings().entrySet()) {
			xmlDump.append("      " + EOL);
			xmlDump.append(
				"        " + XmlDumper.replaceIllegalChars(entry.getValue()) + "" + EOL +
				"        " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + XmlDumper.replaceIllegalChars(entry.getKey()) + "Input" + EOL);
			xmlDump.append("      " + EOL);
		}
		for (Map.Entry entry: workItemNode.getWork().getParameters().entrySet()) {
			if (entry.getValue() != null) {
				xmlDump.append("      " + EOL);
				xmlDump.append(
					"        " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + XmlDumper.replaceIllegalChars(entry.getKey()) + "Input" + EOL +
					"        " + EOL +
					"          " + XmlDumper.replaceIllegalChars(entry.getValue().toString()) + "" + EOL +
					"          " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + XmlDumper.replaceIllegalChars(entry.getKey()) + "Input" + EOL +
					"        " + EOL);
				xmlDump.append("      " + EOL);
			}
		}
	}
	
    protected void writeOutputAssociation(WorkItemNode workItemNode, StringBuilder xmlDump) {
		for (Map.Entry entry: workItemNode.getOutMappings().entrySet()) {
			xmlDump.append("      " + EOL);
			xmlDump.append(
				"        " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + XmlDumper.replaceIllegalChars(entry.getKey()) + "Output" + EOL +
				"        " + XmlDumper.replaceIllegalChars(entry.getValue()) + "" + EOL);
			xmlDump.append("      " + EOL);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy