package dk.socketmud.action; public class ActionFactory { protected ActionFactory() { ; // to prevent instances of this class being made } public static SMAction getInstance(String command) throws IllegalActionException { try { Class c = Class.forName("dk.socketmud.action.Cmd" + command); Object o = c.newInstance(); if (o instanceof SMAction) return (SMAction) o; throw new IllegalActionException("Command '" + command + "' is not an SMAction"); } catch (ClassNotFoundException ex) { throw new IllegalActionException("Class for command '" + command + "' not found"); } catch (InstantiationException ex) { throw new IllegalActionException("Failed to instantiate class for command '" + command + "'"); } catch (IllegalAccessException ex) { throw new IllegalActionException("Class for command '" + command + "' not accessable"); } } }