001package org.cpsolver.studentsct; 002 003import org.apache.log4j.Logger; 004import org.cpsolver.ifs.assignment.Assignment; 005import org.cpsolver.ifs.util.Callback; 006import org.cpsolver.studentsct.model.Enrollment; 007import org.cpsolver.studentsct.model.Request; 008 009 010/** 011 * Abstract student sectioning loader class. 012 * 013 * @version StudentSct 1.3 (Student Sectioning)<br> 014 * Copyright (C) 2007 - 2014 Tomas Muller<br> 015 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 016 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 017 * <br> 018 * This library is free software; you can redistribute it and/or modify 019 * it under the terms of the GNU Lesser General Public License as 020 * published by the Free Software Foundation; either version 3 of the 021 * License, or (at your option) any later version. <br> 022 * <br> 023 * This library is distributed in the hope that it will be useful, but 024 * WITHOUT ANY WARRANTY; without even the implied warranty of 025 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 026 * Lesser General Public License for more details. <br> 027 * <br> 028 * You should have received a copy of the GNU Lesser General Public 029 * License along with this library; if not see 030 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 031 */ 032 033public abstract class StudentSectioningLoader implements Runnable { 034 private StudentSectioningModel iModel = null; 035 private Assignment<Request, Enrollment> iAssignment = null; 036 private Callback iCallback = null; 037 038 /** 039 * Constructor 040 * 041 * @param model 042 * an empty instance of timetable model 043 * @param assignment an empty assignment to be populated 044 */ 045 public StudentSectioningLoader(StudentSectioningModel model, Assignment<Request, Enrollment> assignment) { 046 iModel = model; 047 iAssignment = assignment; 048 } 049 050 /** 051 * Returns provided model. 052 * 053 * @return provided model 054 */ 055 protected StudentSectioningModel getModel() { 056 return iModel; 057 } 058 059 /** 060 * Returns provided assignment. 061 * 062 * @return provided assignment 063 */ 064 protected Assignment<Request, Enrollment> getAssignment() { 065 return iAssignment; 066 } 067 068 /** 069 * Load the model. 070 * @throws Exception thrown when the load fails 071 */ 072 public abstract void load() throws Exception; 073 074 /** 075 * Sets callback class 076 * 077 * @param callback 078 * method {@link Callback#execute()} is executed when load is 079 * done 080 */ 081 public void setCallback(Callback callback) { 082 iCallback = callback; 083 } 084 085 @Override 086 public void run() { 087 try { 088 load(); 089 } catch (Exception e) { 090 Logger.getLogger(this.getClass()).error(e.getMessage(), e); 091 } finally { 092 if (iCallback != null) 093 iCallback.execute(); 094 } 095 } 096 097}