FileDocCategorySizeDatePackage
ValidCommand.javaAPI DocGlassfish v2 API18625Fri May 04 22:25:22 BST 2007com.sun.enterprise.cli.framework

ValidCommand

public class ValidCommand extends Object implements Serializable, ICommand
The ValidCommand object represents a valid command.
version
$Revision: 1.4 $

Fields Summary
private String
name
private String
numberOfOperands
private Vector
validOptions
private Vector
requiredOptions
private Vector
deprecatedOptions
private String
className
private String
usageText
private Hashtable
properties
private String
defaultOperand
private static final transient String
DEFAULTOPERAND_QUANTIFIER_REGEXP
Constructors Summary
public ValidCommand()
Construct a vanila ValidCommand object

    
                      
     
    
        validOptions = new Vector();
        requiredOptions = new Vector();
        deprecatedOptions = new Vector();
        properties = new Hashtable();
    
public ValidCommand(String name, String numberOfOperands, Vector validOptions, Vector requiredOptions, Vector deprecatedOptions, String usageText)
Construct ValidCommand object with the given arguments.

param
name the name of the valid command
param
numberOfOperands number of operands in this command
param
validOptions a list of validOptions
param
requiredOptions a list of required options
param
deprecatedOptions a list of deprecated options
param
usageText usage text for this command

        this.name = name;
        this.numberOfOperands = numberOfOperands;
        this.validOptions = validOptions;
        this.requiredOptions = requiredOptions;
        this.deprecatedOptions = deprecatedOptions;
        this.usageText = usageText;
    
Methods Summary
public voidaddDeprecatedOption(ValidOption option)
Adds the deprecated option to the deprecated options list

param
option option to add to the deprecated

        if ((option != null) && !hasDeprecatedOption(option.getName()))
        {
            deprecatedOptions.add(option);
        }
    
public voidaddRequiredOption(ValidOption option)
Adds the required option to the required options list

param
option option to add to the required

        if ((option != null) && !hasRequiredOption(option.getName()))
        {
            requiredOptions.add(option);
        }
    
public voidaddValidOption(ValidOption option)
Add ValidOption object to the valid option list

param
option valid option list

        if ((option != null) && !hasValidOption(option.getName()))
        {
            validOptions.add(option);
        }
    
public voiddeleteOption(ValidOption option)
Deletes the option from the options list

param
option option to delete from the list

        if (option != null)
        {
            validOptions.remove(option);
        }
    
public ValidOptiongetAlternateDeprecatedOption(java.lang.String optionName)
Returns the alternate deprecated option

param
optionName the deprecated option name
return
the ValidOption object, return null if option does not exist.

        Vector allOptions = new Vector(validOptions);
        allOptions.addAll(requiredOptions);
        boolean hasAltDeprecatedOption = false;
        ValidOption altDeprecatedOption = null;
        for (int i = 0; (i < allOptions.size()) && !hasAltDeprecatedOption; i++)
        {
            ValidOption validOption = (ValidOption)allOptions.get(i);
            final String deprecatedOptionStr = validOption.getDeprecatedOption();
            if ((deprecatedOptionStr != null) && 
                (deprecatedOptionStr.equals(optionName)))
            {
                hasAltDeprecatedOption = true;
                altDeprecatedOption = validOption;
            }
        }
        return altDeprecatedOption;
    
public java.lang.StringgetClassName()
Returns the class name for this command

return
the class name

        return className;
    
public java.lang.StringgetDefaultOperand()
Get the default operand for this command defaultoperand is valid if numberofoperand attribute is either * or ?. If the numberofoperand is finite or "+" then this attribute is ignored.

        return this.defaultOperand;
    
public java.util.VectorgetDeprecatedOptions()
Gets the list of deprecated options for this command

return
list of deprecated options

        return deprecatedOptions;
    
public java.lang.StringgetName()
Get the name of the command

return
the name of the Valid Command

        return name;
    
public java.lang.StringgetNumberOfOperands()
Returns the number of operands in this Command

return
the number of operands

        return numberOfOperands;
    
public ValidOptiongetOption(java.lang.String longOptionName)
Returns the option which matches in the options list

param
longOptionName the long option name
return
the ValidOption object, return null if option does not exist.

        Vector allOptions = this.getOptions();
        if (longOptionName != null) {
            for (int ii=0; ii<allOptions.size(); ii++)
            {
                ValidOption option = (ValidOption)allOptions.get(ii);
                if ((option.getName()).equals(longOptionName))
                    return option;
            }
        }
        return null;
    
public java.util.VectorgetOptions()
Gets all the options (required and valid)

return
the list of valid options

        Vector options = new Vector(validOptions);
        options.addAll(requiredOptions);
        options.addAll(deprecatedOptions);
        return options;
    
public java.util.HashtablegetProperties()
Gets all the properties of the command

return
the list of properties

        return properties;
    
public java.lang.ObjectgetProperty(java.lang.String key)
Searches for the property with the specified key in this properties list

return
the property

        return properties.get(key);
    
public java.util.VectorgetRequiredOptions()
Gets the list of required options for this command

return
list of required options

        return requiredOptions;
    
public java.lang.StringgetUsageText()
Return the usage text

return
the usage text of the command

        return usageText;
    
public java.util.VectorgetValidOptions()
Returns the list of valid options for this command

return
the list of valid options

        return validOptions;
    
public booleanhasAlternateDeprecatedOption(java.lang.String optionName)
Checks if the alternate deprecated option exists

param
optionName The deprecated option name
return
true if the option exist

        Vector allOptions = new Vector(validOptions);
        allOptions.addAll(requiredOptions);
        boolean hasAltDeprecatedOption = false;
        for (int i = 0; (i < allOptions.size()) && !hasAltDeprecatedOption; i++)
        {
            String deprecatedOptionStr = 
                       ((ValidOption)allOptions.get(i)).getDeprecatedOption();
            if ((deprecatedOptionStr != null) && 
                (deprecatedOptionStr.equals(optionName)))
            {
                hasAltDeprecatedOption = true;
            }
        }
    	return hasAltDeprecatedOption;
    
public booleanhasDeprecatedOption(java.lang.String optionName)
Checks if the deprecated option exists

param
optionName The deprecated option name
return
true if the option exist

        boolean hasDeprecatedOption = false;
        for (int i = 0; (i < deprecatedOptions.size()) && !hasDeprecatedOption; i++)
        {
            if (((ValidOption)deprecatedOptions.get(i)).getName().equals(optionName))
                hasDeprecatedOption = true;
        }
    	return hasDeprecatedOption;
    
public booleanhasDeprecatedOption(ValidOption option)
Checks if the deprecated option exists

param
option The DeprecatedOption object
return
true if the option exist in the deprecatedOptions list

    	return deprecatedOptions.contains(option);
    
public booleanhasProperty(java.lang.String propertyName)
Finds if a property by name exists in the list

param
propertyName name of the property to find in the list
return
true if the property is found

        return properties.containsKey(propertyName);
    
public booleanhasRequiredOption(java.lang.String optionName)
Checks if the required option exists

param
optionName The required option name
return
true if the option exist

        boolean hasRequiredOption = false;
        for (int i = 0; (i < requiredOptions.size()) && !hasRequiredOption; i++)
        {
            if (((ValidOption)requiredOptions.get(i)).getName().equals(optionName))
                hasRequiredOption = true;
        }
    	return hasRequiredOption;
    
public booleanhasRequiredOption(ValidOption option)
Checks if the required option exists

param
option The RequiredOption object
return
true if the option exist

    	return requiredOptions.contains(option);
    
public booleanhasValidOption(java.lang.String optionName)
Checks if the option exists

param
optionName The ValidOption name
return
true if the option exist

        boolean hasValidOption = false;
        if (optionName != null) {
            for (int i = 0; (i < validOptions.size()) && !hasValidOption; i++)
            {
                if (((ValidOption)validOptions.get(i)).getName().equals(optionName))
                    hasValidOption = true;
            }
        }
    	return hasValidOption;
    
public booleanhasValidOption(ValidOption option)
Checks if the option exists

param
option The ValidOption object
return
true if the option exist

    	return validOptions.contains(option);
    
public voidreplaceAllOptions(ValidOption replaceOption)
Calls ReplaceOptionsList to relace the options with replaceOption in validOptions, requiredOptions and deprecatedOptions.

        if (replaceOption != null)
        {
            final String replaceOptionName = replaceOption.getName();
            if (hasValidOption(replaceOptionName))
            {
                replaceOptionsList(validOptions, replaceOption);
            }
            if (hasRequiredOption(replaceOptionName))
            {
                replaceOptionsList(requiredOptions, replaceOption);
            }
            if (hasDeprecatedOption(replaceOptionName))
            {
                replaceOptionsList(deprecatedOptions, replaceOption);
            }
        }
    
private voidreplaceOptionsList(java.util.Vector optionsList, ValidOption replaceOption)
Search in the options list and replace it with replaceOption object.

        final String replaceOptionName = replaceOption.getName();
        for (int ii = 0; ii<optionsList.size(); ii++)
        {
            try {
                if (((ValidOption)optionsList.get(ii)).getName().equals(replaceOptionName))
                {
                    if (((ValidOption)optionsList.get(ii)).hasDeprecatedOption()) {
                        final String deprecatedOption=((ValidOption)optionsList.get(ii)).getDeprecatedOption();
                        replaceOption.setDeprecatedOption(deprecatedOption);
                    }
                    
                    optionsList.set(ii, replaceOption);
                    break;
                }
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
        return;
    
public voidsetClassName(java.lang.String className)
Sets the class name for this command

param
className the class name to set

        this.className = className;
    
public voidsetDefaultOperand(java.lang.String defaultOperand)
Sets the default operand for this command defaultoperand is valid if numberofoperand attribute is either * or ?. If the numberofoperand is finite or "+" then this attribute is ignored and set to nil.

param
defaultOperand

        if (defaultOperand != null &&
            numberOfOperands.matches(DEFAULTOPERAND_QUANTIFIER_REGEXP)) 
        {
            this.defaultOperand = defaultOperand;
        }
        else
            this.defaultOperand = null;
    
public voidsetDeprecatedOptions(java.util.Vector deprecatedOptions)
Sets the list of Deprecated options for this command

param
deprecatedOptions the list of deprecated options to set

        this.deprecatedOptions = deprecatedOptions;
    
public voidsetName(java.lang.String name)
Sets the name of the Valid Command

param
name name of the command

        this.name = name;
    
public voidsetNumberOfOperands(java.lang.String numberOfOperands)
Sets the number of operands for this command

param
numberOfOperands the number of operands

        this.numberOfOperands = numberOfOperands;
    
public voidsetProperty(java.lang.String key, java.lang.Object value)
Sets the properties of the command

param
key
param
value

        properties.put(key, value);
    
public voidsetRequiredOptions(java.util.Vector requiredOptions)
Sets the list of Required options for this command

param
requiredOptions the list of required options to set

        this.requiredOptions = requiredOptions;
    
public voidsetUsageText(java.lang.String usageText)

        this.usageText = usageText;
    
public voidsetValidOptions(java.util.Vector validOptions)
Sets the list of valid options for this command

param
validOptions the valid options to set

        this.validOptions = validOptions;
    
public java.lang.StringtoString()
Returns the toString()

return
String the object in the string format

        String validOptionsStr = "{";
        for (int i = 0; i < validOptions.size(); i++)
        {
            validOptionsStr += validOptions.get(i).toString() + ",";
        }
        validOptionsStr += "}";
       
        String requiredOptionsStr = "";
        for (int i = 0; i < requiredOptions.size(); i++)
        {
            requiredOptionsStr += requiredOptions.get(i).toString() + ",";
        }
        requiredOptionsStr += "}";

        String deprecatedOptionsStr = "";
        for (int i = 0; i < deprecatedOptions.size(); i++)
        {
            deprecatedOptionsStr += deprecatedOptions.get(i).toString() + ",";
        }
        deprecatedOptionsStr += "}";

        String propertiesStr = "{";
        for (Enumeration propertyNames = properties.keys() ; propertyNames.hasMoreElements() ;) 
        {
            String name = (String) propertyNames.nextElement();
            Vector value = (Vector) properties.get(name);
            propertiesStr += "|" + name + " , " + value;
        }
        propertiesStr += "}";
         
        return (name + " " + numberOfOperands + " | " + validOptionsStr + 
                " | " + requiredOptionsStr + " | " +
                " | " + deprecatedOptionsStr + " | " + usageText + " " + 
                propertiesStr);