FileDocCategorySizeDatePackage
ExportCommand.javaAPI DocGlassfish v2 API8366Fri May 04 22:25:10 BST 2007com.sun.enterprise.cli.commands

ExportCommand

public class ExportCommand extends S1ASCommand
This class is the export command. It will set the given environment variable in multimode.

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


        
      
    
    
Methods Summary
private java.lang.StringcheckForPrefix(java.lang.String name)
this method check for prefix AS_ADMIN retursn 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("CouldNotSetVariable",
                                                          new Object[] {name}));
        }
        return envName.toLowerCase();
    
private voidprintAllEnvValues()
this method prints the environment variable.

        if ((commandEnvironment.getNumEnvironments() == 0) &&
                (MultiProcessCommand.getNumLocalEnvironments() == 0))
        {
            CLILogger.getInstance().printDetailMessage(
                                        getLocalizedString("NoEnvironment"));
        }
        else
        {
            HashMap allEnvironments = commandEnvironment.getEnvironments();
            // Add Local Environment values (Will contain only for passwords)
            allEnvironments.putAll(MultiProcessCommand.getLocalEnvironments());
            printEnvValues(allEnvironments);
        }
    
private voidprintEnvValue(java.lang.String name, java.lang.Object value)
print one environment

param
name used in the environment
param
value is the value of the given name in environment

        final String displayName = ENVIRONMENT_PREFIX.concat(name.toUpperCase());
        //Do not display the password value in clear text
        if (name.endsWith(PASSWORD_STRING))
        {
            CLILogger.getInstance().printMessage(displayName + " = ********");
        }
        else
        {
            CLILogger.getInstance().printMessage(displayName + " = " + value);
        }
    
private voidprintEnvValues(java.util.HashMap allEnvironments)
Prints the name,value pairs of the local or global environments

        final Iterator envIterator = allEnvironments.keySet().iterator();

        while (envIterator.hasNext())
        {
            final String name = (String) envIterator.next();
            CLILogger.getInstance().printDebugMessage(
                                        commandEnvironment.toString());
            final Object value = allEnvironments.get(name);
            printEnvValue(name, value);
        }
    
public voidrunCommand()
Executes the command

throws
CommandException

        validateOptions();
        
        Vector operands = getOperands();
        if (operands.size() == 0)
        {
            printAllEnvValues();
            return;
        }
        for (int ii = 0; ii < operands.size(); ii++)
        {
            updateEnvironment((String)operands.elementAt(ii));
        }
    
private voidupdateEnvironment(java.lang.String nameStr)
this method updates the variable in the CommandEnvironment object.

param
nameStr - the name of the environment

        final int nameend = nameStr.indexOf(ENVIRONMENT_DELIMITER);
        //remove the environment if command is "export AS_ADMIN_<name>="
        if (nameend == nameStr.length()-1) 
        {
            final String envName = checkForPrefix(nameStr.substring(0, nameend));
            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.subSequence(0, nameend)}));
            }
        }
        //print the value if the command is "export AS_ADMIN_<name>"
        else if (nameend == -1)
        {
            final String name = checkForPrefix(nameStr);
            if (MultiProcessCommand.getLocalEnvironmentValue(name) != null)
                printEnvValue(name, 
                            MultiProcessCommand.getLocalEnvironmentValue(name));
            else
                printEnvValue(name,
                            commandEnvironment.getEnvironmentValue(name));
        }
        //set the environment if the command is "export AS_ADMIN_<name>=<value>"
        else 
        {
            final String envName = checkForPrefix(nameStr.substring(0, nameend));
            //Set only the password options in local environment
            //to avoid printing the password warning message when in multimode
            if (envName.matches(NOT_DEPRECATED_PASSWORDFILE_OPTIONS))
                MultiProcessCommand.setLocalEnvironment(envName, 
                                              nameStr.substring(nameend+1));
            else
                commandEnvironment.setEnvironment(envName,
                                              nameStr.substring(nameend+1));
        }
    
public booleanvalidateOptions()
Validates the Options for correctness

return
boolean returns true if validation is succesful else false

        return super.validateOptions();