/*
Tiamat - a role-playing game framework
MapFactory.java - Abstract factory to select an appropriate Map for a given file
 
 Copyright  (C) 2000-2004 Hugues Johnson
 
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

package com.huguesjohnson.tiamat.graphics;

import com.huguesjohnson.serialization.Formatter;
import com.huguesjohnson.serialization.Storable;

/** MapFactory - Abstract factory to select an appropriate Map for a given file
 * @author Hugues Johnson
 */
public abstract class MapFactory{
    /**
     * Chooses an appropriate Map for the given file and loads it, throws UnsupportedMapException if one can not be found.
     * @param path The path of the Map to load.
     * @param formatter The Formatted used to deserialize the Map.
     * @return A deserialized instance of Map.
     * @throws UnsupportedMapException If the file can not be deserialized.
     */
    public final static Map load(String path,Formatter formatter) throws UnsupportedMapException{
        try{
            Storable object=formatter.loadFrom(path);
            if(object instanceof TileMap){
                return((TileMap)object);
            }
			throw(new UnsupportedMapException());
        } catch(Exception x){
            x.printStackTrace();
            throw(new UnsupportedMapException(x.getMessage()));
        }
    }
}