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

org.activiti.bpmn.model.BpmnModel Maven / Gradle / Ivy

There is a newer version: 7.1.0.M6
Show newest version
/* 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.activiti.bpmn.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.xml.stream.XMLStreamReader;

import org.activiti.bpmn.model.parse.Problem;
import org.activiti.bpmn.model.parse.Warning;
import org.apache.commons.lang3.StringUtils;


/**
 * @author Tijs Rademakers
 */
public class BpmnModel {
  
	protected List processes = new ArrayList();
	protected Map locationMap = new LinkedHashMap();
	protected Map labelLocationMap = new LinkedHashMap();
	protected Map> flowLocationMap = new LinkedHashMap>();
	protected List signals = new ArrayList();
	protected Map messageMap = new LinkedHashMap();
	protected Map errorMap = new LinkedHashMap();
	protected Map itemDefinitionMap = new LinkedHashMap();
	protected List pools = new ArrayList();
	protected List imports = new ArrayList();
	protected List interfaces = new ArrayList();
	protected List globalArtifacts = new ArrayList();
	protected Map namespaceMap = new LinkedHashMap();
	protected String targetNamespace;
	protected int nextFlowIdCounter = 1;

	public Process getMainProcess() {
	  if (getPools().size() > 0) {
	    return getProcess(getPools().get(0).getId());
	  } else {
	    return getProcess(null);
	  }
	}

	public Process getProcess(String poolRef) {
	  for (Process process : processes) {
	    boolean foundPool = false;
	    for (Pool pool : pools) {
        if (StringUtils.isNotEmpty(pool.getProcessRef()) && pool.getProcessRef().equalsIgnoreCase(process.getId())) {
          
          if(poolRef != null) {
            if(pool.getId().equalsIgnoreCase(poolRef)) {
              foundPool = true;
            }
          } else {
            foundPool = true;
          }
        }
      }
	    
	    if(poolRef == null && foundPool == false) {
	      return process;
	    } else if(poolRef != null && foundPool == true) {
	      return process;
	    }
	  }
	  
	  return null;
  }
	
	public List getProcesses() {
	  return processes;
	}
	
	public void addProcess(Process process) {
	  processes.add(process);
	}
	
	public Pool getPool(String id) {
	  Pool foundPool = null;
	  if (StringUtils.isNotEmpty(id)) {
  	  for (Pool pool : pools) {
        if (id.equals(pool.getId())) {
          foundPool = pool;
          break;
        }
      }
	  }
	  return foundPool;
	}
	
	public Lane getLane(String id) {
	  Lane foundLane = null;
    if (StringUtils.isNotEmpty(id)) {
      for (Process process : processes) {
        for (Lane lane : process.getLanes()) {
          if (id.equals(lane.getId())) {
            foundLane = lane;
            break;
          }
        }
        if (foundLane != null) {
          break;
        }
      }
    }
    return foundLane;
  }
	
	public FlowElement getFlowElement(String id) {
	  FlowElement foundFlowElement = null;
	  for (Process process : processes) {
	    foundFlowElement = process.getFlowElement(id);
	    if (foundFlowElement != null) {
	      break;
	    }
	  }
	  
	  if (foundFlowElement == null) {
	    for (Process process : processes) {
	      for (FlowElement flowElement : process.findFlowElementsOfType(SubProcess.class)) {
	        foundFlowElement = getFlowElementInSubProcess(id, (SubProcess) flowElement);
	        if (foundFlowElement != null) {
	          break;
	        }
	      }
	      if (foundFlowElement != null) {
          break;
        }
	    }
	  }
	  
	  return foundFlowElement;
	}
	
	protected FlowElement getFlowElementInSubProcess(String id, SubProcess subProcess) {
	  FlowElement foundFlowElement = subProcess.getFlowElement(id);
    if (foundFlowElement == null) {
      for (FlowElement flowElement : subProcess.getFlowElements()) {
        if (flowElement instanceof SubProcess) {
          foundFlowElement = getFlowElementInSubProcess(id, (SubProcess) flowElement);
          if (foundFlowElement != null) {
            break;
          }
        }
      }
    }
    return foundFlowElement;
	}
	
	public Artifact getArtifact(String id) {
	  Artifact foundArtifact = null;
    for (Process process : processes) {
      foundArtifact = process.getArtifact(id);
      if (foundArtifact != null) {
        break;
      }
    }
    
    if (foundArtifact == null) {
      for (Process process : processes) {
        for (FlowElement flowElement : process.findFlowElementsOfType(SubProcess.class)) {
          foundArtifact = getArtifactInSubProcess(id, (SubProcess) flowElement);
          if (foundArtifact != null) {
            break;
          }
        }
        if (foundArtifact != null) {
          break;
        }
      }
    }
    
    return foundArtifact;
  }
  
  protected Artifact getArtifactInSubProcess(String id, SubProcess subProcess) {
    Artifact foundArtifact = subProcess.getArtifact(id);
    if (foundArtifact == null) {
      for (FlowElement flowElement : subProcess.getFlowElements()) {
        if (flowElement instanceof SubProcess) {
          foundArtifact = getArtifactInSubProcess(id, (SubProcess) flowElement);
          if (foundArtifact != null) {
            break;
          }
        }
      }
    }
    return foundArtifact;
  }
	
	public void addGraphicInfo(String key, GraphicInfo graphicInfo) {
		locationMap.put(key, graphicInfo);
	}
	
	public GraphicInfo getGraphicInfo(String key) {
		return locationMap.get(key);
	}
	
	public void removeGraphicInfo(String key) {
    locationMap.remove(key);
  }
	
	public List getFlowLocationGraphicInfo(String key) {
    return flowLocationMap.get(key);
  }
	
	public void removeFlowGraphicInfoList(String key) {
	  flowLocationMap.remove(key);
  }
	
	public Map getLocationMap() {
		return locationMap;
	}
	
	public Map> getFlowLocationMap() {
    return flowLocationMap;
  }
	
	public GraphicInfo getLabelGraphicInfo(String key) {
    return labelLocationMap.get(key);
  }
	
	public void addLabelGraphicInfo(String key, GraphicInfo graphicInfo) {
		labelLocationMap.put(key, graphicInfo);
	}
	
	public void removeLabelGraphicInfo(String key) {
	  labelLocationMap.remove(key);
  }
	
	public Map getLabelLocationMap() {
    return labelLocationMap;
  }
	
	public void addFlowGraphicInfoList(String key, List graphicInfoList) {
		flowLocationMap.put(key, graphicInfoList);
	}
	
  public Collection getSignals() {
  	return signals;
  }
  
  public void setSignals(Collection signalList) {
    if (signalList != null) {
      signals.clear();
      signals.addAll(signalList);
    }
  }
  
  public void addSignal(Signal signal) {
    if (signal != null) {
    	signals.add(signal);
    }
  }
  
  public boolean containsSignalId(String signalId) {
    return getSignal(signalId) != null;
  }
  
  public Signal getSignal(String id) {
    for (Signal signal : signals) {
    	if (id.equals(signal.getId())) {
    		return signal;
    	}
    }
    return null;
  }

  public Collection getMessages() {
    return messageMap.values();
  }
  
  public void setMessages(Collection messageList) {
    if (messageList != null) {
      messageMap.clear();
      for (Message message : messageList) {
        addMessage(message);
      }
    }
  }

  public void addMessage(Message message) {
    if (message != null && StringUtils.isNotEmpty(message.getId())) {
      messageMap.put(message.getId(), message);
    }
  }
  
  public Message getMessage(String id) {
    return messageMap.get(id);
  }
  
  public boolean containsMessageId(String messageId) {
    return messageMap.containsKey(messageId);
  }
  
  public Map getErrors() {
    return errorMap;
  }
  
  public void setErrors(Map errorMap) {
    this.errorMap = errorMap;
  }

  public void addError(String errorRef, String errorCode) {
    if (StringUtils.isNotEmpty(errorRef)) {
      errorMap.put(errorRef, errorCode);
    }
  }
  
  public boolean containsErrorRef(String errorRef) {
    return errorMap.containsKey(errorRef);
  }
  
  public Map getItemDefinitions() {
    return itemDefinitionMap;
  }
  
  public void setItemDefinitions(Map itemDefinitionMap) {
    this.itemDefinitionMap = itemDefinitionMap;
  }

  public void addItemDefinition(String id, ItemDefinition item) {
    if (StringUtils.isNotEmpty(id)) {
      itemDefinitionMap.put(id, item);
    }
  }
  
  public boolean containsItemDefinitionId(String id) {
    return itemDefinitionMap.containsKey(id);
  }

  public List getPools() {
    return pools;
  }
  
  public void setPools(List pools) {
    this.pools = pools;
  }
  
  public List getImports() {
    return imports;
  }

  public void setImports(List imports) {
    this.imports = imports;
  }

  public List getInterfaces() {
    return interfaces;
  }

  public void setInterfaces(List interfaces) {
    this.interfaces = interfaces;
  }

  public List getGlobalArtifacts() {
    return globalArtifacts;
  }

  public void setGlobalArtifacts(List globalArtifacts) {
    this.globalArtifacts = globalArtifacts;
  }

  public void addNamespace(String prefix, String uri) {
    namespaceMap.put(prefix, uri);
  }
  
  public boolean containsNamespacePrefix(String prefix) {
    return namespaceMap.containsKey(prefix);
  }
  
  public String getNamespace(String prefix) {
    return namespaceMap.get(prefix);
  }
  
  public Map getNamespaces() {
    return namespaceMap;
  }
  
  public String getTargetNamespace() {
    return targetNamespace;
  }

  public void setTargetNamespace(String targetNamespace) {
    this.targetNamespace = targetNamespace;
  }
  
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy