FileDocCategorySizeDatePackage
CommandFactory.javaAPI DocGlassfish v2 API4829Fri May 04 22:25:20 BST 2007com.sun.enterprise.cli.framework

CommandFactory

public class CommandFactory extends Object
This is a factory class that creates a Command object.
version
$Revision: 1.6 $
author
pa100654

Fields Summary
Constructors Summary
public CommandFactory()
Creates a new instance of CommandFactory

    
Methods Summary
public static CommandcreateCommand(ValidCommand commandMatched, OptionsMap options, java.util.Vector operands)
The static class that creates the command object

param
commandMatched, the ValidCommand object that contains vital info on the command.
param
options, the options in command line
param
operands,the operands in command line
throws
CommandValidationException if there is an error creating the command.

        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.VectordetermineOperand(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;