ArrayList infoExecutionCourses = new ArrayList(); for (int j = 1; j < 6; j++) { try { infoExecutionCourses.addAll( (List) ServiceUtils.executeService( userView, "SelectExecutionCourse", new Object[] { selectedDegree, currentExecutionPeriod, new Integer(j)})); } catch (FenixServiceException e4) { throw new FenixActionException(e4); }
List infoExecutionCourses = new ArrayList();
	public ActionForward enrollCourses(		ActionMapping mapping,		ActionForm form,		HttpServletRequest request,		HttpServletResponse response)		throws FenixActionException {		boolean firstTime = request.getParameter("firstTime") != null;		if (firstTime) {			createToken(request);		} else {			validateToken(				request,				form,				mapping,				TRANSACTION_ERROR_MESSAGE_KEY);		}		HttpSession session = request.getSession();		IUserView userView =			(IUserView) session.getAttribute(SessionConstants.U_VIEW);		// retrieve the student information to fill the info 		// to be passed to the readShifts service		InfoStudent infoStudent = null;		try {			infoStudent =				(InfoStudent) ServiceUtils.executeService(					userView,					"ReadStudentByUsername",					new Object[] { userView.getUtilizador()});		} catch (FenixServiceException e) {			throw new FenixActionException(e);		}		//Update the student's attending courses:		String[] wantedCourses = { };				if (request.getParameter("wantedCourse") != null){			wantedCourses = ((String[]) ((DynaActionForm) form).get("wantedCourse"));		}					if (wantedCourses != null && !firstTime) {			//Build up the arrayList			Boolean attendenceChanged =				writeAttendingCourses(userView, infoStudent, wantedCourses);			if (!attendenceChanged.booleanValue()) {				System.out.println(					"Nao foi possivel actualizar as disciplinas do aluno");				throw new FenixActionException("Can't Change Degree Attending.");			}		} // firstTime if		// Retrieve the current executionYear to later get the existing degrees		InfoExecutionYear currentExecutionYear;		try {			currentExecutionYear =				(					InfoExecutionYear) ServiceUtils						.executeService(							userView,							"ReadCurrentExecutionYear",							new Object[] {			});		} catch (FenixServiceException e1) {			throw new FenixActionException(e1);		}		// Retrieve the list of existing degrees		List degreeList;		try {			degreeList =				(List) ServiceUtils.executeService(					userView,					"ReadNonMasterExecutionDegreesByExecutionYear",					new Object[] { currentExecutionYear });		} catch (FenixServiceException e2) {			throw new FenixActionException(e2);		}		// get the student's own course to show first, if there is not one		// already selected		String selectedDegreeAbbrev = request.getParameter("degree");		InfoExecutionDegree selectedDegree = null, idtemp = null;		Collections.sort(degreeList,new ComparatorByNameForInfoExecutionDegree());		// if there is no selected degree		if (selectedDegreeAbbrev == null) {			// retrieve the student's own curricular plan			try {				selectedDegreeAbbrev =					((InfoDegree) ServiceUtils						.executeService(							userView,							"ReadCourseByStudent",							new Object[] {								infoStudent.getNumber(),								infoStudent.getDegreeType()}))						.getSigla();			} catch (FenixServiceException e3) {				throw new FenixActionException(e3);			}		}		Iterator i = degreeList.iterator();		// we assume that the Abbrev ( sigla ) is unique amongst the degrees		while (i.hasNext()) {			idtemp = (InfoExecutionDegree) i.next();			if (idtemp				.getInfoDegreeCurricularPlan()				.getInfoDegree()				.getSigla()				.equals(selectedDegreeAbbrev)) {				selectedDegree = idtemp;				i.remove();			}		}		if (selectedDegree == null) {			// didn't found the degree, doesn't exist. someone did a boo boo			throw new FenixActionException("Wrong Degree Selected. Please enroll in another college.");		} // end of if ()		// add to the beginning of the list the selected degree		degreeList.add(0, selectedDegree);		request.setAttribute("degreeList", degreeList);		InfoExecutionPeriod currentExecutionPeriod;		try {			currentExecutionPeriod =				(					InfoExecutionPeriod) ServiceUtils						.executeService(							userView,							"ReadCurrentExecutionPeriod",							new Object[] {			});		} catch (FenixServiceException e3) {			throw new FenixActionException(e3);		}		// retrieve all courses pertaining to the selected degree		ArrayList infoExecutionCourses = new ArrayList();		for (int j = 1; j < 6; j++) {			try {				infoExecutionCourses.addAll(					(List) ServiceUtils.executeService(						userView,						"SelectExecutionCourse",						new Object[] {							selectedDegree,							currentExecutionPeriod,							new Integer(j)}));			} catch (FenixServiceException e4) {				throw new FenixActionException(e4);			}		}		request.setAttribute("courseList", infoExecutionCourses);		// and finally retrieve all courses the student is currently enrolled in		List attendingCourses;		try {			attendingCourses =				(List) ServiceUtils.executeService(					userView,					"ReadDisciplinesByStudent",					new Object[] {						infoStudent.getNumber(),						infoStudent.getDegreeType()});		} catch (FenixServiceException e4) {			throw new FenixActionException(e4);		}		request.setAttribute("wantedCourse", attendingCourses);		return mapping.findForward("selectCourses");	}