FileDocCategorySizeDatePackage
BaseLifeCycleCommand.javaAPI DocGlassfish v2 API16817Fri May 04 22:25:08 BST 2007com.sun.enterprise.cli.commands

BaseLifeCycleCommand

public abstract class BaseLifeCycleCommand extends S1ASCommand
Abstract base class for the Lifecycle commands

Fields Summary
private static final String
DEFAULT_FEATURES_PROPERTY_CLASS
protected com.sun.enterprise.admin.pluggable.ClientPluggableFeatureFactory
_featureFactory
private static final String DEFAULT_FEATURES_PROPERTY_CLASS = "com.sun.enterprise.admin.pluggable.EEClientPluggableFeatureImpl";
protected static final String
DOMAIN
protected static final String
DOMAINDIR
protected static final String
MASTER_PASSWORD
protected static final String
NEW_MASTER_PASSWORD
protected static final String
ADMIN_USER
protected static final String
ADMIN_PASSWORD
protected static final String
PASSWORD
protected static final String
DEFAULT_MASTER_PASSWORD
protected static final String
ADMIN_PORT
protected static final String
SAVE_MASTER_PASSWORD
protected static final char
ESCAPE_CHAR
protected static final char
EQUAL_SIGN
protected static final String
DELIMITER
protected static final String
KILL
Constructors Summary
public BaseLifeCycleCommand()
Creates new BaseLifeCycleCommand


        
     
    
        _featureFactory = createPluggableFeatureFactory();
    
Methods Summary
private com.sun.enterprise.admin.pluggable.ClientPluggableFeatureFactorycreatePluggableFeatureFactory()
Find and create a pluggable feature factory.

return
ClientPluggableFeatureFactory

	String featurePropClass = System.getProperty(
				  ClientPluggableFeatureFactory.PLUGGABLE_FEATURES_PROPERTY_NAME,
				  DEFAULT_FEATURES_PROPERTY_CLASS);
        getLogger().log(Level.FINER, "featurePropClass: " + featurePropClass);
        ClientPluggableFeatureFactoryImpl featureFactoryImpl =
            new ClientPluggableFeatureFactoryImpl(getLogger());
        ClientPluggableFeatureFactory featureFactory = 
	    (ClientPluggableFeatureFactory)featureFactoryImpl.getInstance(featurePropClass);
        if (featureFactory == null) {
            getLogger().log(Level.WARNING,
			    "j2eerunner.pluggable_feature_noinit", featurePropClass);
        }
        return featureFactory;
    
protected java.lang.StringgetAdminUser()
this methods returns the admin user. first it checks if adminuser option is specified on command line. if not, then it'll try to get AS_ADMIN_ADMINUSER from .asadminprefs file. if that still does not exist then get AS_ADMIN_USER from ./asadminprefs file. if all else fails, an CommandValidationException is thrown.

return
admin user.
throws
CommandValidationException if could not get adminuser option

        String adminUserVal = getOption(USER);
        if (adminUserVal != null)
            return adminUserVal;
        else
        {
            adminUserVal = getValuesFromASADMINPREFS(USER);
            if (adminUserVal != null) 
            {
                return adminUserVal;
            }
                //if adminUserVal is still null then read AS_ADMIN_ADMINUSER 
                //from .asadminprefs file
            else
            {
                adminUserVal = getValuesFromASADMINPREFS(ADMIN_USER);
                if (adminUserVal != null)  return adminUserVal;
                    //if all else fails, thrown and exception
                else if (getBooleanOption(INTERACTIVE))
                { 
                    //prompt for user
                    try {
                        InputsAndOutputs.getInstance().getUserOutput().print(
                                        getLocalizedString("AdminUserPrompt"));
                        return InputsAndOutputs.getInstance().getUserInput().getLine();
                    }
                    catch (IOException ioe)
                    {
                        throw new CommandValidationException(
                                    getLocalizedString("CannotReadOption", 
                                                new Object[]{"ADMIN_USER"}));
                    }
                } 
                else
                    throw new CommandValidationException(getLocalizedString(
                                                         "OptionIsRequired",
                                                         new Object[] {ADMIN_USER}));
            }
        }
    
protected com.sun.enterprise.admin.servermgmt.DomainConfiggetDomainConfig(java.lang.String domainName)

        try {
            DomainConfig dc = new DomainConfig(domainName, getDomainsRoot());

	    // add map entries for --verbose and --debug options to start-domain
	    if ( getBooleanOption("verbose") ) {
		dc.put(DomainConfig.K_VERBOSE, Boolean.TRUE);
	    }
	    if ( getBooleanOption("debug") ) {
		dc.put(DomainConfig.K_DEBUG, Boolean.TRUE);
	    }

            return dc;

        } catch (Exception e) {
            throw new CommandException(e);
        }
    
protected java.lang.StringgetDomainName()


	String domainName = null;
        if (operands.isEmpty())
        {
	    // need to also support domain option for backward compatibility
	    if (getOption(DOMAIN)!=null) 
		domainName = getOption(DOMAIN);
	    else 
	    {
		final String[] domains = getDomains();
		if (domains.length == 0)
		    throw new CommandException(getLocalizedString("NoDomains", 
								  new Object[] {
								  getDomainsRoot()}));
		else if (domains.length > 1)
		    throw new CommandException(getLocalizedString("NoDefaultDomain",
								  new Object[] {
								  getDomainsRoot()}));
		else
		    domainName = domains[0];  //assign the only domain
	    }
        }
	else
	    domainName = (String)operands.firstElement();
        CLILogger.getInstance().printDebugMessage("domainName = " + domainName);
        return domainName;
    
protected java.lang.String[]getDomains()

        try
        {
            DomainsManager mgr = getFeatureFactory().getDomainsManager();
            return mgr.listDomains(getDomainConfig(null));            
        }
        catch(Exception e)
        { 
            throw new CommandException(e.getLocalizedMessage());
        }                
    
protected java.lang.StringgetDomainsRoot()

        String domainDir = getOption(DOMAINDIR);
        if (domainDir == null)
        {
            domainDir = System.getProperty(SystemPropertyConstants.DOMAINS_ROOT_PROPERTY);
        }
        if (domainDir == null)
        {
            throw new CommandException(getLocalizedString("InvalidDomainPath",
				       new String[] {domainDir}) );
        }
        return domainDir;
    
protected java.util.HashMapgetExtraPasswords(java.lang.String[] optionNames)

        HashMap result = new HashMap();
        String password;
        String optionName;
        for (int i = 0; i < optionNames.length; i++) {            
            optionName = optionNames[i];            
            //Add the new option as a non-deprecated option, so a message will not be displayed.            
            NOT_DEPRECATED_PASSWORDFILE_OPTIONS += "|" + optionName;
            //getPassword(optionName, allowedOnCommandLine, readPrefsFile, readPasswordOptionFromPrefs, readMasterPasswordFile, config,
            //promptUser, confirm, validate)
            password = getPassword(optionName, "ExtraPasswordPrompt", null, false, false, false, false, null, null, 
                true, false, false, false);
            result.put(optionName, password);
        }
        return result;
    
protected com.sun.enterprise.admin.pluggable.ClientPluggableFeatureFactorygetFeatureFactory()
gets client pluggable feature factory

return
ClientPluggableFeatureFactory

        return _featureFactory;
    
protected java.util.logging.LoggergetLogger()
gets Logger from LogDomains

return
Logger

        return LogDomains.getLogger(LogDomains.CORE_LOGGER);
    
protected java.lang.StringgetMasterPassword(boolean confirmAndValidate)
this methods returns the master password and is used to get the master password for both create-domain and create-nodeagent commands. The password can be passed in on the command line (--masterpassword), environment variable (AS_ADMIN_MASTERPASSWORD), or in the password file (--passwordfile). first it checks if masterpassword option is specified on command line. if not, then it'll try to get AS_ADMIN_MASTERPASSWORD from the password file. if all else fails, then prompt the user for the password if interactive=true.

param
confirmAndValidate - boolean whether to confirm and validate masterpassword
return
admin password
throws
CommandValidationException if could not get adminpassword option

           return getMasterPassword(confirmAndValidate, false);
    
protected java.lang.StringgetMasterPassword(boolean confirmAndValidate, boolean alwaysPrompt)
this methods returns the master password and is used to get the master password for both create-domain and create-nodeagent commands. The password can be passed in on the command line (--masterpassword), environment variable (AS_ADMIN_MASTERPASSWORD), or in the password file (--passwordfile). first it checks if masterpassword option is specified on command line. if not, then it'll try to get AS_ADMIN_MASTERPASSWORD from the password file. if all else fails, then prompt the user for the password if interactive=true.

param
confirmAndValidate - boolean whether to confirm and validate masterpassword
param
alwaysPrompt - boolean whether to always prompt for masterpassword reguardless of adminuser/password
return
admin password
throws
CommandValidationException if could not get adminpassword option

           
        //getPassword(optionName, allowedOnCommandLine, readPrefsFile, readPasswordOptionFromPrefs, readMasterPasswordFile, mgr, config,
        //promptUser, confirm, validate)
        String adminPassword = getPassword(ADMIN_PASSWORD, true, false, false, false, null, null,
            false, false, false, false);
        
        if (adminPassword != null && !alwaysPrompt) {
            //If we got here, then the admin password was found in the command line, password file,
            //or environment variable
            //getPassword(optionName, allowedOnCommandLine, readPrefsFile, readPasswordOptionFromPrefs, readMasterPasswordFile, mgr, config,
            //promptUser, confirm, validate)
            String masterPassword = getPassword(MASTER_PASSWORD, false, false, false, false, null, null,
                false, false, confirmAndValidate, false);
            if (masterPassword == null) {
                //If we got here, then the master password was not found in the command line or
                //password file, so we return the default master password rather than prompting.
                return DEFAULT_MASTER_PASSWORD;
            } else {
                return masterPassword;
            }
        } 
        //If the admin user was not provided on the command line (i.e. the user was prompted), then
        //we can prompt for the master password.
        //getPassword(optionName, allowedOnCommandLine, readPrefsFile, readPasswordOptionFromPrefs, readMasterPasswordFile, mgr, config,
        //promptUser, confirm, validate)
        return getPassword(MASTER_PASSWORD, "MasterPasswordPrompt", "MasterPasswordConfirmationPrompt",
            false, false, false, false, null, null,  
            true, confirmAndValidate, confirmAndValidate, false);      
    
protected java.lang.StringgetMasterPassword(com.sun.enterprise.admin.servermgmt.RepositoryManager mgr, com.sun.enterprise.admin.servermgmt.RepositoryConfig config)

        //getPassword(optionName, allowedOnCommandLine, readPrefsFile, readPasswordOptionFromPrefs, readMasterPasswordFile, config,
        //promptUser, confirm, validate)
        return getPassword(MASTER_PASSWORD, "MasterPasswordPrompt", null, 
            false, false, false, true, mgr, config, 
            true, false, false, false);
    
protected java.lang.StringgetNewMasterPassword()

        return getPassword(NEW_MASTER_PASSWORD, 
            "NewMasterPasswordPrompt", "NewMasterPasswordConfirmationPrompt", 
            false, false, false, false, null, null, 
            true, true, true, false);
    
protected java.lang.BooleangetSaveMasterPassword(java.lang.String masterPassword)

        Boolean saveMasterPassword = Boolean.valueOf(getBooleanOption(SAVE_MASTER_PASSWORD));
        if (masterPassword != null && masterPassword.equals(DEFAULT_MASTER_PASSWORD)) {
            saveMasterPassword = Boolean.TRUE;
        }
        return saveMasterPassword;
    
protected booleanisSpaceInPath(java.lang.String path)

        return path.indexOf(' ") != -1;
    
protected booleanisWindows()

        final String osname = System.getProperty("os.name").toLowerCase();
        CLILogger.getInstance().printDebugMessage("osname = " + osname);
        return osname.indexOf("windows") != -1;