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

org.yaoqiang.bpmn.model.elements.collaboration.Collaboration Maven / Gradle / Ivy

package org.yaoqiang.bpmn.model.elements.collaboration;

import java.util.List;

import org.yaoqiang.bpmn.model.elements.XMLAttribute;
import org.yaoqiang.bpmn.model.elements.XMLElement;
import org.yaoqiang.bpmn.model.elements.XMLTextElements;
import org.yaoqiang.bpmn.model.elements.artifacts.Artifacts;
import org.yaoqiang.bpmn.model.elements.conversations.ConversationLink;
import org.yaoqiang.bpmn.model.elements.conversations.ConversationLinks;
import org.yaoqiang.bpmn.model.elements.conversations.ConversationNode;
import org.yaoqiang.bpmn.model.elements.conversations.ConversationNodes;
import org.yaoqiang.bpmn.model.elements.core.common.CorrelationKeys;
import org.yaoqiang.bpmn.model.elements.core.foundation.BaseElement;
import org.yaoqiang.bpmn.model.elements.core.foundation.RootElement;
import org.yaoqiang.bpmn.model.elements.core.foundation.RootElements;

/**
 * Collaboration
 * 
 * @author Shi Yaoqiang([email protected])
 */
public class Collaboration extends BaseElement implements RootElement {

	private static final long serialVersionUID = -5977637447958690788L;

	public Collaboration(RootElements parent) {
		super(parent, "collaboration");
	}

	public Collaboration(RootElements parent, String name) {
		super(parent, name);
	}

	protected void fillStructure() {
		XMLAttribute attrName = new XMLAttribute(this, "name");
		XMLAttribute attrIsClosed = new XMLAttribute(this, "isClosed", Boolean.FALSE.toString());
		Participants refParticipants = new Participants(this);
		MessageFlows refMessageFlows = new MessageFlows(this);
		Artifacts refArtifacts = new Artifacts(this);
		ConversationNodes refConversations = new ConversationNodes(this);
		ConversationAssociations refConversationAssociations = new ConversationAssociations(this);
		ParticipantAssociations refParticipantAssociations = new ParticipantAssociations(this);
		MessageFlowAssociations refMessageFlowAssociations = new MessageFlowAssociations(this);
		CorrelationKeys refCorrelationKeys = new CorrelationKeys(this);
		XMLTextElements refChoreographyRef = new XMLTextElements(this, "choreographyRef");
		ConversationLinks refConversationLinks = new ConversationLinks(this);

		super.fillStructure();
		add(attrName);
		add(attrIsClosed);
		add(refParticipants);
		add(refMessageFlows);
		add(refArtifacts);
		add(refConversations);
		add(refConversationAssociations);
		add(refParticipantAssociations);
		add(refMessageFlowAssociations);
		add(refCorrelationKeys);
		add(refChoreographyRef);
		add(refConversationLinks);
	}

	public final Participants getParticipants() {
		return (Participants) get("participants");
	}
	
	public final List getParticipantList() {
		return getParticipants().getXMLElements();
	}
	
	public final MessageFlows getMessageFlows() {
		return (MessageFlows) get("messageFlows");
	}

	public final List getMessageFlowList() {
		return getMessageFlows().getXMLElements();
	}
	
	public final Artifacts getArtifacts() {
		return (Artifacts) get("artifacts");
	}

	public final ConversationNodes getConversationNodes() {
		return (ConversationNodes) get("conversationNodes");
	}
	
	public final ConversationLinks getConversationLinks() {
		return (ConversationLinks) get("conversationLinks");
	}
	
	public final Participant addParticipant(String id, String name) {
		Participant participant = (Participant) getParticipants().getCollectionElement(id);
		if (participant != null) {
			return participant;
		}
		participant = (Participant) getParticipants().generateNewElement();
		participant.setId(id);
		participant.setName(name);
		getParticipants().add(participant);
		return participant;
	}
	
	public final void addParticipant(Participant participant) {
		getParticipants().add(participant);
	}

	public final void removeParticipant(String partId) {
		getParticipants().remove(partId);
	}

	public final MessageFlow addMessageFlow(String id, String sourceRef, String targetRef) {
		MessageFlow messageFlow = (MessageFlow) getMessageFlows().generateNewElement();
		messageFlow.setId(id);
		messageFlow.setSourceRef(sourceRef);
		messageFlow.setTargetRef(targetRef);
		getMessageFlows().add(messageFlow);
		return messageFlow;
	}
	
	public final ConversationNode addConversationNode(String type, String id, String name) {
		getConversationNodes().setType(type);
		ConversationNode conversationNode = (ConversationNode) getConversationNodes().generateNewElement();
		conversationNode.setId(id);
		conversationNode.setName(name);
		getConversationNodes().add(conversationNode);
		return conversationNode;
	}

	public final void addConversationNode(ConversationNode conversationNode) {
		getConversationNodes().add(conversationNode);
	}
	
	public final ConversationLink addConversationLink(String id, String sourceRef, String targetRef) {
		ConversationLink conversationLink = (ConversationLink) getConversationLinks().generateNewElement();
		conversationLink.setId(id);
		conversationLink.setSourceRef(sourceRef);
		conversationLink.setTargetRef(targetRef);
		getConversationLinks().add(conversationLink);
		return conversationLink;
	}
	
	public final void addArtifacts(Artifacts artifacts) {
		for(XMLElement arti: artifacts.getXMLElements()) {
			getArtifacts().add(arti);
		}
		artifacts.clear();
	}
	
	public final void addArtifact(XMLElement artifact) {
		getArtifacts().add(artifact);
	}

	public boolean isEmpty() {
		boolean isEmpty = true;
		for(XMLElement el: getXMLElements()) {
			if (el instanceof Artifacts) {
				continue;
			}
			isEmpty = isEmpty && el.isEmpty();
		}
		return isEmpty;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy