IEnrolment enrolment = (IEnrolment) iterator.next();
IEnrollment enrolment = (IEnrollment) iterator.next();
	public void run(		IUserView userView,		Integer studentCurricularPlanId,		String currentState,		Double credits,		String startDate,		List extraCurricularCourses,		String observations)		throws FenixServiceException {		try {			ISuportePersistente sp = SuportePersistenteOJB.getInstance();						IStudentCurricularPlanPersistente persistentStudentCurricularPlan =				sp.getIStudentCurricularPlanPersistente();						IStudentCurricularPlan studentCurricularPlanTemp = new StudentCurricularPlan();			studentCurricularPlanTemp.setIdInternal(studentCurricularPlanId);			IStudentCurricularPlan studentCurricularPlan =				(IStudentCurricularPlan) persistentStudentCurricularPlan.readByOId(					studentCurricularPlanTemp,					true);			if (studentCurricularPlan == null) {				throw new InvalidArgumentsServiceException();			}						StudentCurricularPlanState newState = new StudentCurricularPlanState(currentState);						IEmployee employee = null;			IPersistentEmployee persistentEmployee = sp.getIPersistentEmployee();			IPessoaPersistente persistentPerson = sp.getIPessoaPersistente();			IPersistentEnrolment persistentEnrolment = sp.getIPersistentEnrolment();						IPessoa person = persistentPerson.lerPessoaPorUsername(userView.getUtilizador());			if (person == null) {				throw new InvalidArgumentsServiceException();			}						employee = persistentEmployee.readByPerson(person.getIdInternal().intValue());			if (employee == null) {				throw new InvalidArgumentsServiceException();			}			studentCurricularPlan.setStartDate(stringDateToCalendar(startDate).getTime());			studentCurricularPlan.setCurrentState(newState);			studentCurricularPlan.setEmployee(employee);			studentCurricularPlan.setGivenCredits(credits);			studentCurricularPlan.setObservations(observations);						List enrollments = studentCurricularPlan.getEnrolments();			Iterator iterator = enrollments.iterator();			if (newState.getState().intValue() == StudentCurricularPlanState.INACTIVE) {				while (iterator.hasNext()) {					IEnrolment enrolment = (IEnrolment) iterator.next();					if (enrolment.getEnrolmentState().getValue() ==  EnrolmentState.ENROLED_TYPE							|| enrolment.getEnrolmentState().getValue() ==  EnrolmentState.TEMPORARILY_ENROLED_TYPE) {						persistentEnrolment.simpleLockWrite(enrolment);						enrolment.setEnrolmentState(EnrolmentState.ANNULED);					}				}			} else {			   				while (iterator.hasNext()) {					IEnrolment enrolment = (IEnrolment) iterator.next();										if (extraCurricularCourses.contains(enrolment.getIdInternal())) {						if (!(enrolment instanceof EnrolmentInExtraCurricularCourse)) {						    persistentEnrolment.delete(enrolment);						    							IEnrolment auxEnrolment = new EnrolmentInExtraCurricularCourse();								persistentEnrolment.simpleLockWrite(auxEnrolment);						    							copyEnrollment(enrolment, auxEnrolment);							changeAnnulled2ActiveIfActivePlan(newState, persistentEnrolment, auxEnrolment);													} else {							changeAnnulled2ActiveIfActivePlan(newState, persistentEnrolment, enrolment);												}					} else {						if (enrolment instanceof EnrolmentInExtraCurricularCourse) {						    persistentEnrolment.delete(enrolment);						    IEnrolment auxEnrolment = new Enrolment();							persistentEnrolment.simpleLockWrite(auxEnrolment);														copyEnrollment(enrolment, auxEnrolment);							changeAnnulled2ActiveIfActivePlan(newState, persistentEnrolment, auxEnrolment);						} else {							changeAnnulled2ActiveIfActivePlan(newState, persistentEnrolment, enrolment);												}					}				}			}		} catch (ExcepcaoPersistencia e) {			throw new FenixServiceException(e);		}	}