foe = stateFactory.createFOE(pi);
	private ITaskInstance createTask(ITaskDefinition td, IProcessInstance pi, IFOE foe)			throws CreateObjectException, StateFailureException,			DefinitionNotFoundException {				if (foe == null || pi == null || td == null) {			throw new CreateObjectException(					"Missing required parameters to create a Task Instance - TD: " + td + ", PI: " + pi + ", FOE:" + foe);		}		/*		 * TODO should probably add another check here to ensure that task def		 * comes from process instance's process def (i.e. protect against potential		 * workflow definition corruption)		 */		if (td.isSynchronised()) {			// task is a syncTask - we need to ensure that there is only			// TaskInstance for this definition			for (Iterator it = pi.getTaskInstances().iterator(); it.hasNext();) {				ITaskInstance checkTask = (ITaskInstance) it.next();				if (checkTask.getTaskDefinition().getId().longValue() == td						.getId().longValue()) {					// found this task already, so just return it					if (log.isInfoEnabled()) {						log								.info("Instance of Sync Task already exists; returning this instance");					}					return checkTask;				}			}		}		/*		 * instance of sync task not found or was not a sync task, so we create		 * the new one		 */		if (log.isInfoEnabled()) {			log.info("Creating new instance of TaskDef " + td);		}		ITaskInstance task = stateFactory.createTaskInstance(td, pi, foe);		// check to see if task has an initialiser - if not, ensure status is		// set optimally to not waste processor clicks		if (td.isSynchronised()) {			if (log.isInfoEnabled()) {				log.info("Sync Task Detected: " + task);			}			task.setState(ITaskInstance.STATE_AWAITINGSYNC);		} else if (td.getClassConstruct() != null) {			if (log.isInfoEnabled()) {				log.info("Task Constructor Detected: " + task);			}			task.setState(ITaskInstance.STATE_AWAITINGINITIALISATION);		} else {			if (log.isInfoEnabled()) {				log.info("Shortcutting to READY as Task without SYNC or CONSTRUCTOR detected: " + task);			}			task.setState(ITaskInstance.STATE_READY);		}		stateFactory.saveObject(task);		return task;	}