CommandFactorypublic class CommandFactory extends Object This is a factory class that creates a Command object. |
Constructors Summary |
---|
public CommandFactory()Creates a new instance of CommandFactory
|
Methods Summary |
---|
public static Command | createCommand(ValidCommand commandMatched, OptionsMap options, java.util.Vector operands)The static class that creates the command object
Command command = null;
String commandName = commandMatched.getName();
String className = commandMatched.getClassName();
if (className == null)
{
LocalStringsManager lsm =
LocalStringsManagerFactory.getFrameworkLocalStringsManager();
throw new CommandValidationException(lsm.getString("InvalidCommand",
new Object[] {commandName} ));
}
try
{
Class theClass = Class.forName(className);
command = (Command)theClass.newInstance();
command.setName(commandName);
command.setOptionsMap(options);
command.setOperands(determineOperand(operands,
commandMatched.getDefaultOperand()));
//command.setOperands(operands);
command.setUsageText(commandMatched.getUsageText());
command.setProperties(commandMatched.getProperties());
}
catch(Exception e)
{
LocalStringsManager lsm =
LocalStringsManagerFactory.getFrameworkLocalStringsManager();
throw new CommandValidationException(lsm.getString("UnableToCreateCommand",
new Object[] {commandName}), e);
//e.printStackTrace();
}
return command;
| private static java.util.Vector | determineOperand(java.util.Vector operands, java.lang.String defaultOperand)This api will check if the user enters an operand, if not, then
replace it with the defaultoperand specified in the
CLIDescriptor.xml
return operands.size()<1 && defaultOperand!=null ?
new Vector<String>(java.util.Arrays.asList(
new String[]{defaultOperand})):operands;
|
|