}
public static FlowElement clone(final FlowElement element, final Diagram diagram) {
FlowElement cloneElement = null;
List<FormProperty> formProperties = null;
if (element instanceof StartEvent) {
cloneElement = clone((StartEvent) element, diagram);
formProperties = ((StartEvent) element).getFormProperties();
} else if (element instanceof ServiceTask) {
cloneElement = clone((ServiceTask) element, diagram);
} else if (element instanceof EndEvent) {
cloneElement = clone((EndEvent) element, diagram);
} else if (element instanceof ExclusiveGateway) {
cloneElement = clone((ExclusiveGateway) element, diagram);
} else if (element instanceof InclusiveGateway) {
cloneElement = clone((InclusiveGateway) element, diagram);
} else if (element instanceof ManualTask) {
cloneElement = clone((ManualTask) element, diagram);
} else if (element instanceof ParallelGateway) {
cloneElement = clone((ParallelGateway) element, diagram);
} else if (element instanceof ScriptTask) {
cloneElement = clone((ScriptTask) element, diagram);
} else if (element instanceof UserTask) {
cloneElement = clone((UserTask) element, diagram);
formProperties = ((UserTask) element).getFormProperties();
List<ActivitiListener> resultListenerList = new ArrayList<ActivitiListener>();
for (ActivitiListener listener : ((UserTask) element).getTaskListeners()) {
resultListenerList.add(clone(listener));
}
((UserTask) cloneElement).setTaskListeners(resultListenerList);
}
if (element instanceof Activity && element instanceof UserTask == false) {
List<ActivitiListener> resultListenerList = new ArrayList<ActivitiListener>();
for (ActivitiListener listener : ((Activity) element).getExecutionListeners()) {
resultListenerList.add(clone(listener));
}
((Activity) cloneElement).setExecutionListeners(resultListenerList);
}
if (element instanceof Activity) {
((Activity) cloneElement).setAsynchronous(((Activity) element).isAsynchronous());
((Activity) cloneElement).setDefaultFlow(((Activity) element).getDefaultFlow());
}
if (formProperties != null) {
List<FormProperty> resultPropertyList = new ArrayList<FormProperty>();
for (FormProperty formProperty : formProperties) {
resultPropertyList.add(clone(formProperty));
}
if (cloneElement instanceof UserTask) {
((UserTask) cloneElement).setFormProperties(resultPropertyList);
} else {
((StartEvent) cloneElement).setFormProperties(resultPropertyList);
}
}
if (cloneElement != null) {
cloneElement.setName(element.getName());
ModelHandler.getModel(EcoreUtil.getURI(diagram)).getBpmnModel().getMainProcess().addFlowElement(cloneElement);
}
return cloneElement;