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

org.jbpt.pm.bpmn.BpmnControlFlow Maven / Gradle / Ivy

/**
 * 
 */
package org.jbpt.pm.bpmn;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.jbpt.graph.abs.AbstractDirectedGraph;
import org.jbpt.graph.abs.IDirectedEdge;
import org.jbpt.hypergraph.abs.IVertex;
import org.jbpt.pm.ControlFlow;
import org.jbpt.pm.IDataNode;
import org.jbpt.pm.IFlowNode;


/**
 * Class for BPMN Control Flow element.In BPMN, there exists a notation element called Attached 
 * Intermediate Event, where an event is directly connected to an Activity. This violates jBPTs 
 * condition that all vertexes have to be connected by edges with each other. To avoid this violation, 
 * we simply add the attached event to the ControlFlow object.
 * @author Cindy Fähnrich
 *
 */
public class BpmnControlFlow extends ControlFlow implements IBpmnControlFlow {

	private Set readDocuments = new HashSet();
	private Set writeDocuments = new HashSet();
	private Set unspecifiedDocuments = new HashSet();
	
	/**
	 * Parameter for attached event. There can only exist one attached event for a control flow.
	 */
	private BpmnEvent attachedEvent = null;
	/**
	 * Denotes the condition of the current control flow object. If the phrase is empty, this is a 
	 * default control flow.
	 */
	private String condition = null;
	
	private boolean defaultFlow = false;
	
	public BpmnControlFlow(AbstractDirectedGraph g, V source, V target) {
		super(g, source, target);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void addReadDocument(IDataNode document) {
		this.readDocuments.add(document);
		//31.07.2012 Temporary Remove
		//document.addReadingFlow((IDirectedEdge) this);
	}

	@Override
	public void addReadWriteDocument(IDataNode document) {
		this.readDocuments.add(document);
		this.writeDocuments.add(document);
	}

	@Override
	public void addUnspecifiedDocument(IDataNode document) {
		this.unspecifiedDocuments.add(document);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void addWriteDocument(IDataNode document) {
		this.writeDocuments.add(document);
		//31.07.2012 Temporary Remove
		//document.addWritingFlow((IDirectedEdge) this);
	}

	@Override
	public void attachEvent(BpmnEvent event) {
		this.attachedEvent = event;
		if(event != null) {
			event.setAttached(true);
		}
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public BpmnControlFlow clone() {
		BpmnControlFlow clone = (BpmnControlFlow) super.clone();
		if (this.condition != null){
			clone.condition = new String(this.condition);
		}
		if (this.attachedEvent != null) {
			clone.attachedEvent = (BpmnEvent) this.attachedEvent.clone(); 
		}
		clone.readDocuments = (Set) ((HashSet) this.readDocuments).clone();
		clone.writeDocuments = (Set) ((HashSet) this.writeDocuments).clone();
		clone.unspecifiedDocuments = (Set) ((HashSet) this.unspecifiedDocuments).clone();
				
		return clone;
	}

	@Override
	public BpmnEvent detachEvent() {
		BpmnEvent result = this.attachedEvent;
		this.attachedEvent = null;
		return result;		
	}

	@Override
	public BpmnEvent getAttachedEvent() {
		return this.attachedEvent;
	}

	@Override
	public String getCondition() {
		return this.condition;
	}

	@Override
	public Collection getReadDocuments() {
		return this.readDocuments;
	}

	@Override
	public Collection getReadWriteDocuments() {
		Collection result = new ArrayList();
		result.addAll(this.readDocuments);
		result.retainAll(this.writeDocuments);
		return result;
	}

	@Override
	public Collection getWriteDocuments() {
		return this.writeDocuments;
	}

	@Override
	public Collection getUnspecifiedDocuments() {
		return this.unspecifiedDocuments;
	}

	@Override
	public boolean hasAttachedEvent() {
		return this.attachedEvent != null ? true : false;
	}

	@Override
	public boolean hasCondition() {
		return (this.condition != null);
	}

	@Override
	public boolean isDefault(){
		return this.defaultFlow;
	}

	@Override
	public void setCondition(String condition) {
		this.condition = condition;		
	}

	@Override
	public void setDefault(){
		this.defaultFlow = true;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy