FileDocCategorySizeDatePackage
UnsetCommand.javaAPI DocGlassfish v2 API5704Fri May 04 22:25:12 BST 2007com.sun.enterprise.cli.commands

UnsetCommand

public class UnsetCommand extends S1ASCommand
This class is the unset command. It will unset the given environment variable in multimode.

Fields Summary
private static final String
ENVIRONMENT_PREFIX
private static final String
ENVIRONMENT_DELIMITER
private CommandEnvironment
commandEnvironment
Constructors Summary
public UnsetCommand()
Creates new UnsetCommand


        
      
    
    
Methods Summary
private java.lang.StringcheckForPrefix(java.lang.String name)
this method check for prefix AS_ADMIN returns the name without the prefix AS_ADMIN

	String envName = null;
	//check for prefix AS_ADMIN
        if (name.regionMatches(true, 0, ENVIRONMENT_PREFIX, 0, 
                               ENVIRONMENT_PREFIX.length())) 
        {
	    //extract AS_ADMIN from sOperandName
            envName =  name.substring(ENVIRONMENT_PREFIX.length());
        }
	else 
        {
	    throw new CommandException(getLocalizedString("CouldNotUnsetVariable",
							  new Object[] {name}));
	}
	return envName.toLowerCase();
    
private voidremoveAllEnvironments()
this method is called when AS_ADMIN_* is encountered. The wildcard means to remove all variables set in the environment.

        // remove the Local environments
        MultiProcessCommand.removeAllEnvironments();
        
        final java.util.HashMap envMap = new
           java.util.HashMap(commandEnvironment.getEnvironments());
        final java.util.Iterator envIter = envMap.keySet().iterator();

        while (envIter.hasNext())
        {
            final String envName = (String)envIter.next();
            if (commandEnvironment.removeEnvironment(envName) == null)
                CLILogger.getInstance().printWarning(getLocalizedString(
                                                    "UnableToRemoveEnv",
                                                    new Object[] {envName}));
        }
     
public voidrunCommand()
Executes the command

throws
CommandException

        validateOptions();
        
        for (int ii = 0; ii < operands.size(); ii++)
        {
	    updateEnvironment((String)operands.elementAt(ii));
        }
    
private voidupdateEnvironment(java.lang.String nameStr)
this method updates the variables by removing them from the command environment (local and global).

param
nameStr - the name of the environment to remove
throws
CommandException if environment could not be removed.

	final String envName = checkForPrefix(nameStr);
	if (envName.equals("*"))
	{
            // Remove both the local and global environment variables
            removeAllEnvironments();
	}
	else
	{
            if (MultiProcessCommand.removeLocalEnvironment(envName) != null)
            {
                // Also remove the global environment if exists
                commandEnvironment.removeEnvironment(envName);
            }
            else if (commandEnvironment.removeEnvironment(envName) == null)
            {
		throw new CommandException(getLocalizedString("UnableToRemoveEnv",
					   new Object[] {nameStr}));
            }
	}
    
public booleanvalidateOptions()
Validates the Options for correctness

return
boolean returns true if validation is succesful else false

        return super.validateOptions();