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

GlobalsManager

public class GlobalsManager extends Object
A utility class which sets and gets the command environment, user input information.

Fields Summary
private static GlobalsManager
sGlobalsMgr
private ICommandEnvironment
mGlobalCommandEnvironment
private static HashMap
resourceBundles
private static String
COMMANDS_BASE_PACKAGE
private static final String
FRAMEWORK_BASE_PACKAGE
private static String
FRAMEWORK_PROPERTY_FILE_NAME
private static String
COMMANDS_PROPERTY_FILE_NAME
Constructors Summary
protected GlobalsManager()
A constructor which is accessed by it's sub classes only.


                          

      
		this(new CommandEnvironment());
	
protected GlobalsManager(ICommandEnvironment env)

	  mGlobalCommandEnvironment = env;
	  resourceBundles = new HashMap();
    
Methods Summary
public static java.lang.StringgetFrameworkString(java.lang.String key)

        return getString(key, FRAMEWORK_BASE_PACKAGE, 
                            FRAMEWORK_PROPERTY_FILE_NAME);
    
public static java.lang.StringgetFrameworkString(java.lang.String key, java.lang.Object[] toInsert)

        return getString(key, toInsert, FRAMEWORK_BASE_PACKAGE, 
                            FRAMEWORK_PROPERTY_FILE_NAME);
    
public ICommandEnvironmentgetGlobalsEnv()
Returns the command environment that is set in in GlobalsManager.

        return mGlobalCommandEnvironment;
    
public static synchronized com.sun.enterprise.cli.framework.GlobalsManagergetInstance()
Returns the instance of the GlobalsManager through this object, the caller can access all the methods in this class.

        if( sGlobalsMgr == null )
        {
            sGlobalsMgr = new GlobalsManager();
        }
        return sGlobalsMgr;
    
public java.lang.StringgetOption(java.lang.String optionName)
Returns the option value that is set in GlobalsManager.

param
optionName is the name of the option.

        String optionValue = (String)mGlobalCommandEnvironment.getEnvironmentValue(optionName );
        return optionValue;
    
private static java.util.ResourceBundlegetResourceBundle(java.lang.String packageName, java.lang.String propertyFile)

        ResourceBundle resBundle = (ResourceBundle) resourceBundles.get(packageName);
        if (resBundle == null)
        {
            try
            {
                resBundle = ResourceBundle.getBundle(
                                packageName + "." + propertyFile);
                resourceBundles.put(packageName, resBundle);
            }
            catch(java.util.MissingResourceException mre)
            {
                throw new CommandException(mre.getLocalizedMessage());
            }
        }
        return resBundle;
    
public static java.lang.StringgetString(java.lang.String key)

        return getString(key, COMMANDS_BASE_PACKAGE, 
                            COMMANDS_PROPERTY_FILE_NAME);
    
public static java.lang.StringgetString(java.lang.String key, java.lang.Object[] toInsert)

        return getString(key, toInsert, COMMANDS_BASE_PACKAGE, 
                            COMMANDS_PROPERTY_FILE_NAME);
    
private static java.lang.StringgetString(java.lang.String key, java.lang.String basePkg, java.lang.String propertyFile)

        return getResourceBundle(basePkg, propertyFile).getString(key);
    
private static java.lang.StringgetString(java.lang.String key, java.lang.Object[] toInsert, java.lang.String basePkg, java.lang.String propertyFile)

        String fmtStr = null;
        try
        {
            ResourceBundle resBundle = getResourceBundle(basePkg, propertyFile);
            MessageFormat msgFormat = 
                        new MessageFormat(resBundle.getString(key));
            fmtStr = msgFormat.format(toInsert);
        }
        catch(Exception e)
        {
            throw new CommandException(e.getLocalizedMessage());
        }
        return fmtStr;
    
public static voidmain(java.lang.String[] args)

        try
        {
            GlobalsManager globalsMgr = GlobalsManager.getInstance();
            System.out.println(globalsMgr.getFrameworkString("junk", new Object[]{"junk", "prashanth"}));
            globalsMgr.setBasePackage("com.sun.enterprise.cli.commands");
            System.out.println(globalsMgr.getString("junk", new Object[]{"junk", "prashanth"}));
        }
        catch(CommandException ce)
        {
            ce.printStackTrace();
        }
    
public voidremoveOption(java.lang.String optionName)
Removes the option from the options list

        mGlobalCommandEnvironment.removeEnvironment(optionName);
    
public static voidsetBasePackage(java.lang.String basePkg)

        COMMANDS_BASE_PACKAGE = basePkg;
    
public voidsetGlobalsEnv(ICommandEnvironment env)
Sets the global command environment. (global means the set of options which are base/common options to all the subcommands).

param
env is the command environment to be set.

        mGlobalCommandEnvironment = env;
    
public static synchronized voidsetInstance(com.sun.enterprise.cli.framework.GlobalsManager globalsMgr)
Sets the GlobalsManager object.

param
globalsMgr is the GlobalsManager object to be set.

        if ( sGlobalsMgr != globalsMgr )
        {
            sGlobalsMgr = globalsMgr;
        }
    
public voidsetOption(java.lang.String name, java.lang.String value)
Sets the Option object in the GlobalsManager.

param
option is the Option object to be set.

        mGlobalCommandEnvironment.setEnvironment(name, value);
    
public static voidsetPropertyFile(java.lang.String fileName)

        COMMANDS_PROPERTY_FILE_NAME = fileName;