PersistenceService persistenceService = PersistenceServiceProvider.getPersistenceService();
ContextTrackingService trackingService = ContextTrackingProvider.getTrackingService();
//create a new Procedure: this is the representation of the Procedure Service
Procedure newProcedure = new Procedure(procedureName);
//Get the requested ProcedureService from Spring
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("procedures-beans.xml");
ProcedureService procedureService = (ProcedureService) context.getBean(procedureName);
//Store the procedure so it has a valid id
persistenceService.storeProcedure(newProcedure);
//Configure the ProcedureService
procedureService.configure(emergencyId, newProcedure, parameters);
//Update the procedure.
persistenceService.storeProcedure(newProcedure);
//the process is attached to the emergency
trackingService.attachProcedure(emergencyId, newProcedure.getId());
return procedureService;
}