Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.jbpm.compiler.xml.XmlWorkflowProcessDumper Maven / Gradle / Ivy
/*
* Copyright 2017 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.compiler.xml;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.drools.compiler.compiler.xml.XmlDumper;
import org.kie.api.definition.process.Connection;
import org.kie.api.definition.process.Node;
import org.kie.api.definition.process.WorkflowProcess;
import org.jbpm.process.core.datatype.DataType;
import org.jbpm.process.core.datatype.impl.type.ObjectDataType;
import org.drools.core.xml.Handler;
import org.drools.core.xml.SemanticModule;
import org.jbpm.compiler.xml.processes.AbstractNodeHandler;
import org.jbpm.process.core.context.exception.ActionExceptionHandler;
import org.jbpm.process.core.context.exception.ExceptionHandler;
import org.jbpm.process.core.context.exception.ExceptionScope;
import org.jbpm.process.core.context.swimlane.Swimlane;
import org.jbpm.process.core.context.swimlane.SwimlaneContext;
import org.jbpm.process.core.context.variable.Variable;
import org.jbpm.process.core.context.variable.VariableScope;
import org.jbpm.workflow.core.DroolsAction;
import org.jbpm.workflow.core.impl.NodeImpl;
public class XmlWorkflowProcessDumper {
private final static String EOL = System.getProperty( "line.separator" );
private String type;
private String namespace;
private String schemaLocation;
private SemanticModule semanticModule;
public XmlWorkflowProcessDumper(String type, String namespace, String schemaLocation, SemanticModule semanticModule) {
this.type = type;
this.namespace = namespace;
this.schemaLocation = schemaLocation;
this.semanticModule = semanticModule;
}
public String dump(WorkflowProcess process) {
return dump(process, true);
}
public String dump(WorkflowProcess process, boolean includeMeta) {
StringBuilder xmlDump = new StringBuilder();
visitProcess(process, xmlDump, includeMeta);
return xmlDump.toString();
}
protected void visitProcess(WorkflowProcess process, StringBuilder xmlDump, boolean includeMeta) {
xmlDump.append(" " + EOL
+ "" + EOL + EOL);
visitHeader(process, xmlDump, includeMeta);
visitNodes(process, xmlDump, includeMeta);
visitConnections(process.getNodes(), xmlDump, includeMeta);
xmlDump.append(" ");
}
protected void visitHeader(WorkflowProcess process, StringBuilder xmlDump, boolean includeMeta) {
xmlDump.append(" " + EOL);
visitImports(((org.jbpm.process.core.Process) process).getImports(), xmlDump);
visitGlobals(((org.jbpm.process.core.Process) process).getGlobals(), xmlDump);
visitFunctionImports(((org.jbpm.process.core.Process) process).getFunctionImports(), xmlDump);
VariableScope variableScope = (VariableScope)
((org.jbpm.process.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
if (variableScope != null) {
visitVariables(variableScope.getVariables(), xmlDump);
}
SwimlaneContext swimlaneContext = (SwimlaneContext)
((org.jbpm.process.core.Process) process).getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
if (swimlaneContext != null) {
visitSwimlanes(swimlaneContext.getSwimlanes(), xmlDump);
}
ExceptionScope exceptionScope = (ExceptionScope)
((org.jbpm.process.core.Process) process).getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
if (exceptionScope != null) {
visitExceptionHandlers(exceptionScope.getExceptionHandlers(), xmlDump);
}
xmlDump.append(" " + EOL + EOL);
}
private void visitImports(Collection imports, StringBuilder xmlDump) {
if (imports != null && imports.size() > 0) {
xmlDump.append(" " + EOL);
for (String importString: imports) {
xmlDump.append(" " + EOL);
}
xmlDump.append(" " + EOL);
}
}
private void visitFunctionImports(List imports, StringBuilder xmlDump) {
if (imports != null && imports.size() > 0) {
xmlDump.append(" " + EOL);
for (String importString: imports) {
xmlDump.append(" " + EOL);
}
xmlDump.append(" " + EOL);
}
}
private void visitGlobals(Map globals, StringBuilder xmlDump) {
if (globals != null && globals.size() > 0) {
xmlDump.append(" " + EOL);
for (Map.Entry global: globals.entrySet()) {
xmlDump.append(" " + EOL);
}
xmlDump.append(" " + EOL);
}
}
public static void visitVariables(List variables, StringBuilder xmlDump) {
if (variables != null && variables.size() > 0) {
xmlDump.append(" " + EOL);
for (Variable variable: variables) {
xmlDump.append(" " + EOL);
visitDataType(variable.getType(), xmlDump);
Object value = variable.getValue();
if (value != null) {
visitValue(variable.getValue(), variable.getType(), xmlDump);
}
xmlDump.append(" " + EOL);
}
xmlDump.append(" " + EOL);
}
}
private void visitSwimlanes(Collection swimlanes, StringBuilder xmlDump) {
if (swimlanes != null && swimlanes.size() > 0) {
xmlDump.append(" " + EOL);
for (Swimlane swimlane: swimlanes) {
xmlDump.append(" " + EOL);
}
xmlDump.append(" " + EOL);
}
}
public static void visitExceptionHandlers(Map exceptionHandlers, StringBuilder xmlDump) {
if (exceptionHandlers != null && exceptionHandlers.size() > 0) {
xmlDump.append(" " + EOL);
for (Map.Entry entry: exceptionHandlers.entrySet()) {
ExceptionHandler exceptionHandler = entry.getValue();
if (exceptionHandler instanceof ActionExceptionHandler) {
ActionExceptionHandler actionExceptionHandler = (ActionExceptionHandler) exceptionHandler;
xmlDump.append(" 0) {
xmlDump.append("faultVariable=\"" + faultVariable + "\" ");
}
xmlDump.append(">" + EOL);
DroolsAction action = actionExceptionHandler.getAction();
if (action != null) {
AbstractNodeHandler.writeAction(action, xmlDump);
}
xmlDump.append(" " + EOL);
} else {
throw new IllegalArgumentException("Unknown exception handler type: " + exceptionHandler);
}
}
xmlDump.append(" " + EOL);
}
}
public static void visitDataType(DataType dataType, StringBuilder xmlDump) {
xmlDump.append(" 0
&& !"java.lang.Object".equals(className)) {
xmlDump.append("className=\"" + className + "\" ");
}
}
xmlDump.append("/>" + EOL);
}
public static void visitValue(Object value, DataType dataType, StringBuilder xmlDump) {
xmlDump.append(" " + XmlDumper.replaceIllegalChars(dataType.writeValue(value)) + " " + EOL);
}
private void visitNodes(WorkflowProcess process, StringBuilder xmlDump, boolean includeMeta) {
xmlDump.append(" " + EOL);
for (Node node: process.getNodes()) {
visitNode(node, xmlDump, includeMeta);
}
xmlDump.append(" " + EOL + EOL);
}
public void visitNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
Handler handler = semanticModule.getHandlerByClass(node.getClass());
if (handler != null) {
((AbstractNodeHandler) handler).writeNode((org.jbpm.workflow.core.Node) node, xmlDump, includeMeta);
} else {
throw new IllegalArgumentException(
"Unknown node type: " + node);
}
}
private void visitConnections(Node[] nodes, StringBuilder xmlDump, boolean includeMeta) {
List connections = new ArrayList();
for (Node node: nodes) {
for (List connectionList: node.getIncomingConnections().values()) {
connections.addAll(connectionList);
}
}
xmlDump.append(" " + EOL);
for (Connection connection: connections) {
visitConnection(connection, xmlDump, includeMeta);
}
xmlDump.append(" " + EOL + EOL);
}
public void visitConnection(Connection connection, StringBuilder xmlDump, boolean includeMeta) {
xmlDump.append(" " + EOL);
}
}