/**
* This source file is part of WZ Hybrid Bots
* For the latest information, see http://sourceforge.net/projects/wzhybridbots
*
* Copyright (c) 2006 - WzCtf
* For more information about WzCtf, see http://www.wzctf.net
* Also see the license in license.txt
*/
package wzhybridbots.tools.actions;
/** The imported classes/interfaces */
import wzhybridbots.tools.actions.ASSSServerCommands;
import wzhybridbots.tools.actions.ServerCommands;
import wzhybridbots.tools.actions.VIEServerCommands;
/**
* An abstract factory that creates a {@link wzhybridbots.tools.actions.ServerCommands ServerCommands}
* for the server type specified.
*
* @author Witlospock
* @version 1.0
*/
public class ServerCommandsAbstractFactory {
/** Unknown server type */
public final static int UNKNOWN = -1;
/** VIE server type */
public final static int VIE = 0;
/** ASSS server type */
public final static int ASSS = 1;
/**
* Returns the {@link wzhybridbots.tools.actions.ServerCommands ServerCommands} requested or null
* if the type is unknown.
*
* @param serverType The type of server following ServerCommandsAbstractFactory's constants.
* @return see above.
*/
public static ServerCommands createServerCommands ( int serverType ) {
ServerCommands cmd = null;
// Checks for the type to instantiate
switch ( serverType ) {
// VIE server type
///////////////////////////////////////
case ServerCommandsAbstractFactory.VIE:
cmd = new VIEServerCommands();
break;
// ASSS server type
///////////////////////////////////////
case ServerCommandsAbstractFactory.ASSS:
cmd = new ASSSServerCommands();
break;
// Unknown server type
///////////////////////////////////////
default:
break;
}
return cmd;
}
/**
* Returns the {@link wzhybridbots.tools.actions.ServerCommands ServerCommands} requested or null
* if the type is unknown.
*
* @param serverType The type of server following ServerCommandsAbstractFactory's constants.
* @return see above.
*/
public static ServerCommands createServerCommands ( String serverType ) {
int type = ServerCommandsAbstractFactory.UNKNOWN;
// Eliminate spaces and put to lowercase
serverType = serverType.trim().toLowerCase();
// If the type is a number, call the appropriate method
try {
Integer value = Integer.valueOf( serverType );
if ( value != null ) {
// It is a number, so call the appropriate method
return createServerCommands( value.intValue() );
}
}
catch ( NumberFormatException nfe ) {
// The string isn't a number
}
// Checks for the type requested
if ( serverType.equals( "vie" ) ) {
// VIE Server type
type = ServerCommandsAbstractFactory.VIE;
}
else if ( serverType.equals( "asss" ) ) {
// ASSS Server type
type = ServerCommandsAbstractFactory.ASSS;
}
// Return the type requested if found
return createServerCommands( type );
}
}