| ActionFactory.java |
/*
PCS - A Framework For Java Web Applications
Copyright (C) 2002 Patrick Carl, patrick.carl@web.de
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: ActionFactory.java,v 1.1.1.1 2002/12/27 23:49:43 pcs_org Exp $
*/
package de.spieleck.pcs.action;
import java.io.FileNotFoundException;
import de.spieleck.pcs.factory.DefaultFactory;
import de.spieleck.pcs.factory.FactoryException;
/**
* This object acts as a factory for Actions. It is configurable via the
* properties file. It wraps a DefaultFactory within a member.
* <i>/conf/action.properties</i>. This file should be in your classpath.
* @author Patrick Carl
*/
public class ActionFactory extends DefaultFactory{
protected String configFile = "/conf/action.properties";
/**
* default constructor for ActionFactory
*/
public ActionFactory() throws ActionException{
super();
try{
setConfigFile(configFile);
} catch(FileNotFoundException fe){
fe.printStackTrace();
throw new ActionException(fe.getMessage());
}
}
/**
* factory method for creating objects. The class of the Objects is
* look upped in the configuration file.<br>
* Throws an Exception if the constructed object is not an Action
*/
public Object getNewObject(String key) throws FactoryException{
Object o = super.getNewObject(key);
if(!(o instanceof Action)){
throw new FactoryException("Object connected to key " + key +
" is not an Action. Check your configuration.");
}
return o;
}
}| ActionFactory.java |