public FlowElement getBpmnModelElementInstance() {
BpmnModelInstance bpmnModelInstance = getBpmnModelInstance();
if(bpmnModelInstance != null) {
ModelElementInstance modelElementInstance = null;
if(ExecutionListener.EVENTNAME_TAKE.equals(eventName)) {
modelElementInstance = bpmnModelInstance.getModelElementById(transition.getId());
} else {
modelElementInstance = bpmnModelInstance.getModelElementById(activityId);
}
try {
return (FlowElement) modelElementInstance;
} catch(ClassCastException e) {
ModelElementType elementType = modelElementInstance.getElementType();
throw new ProcessEngineException("Cannot cast "+modelElementInstance+" to FlowElement. "
+ "Is of type "+elementType.getTypeName() + " Namespace "
+ elementType.getTypeNamespace(), e);
}