if(!bCheckOK){
String err = "The provided WFTemplate: "+QName+" is not a valid implementation";
log.debug(err);
throw new Exception(err);
}
WorkflowTemplate wft = (WorkflowTemplate)Class.forName(QName).newInstance();
log.debug("WorkflowFactory: "+QName+" loaded, compiled and classloaded");
//reset the WorkflowContext
workflowContext =null;
//2a)use java reflection API to determine the list of used services within the workflowTemplate
List<Field> declaredServices = getDeclaredWFServices(wft);
int iCount =0;
for(Field declaredService : declaredServices){
String declaredServiceID = declaredService.getName();
//iterate over the provided xml service configurations and try to init the service
for(Service serviceConf : wfConf.getServices().getService()){
String serviceConfID = serviceConf.getId();
if(declaredServiceID.equals(serviceConfID)){
//now initialize it:
initWFService(wft,declaredService, serviceConf);
iCount++;
}
}
}
//check if no configuration was found for initializing the service
if(iCount!=declaredServices.size()){
String err = "The provided Workflow configuration is not suitable for the given workflow "+wft.getClass().getCanonicalName() +"1..n service configurations missing";
log.debug(err);
throw new Exception(err);
}
//<--all expected workflow services have been configured properly by the xml config data
//3) Init the data the worklow will execute upon
wft.setData(digos);
//hand over the WorkflowContext
wft.setWorkflowContext(getOrInitWFContext());
//4) Build the WorkflowInstance
WorkflowInstance wfi = new WorkflowInstanceImpl(wft);
//provide the template with a reference to the wfi's UUID e.g. relevant for logging, storing, ...
wft.setWorkflowInstanceID(wfi.getWorkflowID());
return wfi;
}