Estelle,
The exception you show isn't complaining about your cast to a WorkflowProcess but looks to be deeper in the call to dump (although I cannot tell because you cut off the stack trace). It says you have an instance of org.jbpm.context.def.ContextDefinition that is trying to be cast to org.drools.process.core.Context. I don't know where the org.jbpm.context.def.ContextDefinition is being created but it probably a part of processDefinition. The stack trace with the exception should tell you where the cast is being done.
Here is the code I use to get thet XML:
protected String xmlForProcess(ProcessDefinitionDTO procDef, List<WorkflowNode> nodes, RPCResult result) {
RuleFlowProcessFactory factory = processDefinitionService.createProcesFactory(procDef.getIdString());
factory.version("1");
factory.packageName("com.stuff.pbm");
factory.name(procDef.getName());
addNodesToProcess(nodes, factory);
addLinksToProcess(procDef, factory);
RuleFlowProcess process = factory.getProcess();
ProcessValidationError[] errors = RuleFlowProcessValidator.getInstance().validateProcess(process);
for (ProcessValidationError e : errors) {
result.addMessage(new MessageDTO(MessageCategory.WARNING, e.getMessage()));
}
String asXml = XmlBPMNProcessDumper.INSTANCE.dump(process, XmlBPMNProcessDumper.NO_META_DATA);
return asXml;
}
where
processDefinitionService.createProcessFactory
returns a
org.jbpm.ruleflow.core.RuleFlowProcessFactory
.
I hope this helps.
-Victor