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