org.drools.bpmn2.xml.ActionNodeHandler 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.xml;
import org.drools.compiler.xml.XmlDumper;
import org.drools.rule.builder.dialect.java.JavaDialect;
import org.drools.workflow.core.Node;
import org.drools.workflow.core.impl.DroolsConsequenceAction;
import org.drools.workflow.core.node.ActionNode;
import org.xml.sax.Attributes;
public class ActionNodeHandler extends AbstractNodeHandler {
protected Node createNode(Attributes attrs) {
throw new IllegalArgumentException("Reading in should be handled by specific handlers");
}
@SuppressWarnings("unchecked")
public Class generateNodeFor() {
return ActionNode.class;
}
public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
ActionNode actionNode = (ActionNode) node;
DroolsConsequenceAction action = (DroolsConsequenceAction) actionNode.getAction();
if (action != null) {
String s = action.getConsequence();
if (s.startsWith("org.drools.process.instance.impl.WorkItemImpl workItem = new org.drools.process.instance.impl.WorkItemImpl();")) {
writeNode("intermediateThrowEvent", actionNode, xmlDump, includeMeta);
xmlDump.append(">" + EOL);
String variable = (String) actionNode.getMetaData("MappingVariable");
if (variable != null) {
xmlDump.append(
" " + EOL +
" " + EOL +
" " + XmlDumper.replaceIllegalChars(variable) + " " + EOL +
" " + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input " + EOL +
" " + EOL +
" " + EOL +
" " + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input " + EOL +
" " + EOL);
}
xmlDump.append(" " + EOL);
endNode("intermediateThrowEvent", xmlDump);
} else if (s.startsWith("kcontext.getKnowledgeRuntime().signalEvent(\"")) {
writeNode("intermediateThrowEvent", actionNode, xmlDump, includeMeta);
xmlDump.append(">" + EOL);
s = s.substring(44);
String type = s.substring(0, s.indexOf("\""));
s = s.substring(s.indexOf(",") + 2);
String variable = null;
if (!s.startsWith("null")) {
variable = s.substring(0, s.indexOf(")"));
xmlDump.append(
" " + EOL +
" " + EOL +
" " + XmlDumper.replaceIllegalChars(variable) + " " + EOL +
" " + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input " + EOL +
" " + EOL +
" " + EOL +
" " + XmlBPMNProcessDumper.getUniqueNodeId(actionNode) + "_Input " + EOL +
" " + EOL);
}
if (type.startsWith("Compensate-")) {
xmlDump.append(" " + EOL);
} else {
xmlDump.append(" " + EOL);
}
endNode("intermediateThrowEvent", xmlDump);
} else if (s.startsWith("kcontext.getProcessInstance().signalEvent(\"")) {
writeNode("intermediateThrowEvent", actionNode, xmlDump, includeMeta);
xmlDump.append(">" + EOL);
s = s.substring(43);
String type = s.substring(0, s.indexOf("\""));
xmlDump.append(" " + EOL);
endNode("intermediateThrowEvent", xmlDump);
} else if (s.startsWith("org.drools.process.instance.context.exception.ExceptionScopeInstance scopeInstance = (org.drools.process.instance.context.exception.ExceptionScopeInstance) ((org.drools.workflow.instance.NodeInstance) kcontext.getNodeInstance()).resolveContextInstance(org.drools.process.core.context.exception.ExceptionScope.EXCEPTION_SCOPE, \"")) {
writeNode("intermediateThrowEvent", actionNode, xmlDump, includeMeta);
xmlDump.append(">" + EOL);
s = s.substring(327);
String type = s.substring(0, s.indexOf("\""));
xmlDump.append(" " + EOL);
endNode("intermediateThrowEvent", xmlDump);
} else if ("IntermediateThrowEvent-None".equals(actionNode.getMetaData("NodeType"))) {
writeNode("intermediateThrowEvent", actionNode, xmlDump, includeMeta);
endNode(xmlDump);
} else {
writeNode("scriptTask", actionNode, xmlDump, includeMeta);
if (JavaDialect.ID.equals(action.getDialect())) {
xmlDump.append("scriptLanguage=\"" + XmlBPMNProcessDumper.JAVA_LANGUAGE + "\" ");
}
if (action.getConsequence() != null) {
xmlDump.append(">" + EOL +
" " + EOL);
endNode("scriptTask", xmlDump);
} else {
endNode(xmlDump);
}
}
} else {
writeNode("scriptTask", actionNode, xmlDump, includeMeta);
endNode(xmlDump);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy