org.drools.bpmn2.legacy.beta1.WorkItemNodeHandler Maven / Gradle / Ivy
/**
* Copyright 2010 JBoss Inc
*
* 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.drools.bpmn2.legacy.beta1;
import java.util.Map;
import org.drools.compiler.xml.XmlDumper;
import org.drools.workflow.core.Node;
import org.drools.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, boolean includeMeta) {
WorkItemNode workItemNode = (WorkItemNode) node;
String type = workItemNode.getWork().getName();
if ("Manual Task".equals(type)) {
writeNode("manualTask", workItemNode, xmlDump, includeMeta);
endNode(xmlDump);
return;
}
if ("Service Task".equals(type)) {
writeNode("serviceTask", workItemNode, xmlDump, includeMeta);
xmlDump.append("operationRef=\"" +
XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_ServiceOperation\" implementation=\"Other\" >" + EOL);
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, includeMeta);
xmlDump.append("messageRef=\"" +
XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_Message\" implementation=\"Other\" >" + EOL);
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, includeMeta);
xmlDump.append("messageRef=\"" +
XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_Message\" implementation=\"Other\" >" + EOL);
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, includeMeta);
xmlDump.append("tns:taskName=\"" + XmlDumper.replaceIllegalChars(type) + "\" >" + EOL);
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) + "_" + XmlDumper.replaceIllegalChars(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);
for (Map.Entry entry: workItemNode.getWork().getParameters().entrySet()) {
if (entry.getValue() != null) {
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(
" " + EOL +
" " + XmlDumper.replaceIllegalChars(entry.getValue().toString()) + " " + EOL +
" " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + XmlDumper.replaceIllegalChars(entry.getKey()) + "Input " + EOL +
" " + EOL +
" " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + XmlDumper.replaceIllegalChars(entry.getKey()) + " " + EOL +
" " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + XmlDumper.replaceIllegalChars(entry.getKey()) + "Input " + 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) + "_" + entry.getKey() + "Output " + EOL +
" " + XmlDumper.replaceIllegalChars(entry.getValue()) + " " + EOL);
xmlDump.append(" " + EOL);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy