001    package net.sf.cpsolver.coursett;
002    
003    import org.apache.log4j.Logger;
004    
005    
006    import net.sf.cpsolver.coursett.model.TimetableModel;
007    import net.sf.cpsolver.ifs.util.Callback;
008    
009    /**
010     * Abstract timetable loader class.
011     * 
012     * @version
013     * CourseTT 1.1 (University Course Timetabling)<br>
014     * Copyright (C) 2006 Tomáš Müller<br>
015     * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
016     * Lazenska 391, 76314 Zlin, Czech Republic<br>
017     * <br>
018     * This library is free software; you can redistribute it and/or
019     * modify it under the terms of the GNU Lesser General Public
020     * License as published by the Free Software Foundation; either
021     * version 2.1 of the License, or (at your option) any later version.
022     * <br><br>
023     * This library is distributed in the hope that it will be useful,
024     * but 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.
027     * <br><br>
028     * You should have received a copy of the GNU Lesser General Public
029     * License along with this library; if not, write to the Free Software
030     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
031     */
032    
033    public abstract class TimetableLoader implements Runnable {
034        private TimetableModel iModel = null;
035        private Callback iCallback = null;
036        
037        /** Constructor 
038         * @param model an empty instance of timetable model 
039         */
040        public TimetableLoader(TimetableModel model) {
041            iModel = model;
042        }
043        
044        /** Returns provided model.
045         * @return provided model
046         */
047        protected TimetableModel getModel() { return iModel; }
048        
049        /** Load the model.
050         */
051        public abstract void load() throws Exception;
052        
053        /** Sets callback class
054         * @param callback method {@link Callback#execute()} is executed when load is done
055         */
056        public void setCallback(Callback callback) { iCallback = callback; }
057    
058        public void run() { 
059            try {
060                    load(); 
061            } catch (Exception e) {
062                    Logger.getLogger(this.getClass()).error(e.getMessage(),e);
063            } finally {
064                    if (iCallback!=null)
065                            iCallback.execute();
066            }
067        }
068    
069    }