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

org.drools.bpmn2.xml.EventNodeHandler Maven / Gradle / Ivy

There is a newer version: 5.1.1
Show newest version
/**
 * 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.process.core.event.EventTypeFilter;
import org.drools.workflow.core.Node;
import org.drools.workflow.core.node.EventNode;
import org.xml.sax.Attributes;

public class EventNodeHandler extends AbstractNodeHandler {
    
    protected Node createNode(Attributes attrs) {
        throw new IllegalArgumentException("Reading in should be handled by intermediate catch event handler");
    }
    
    @SuppressWarnings("unchecked")
	public Class generateNodeFor() {
        return EventNode.class;
    }

	public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
		EventNode eventNode = (EventNode) node;
		String attachedTo = (String) eventNode.getMetaData("AttachedTo");
		if (attachedTo == null) {
    		writeNode("intermediateCatchEvent", eventNode, xmlDump, includeMeta);
    		xmlDump.append(">" + EOL);
    		if (eventNode.getVariableName() != null) {
    			xmlDump.append("      " + EOL);
    			xmlDump.append("      " + EOL);
    			xmlDump.append(
    				"      " + XmlBPMNProcessDumper.getUniqueNodeId(eventNode) + "_Output" + EOL +
    				"      " + XmlDumper.replaceIllegalChars(eventNode.getVariableName()) + "" + EOL);
    			xmlDump.append("      " + EOL);
    			xmlDump.append("      " + EOL);
    			xmlDump.append("        " + XmlBPMNProcessDumper.getUniqueNodeId(eventNode) + "_Output" + EOL);
    			xmlDump.append("      " + EOL);
    		}
    		if (eventNode.getEventFilters().size() > 0) {
    			String type = ((EventTypeFilter) eventNode.getEventFilters().get(0)).getType();
    			if (type.startsWith("Message-")) {
    			    type = type.substring(8);
    			    xmlDump.append("      " + EOL);
                } else {
                    xmlDump.append("      " + EOL);
                }
    		}
    		endNode("intermediateCatchEvent", xmlDump);
		} else {
		    String type = ((EventTypeFilter) eventNode.getEventFilters().get(0)).getType();
		    if (type.startsWith("Escalation-")) {
    		    type = type.substring(attachedTo.length() + 12);
    		    boolean cancelActivity = (Boolean) eventNode.getMetaData("CancelActivity");
                writeNode("boundaryEvent", eventNode, xmlDump, includeMeta);
    		    xmlDump.append("attachedToRef=\"" + attachedTo + "\" ");
    		    if (!cancelActivity) {
    		        xmlDump.append("cancelActivity=\"false\" ");
    		    }
    		    xmlDump.append(">" + EOL);
    		    xmlDump.append("      " + EOL);
    		    endNode("boundaryEvent", xmlDump);
		    } else if (type.startsWith("Error-")) {
                type = type.substring(attachedTo.length() + 7);
                writeNode("boundaryEvent", eventNode, xmlDump, includeMeta);
                xmlDump.append("attachedToRef=\"" + attachedTo + "\" ");
                xmlDump.append(">" + EOL);
                xmlDump.append("      " + EOL);
                endNode("boundaryEvent", xmlDump);
            } else if (type.startsWith("Timer-")) {
                type = type.substring(attachedTo.length() + 7);
                boolean cancelActivity = (Boolean) eventNode.getMetaData("CancelActivity");
                writeNode("boundaryEvent", eventNode, xmlDump, includeMeta);
                xmlDump.append("attachedToRef=\"" + attachedTo + "\" ");
                if (!cancelActivity) {
                    xmlDump.append("cancelActivity=\"false\" ");
                }
                xmlDump.append(">" + EOL);
                xmlDump.append(
                    "      " + EOL +
                    "        " + XmlDumper.replaceIllegalChars((String) eventNode.getMetaData("TimeCycle")) + "" + EOL +
                    "      " + EOL);
                endNode("boundaryEvent", xmlDump);
            } else if (type.startsWith("Compensate-")) {
                type = type.substring(attachedTo.length() + 7);
                writeNode("boundaryEvent", eventNode, xmlDump, includeMeta);
                xmlDump.append("attachedToRef=\"" + attachedTo + "\" ");
                xmlDump.append(">" + EOL);
                xmlDump.append("      " + EOL);
                endNode("boundaryEvent", xmlDump);
            } 
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy