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

ListSubComponentsCommand

public class ListSubComponentsCommand extends S1ASCommand
Lists the submodules of a deployed component
version
$Revision: 1.4 $

Fields Summary
private static final String
GET_MODULE_COMPONENTS
private static final String
APPNAME_OPTION
private static final String
TYPE_OPTION
private static final String
EJBS
private static final String
SERVLETS
private static final String
EJB_SUB_MODULE
private static final String
SERVLET_SUB_MODULE
private static final String
TYPE_OPTION_VALUES
Constructors Summary
Methods Summary
private java.lang.Object[]getParams(java.lang.String appname)
Returns the paramters to use to pass into GET_MODULE_COMPONENTS method

param
appname - appname if appname is null then returns the paramter without appname.
return
the parameter in Object[]

	if (appname == null)
	{
	    return new Object[] {(String)getOperands().get(0)};
	}
	else
	{
	    return new Object[] {appname, (String)getOperands().get(0)};
	}
    
private java.lang.String[]getTypes(java.lang.String appname)
Returns the types to use for GET_MODULE_COMPONENTS method

param
appname - appname if appname is null then returns the type without appname.
return
the type in String[]

	if (appname == null)
	{
            return new String[] {String.class.getName()};
	}
	else
	{
            return new String[] {String.class.getName(), String.class.getName()};
	}
    
private voidprintDebug(javax.management.MBeanServerConnection mbsc, java.lang.String objectName)
This method prints the objecName info for debugging purpose

	CLILogger.getInstance().printDebugMessage("********** getMBeanInfo **********");
	final javax.management.MBeanInfo mbinfo = mbsc.getMBeanInfo(new ObjectName(objectName));
	CLILogger.getInstance().printDebugMessage("Description = " + mbinfo.getDescription());
	CLILogger.getInstance().printDebugMessage("Classname = " + mbinfo.getClassName());
        final javax.management.MBeanOperationInfo[] mboinfo = mbinfo.getOperations();
	for (int ii=0; ii<mboinfo.length; ii++) 
	{
	    CLILogger.getInstance().printDebugMessage("("+ii+") Description = " + 
						      mboinfo[ii].getDescription());
	    CLILogger.getInstance().printDebugMessage("("+ii+") Name = " + 
						      mboinfo[ii].getName());
	    CLILogger.getInstance().printDebugMessage("****** TYPE *****");
	    final javax.management.MBeanParameterInfo[]  mbpi  = mboinfo[ii].getSignature();
	    for (int kk=0; kk<mbpi.length; kk++)
	    {
		CLILogger.getInstance().printDebugMessage("type = " + mbpi[kk].getType());
	    }
 	    CLILogger.getInstance().printDebugMessage("returnType = " + mboinfo[ii].getReturnType());
	}
    
private voidprintObjectName(java.lang.Object returnValue, java.lang.String typeOption)
This method prints the object name.

param
return value from operation in mbean

	if (returnValue == null) 
        {
                    CLILogger.getInstance().printDetailMessage(
                                                getLocalizedString("NoElementsToList"));
        }
	try 
	{
	    if (returnValue.getClass().getName().equals(STRING_ARRAY))
	    {
		final String[] objs = (String[])returnValue;
                boolean nothingToList = true;

		for (int ii=0; ii<objs.length; ii++)
		{
		    CLILogger.getInstance().printDebugMessage("***** " + objs[ii]);
		    final ObjectName on = new ObjectName(objs[ii]);
                    if (typeOption != null)
                    {
                        if ((typeOption.equals(EJBS) && 
                             on.getKeyProperty("j2eeType").matches(EJB_SUB_MODULE)) ||
                            (typeOption.equals(SERVLETS) && 
                             on.getKeyProperty("j2eeType").matches(SERVLET_SUB_MODULE)))
                        {
                            printSubComponent(on); 
                            nothingToList=false;
                        }
                    }
                    else 
                    {
                        printSubComponent(on); 
                        nothingToList=false;
                    }
                }
	        if (nothingToList) 
                {
                    CLILogger.getInstance().printDetailMessage(
                                                getLocalizedString("NoElementsToList"));
                }
            }
        }
	catch (Exception e)
	{
	    throw new CommandException(e);
	}
    
private voidprintSubComponent(javax.management.ObjectName on)
This method prints the sub component name

        CLILogger.getInstance().printMessage(on.getKeyProperty("name") + " <"+
                                             on.getKeyProperty("j2eeType") + ">");
    
public voidrunCommand()
An abstract method that Executes the command

throws
CommandException

	validateOptions();

        final String objectName = getObjectName();
	final String appname = getOption(APPNAME_OPTION);
	final String typeOption = getOption(TYPE_OPTION);
	final Object[] params = getParams(appname);
        final String[] types = getTypes(appname);

	//use http connector
	final MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), getPort(), 
                                     getUser(), getPassword());
        try
        { 
	    //	    if (System.getProperty("Debug") != null) printDebug(mbsc, objectName);

	    Object returnValue = mbsc.invoke(new ObjectName(objectName), 
					     GET_MODULE_COMPONENTS, params, types);
	    printObjectName(returnValue, typeOption);
	    CLILogger.getInstance().printDetailMessage(getLocalizedString(
						       "CommandSuccessful",
						       new Object[] {name}));
        }
        catch(Exception e)
        { 
	    if (e.getLocalizedMessage() != null)
		CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage());
            throw new CommandException(getLocalizedString("CommandUnSuccessful",
						     new Object[] {name} ), e);
        }        
    
public booleanvalidateOptions()
An abstract method that validates the options on the specification in the xml properties file This method verifies for the correctness of number of operands and if all the required options are supplied by the client.

return
boolean returns true if success else returns false


                                                             
        
    
        //Check if the type option arguments are valid ejbs|servlets
	final String typeOption = getOption(TYPE_OPTION);
        if ((typeOption != null) && !typeOption.matches(TYPE_OPTION_VALUES))
            throw new CommandValidationException(getLocalizedString(
                                                     "InvalidTypeOption"));
    	return super.validateOptions();