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

JBICommand

public abstract class JBICommand extends S1ASCommand
Will start the JBI component on the specified target.
version
$Revision: 1.13 $

Fields Summary
static final String
VERBOSE
static final String
TERSE
static final String
TARGET_OPTION
static final String
LIBRARY_NAME_OPTION
static final String
ASSEMBLY_NAME_OPTION
static final String
COMPONENT_NAME_OPTION
static final String
UPLOAD_OPTION
static final String
ENABLED_OPTION
static final String
LIFECYCLE_STATE_OPTION
static final String
FORCE_OPTION
static final String
KEEP_ARCHIVE_OPTION
static final String
COMPONENT_PROPERTIES
static String[]
validStates
com.sun.jbi.ui.common.JBIAdminCommands
mJbiAdminCommands
MBeanServerConnection
mbsc
Constructors Summary
Methods Summary
private java.lang.StringcreateFillString(char fillChar, int size)
Will create a string of the size specified filled with the fillChar.

param
fillChar the character to create the string with
param
the size of the string

        String fillString = "";
        for (int i=0; i<size; i++)
        {
            fillString += fillChar;
        }
        return fillString;
    
protected com.sun.jbi.ui.common.JBIManagementMessageextractJBIManagementMessage(java.lang.Exception ex)
Will extract the JBIManagementMessgae from the Remote exception.

param
ex the exception to process

        JBIManagementMessage mgmtMsg = null;
        if (ex instanceof JBIRemoteException)
        {
            JBIRemoteException rEx = (JBIRemoteException)ex;
            mgmtMsg = rEx.extractJBIManagementMessage();
        }
        else
        {
            String exMessage = ex.getMessage();
            mgmtMsg = JBIManagementMessage.createJBIManagementMessage(exMessage);
        }
        return mgmtMsg;
    
private java.lang.StringformatDescription(java.lang.String description, int maxLength, int indentAmount)
Will format the description text that is displayed in the show commands. The formatting will consist of removing all new lines and extra white space, then adding back in line breaks at the first avaliable location that is less then or equal to the given max line length.

param
description the description text to format
param
maxLength the maximum line length size.
param
indentAmout the amount to indent row 2 - n


        // Strip out the leading white spaces in each row, and remove any "\n"
        int endIndex = 0;
        int startIndex = 0;
        String finalString = "";
        String rowString = "";
        String space = "";
        endIndex = description.indexOf("\n",startIndex);
        while (endIndex != -1)
        {   
            rowString = description.substring(startIndex,endIndex).trim();
            finalString += space + rowString;
            startIndex = endIndex + 1;
            endIndex = description.indexOf("\n",startIndex);
            space = " ";
        }
        rowString = description.substring(startIndex).trim();
        finalString += space + rowString;

        // Format the string by adding the line breaks in the correct location and adding
        // the indention amount at that beginning of each row.
        endIndex = 0;
        startIndex = 0;
        int spaceIndex = 0;
        int indentSize = 0;
        String newString = "";
        boolean done = false;
        int totalLength = finalString.length();
        while (!(done))
        {
            endIndex = ((startIndex + maxLength) > totalLength) ? totalLength : (startIndex + maxLength);
            rowString = finalString.substring(startIndex,endIndex);
            spaceIndex = startIndex + rowString.lastIndexOf(" ");
            if (endIndex < totalLength)
            {
                spaceIndex = startIndex + rowString.lastIndexOf(" ");
                if (spaceIndex != -1)
                {
                    endIndex = spaceIndex;
                }
            }
            rowString = finalString.substring(startIndex,endIndex) + "\n";
            startIndex = endIndex + 1;
            newString += createFillString(' ",indentSize) + rowString;
            indentSize = indentAmount;
            if (startIndex >= totalLength)
            {
                done = true;
            }
        }
        finalString = newString.trim();
        return finalString;
    
protected java.lang.StringgetOption(java.lang.String optionName, java.lang.String[] validOptions, java.lang.String defaultValue)
Method that will return the option value or if no option value was specified, the default value will be returned.

param
optionName The option name use to retrieve the value
param
validOptions An array containing a list of valid options
param
defaultValue The default value returned if no option value exists
return
The option value
throws
CommandValidationException

        boolean found = false;
        String option = getOption(optionName);
        if (option == null)
        {
            option = defaultValue;
            found = true;
        }
        else
        {
            for (int i=0; i<validOptions.length; i++)
            {
                if (option.equalsIgnoreCase(validOptions[i]))
                {
                    found = true;
                    break;
                }
            }
        }
        if (found) {
            return option;
        }
        else {
            throw new CommandValidationException(getLocalizedString("InvalidValueInOption",
                                                    new Object[]{optionName}));
        }
    
protected java.lang.StringgetOption(java.lang.String optionName, java.lang.String[] validOptions)
Method that will return the option value or if no option value was specified, the default value will be returned.

param
optionName The option name use to retrieve the value
param
validOptions An array containing a list of valid options
return
The option value
throws
CommandValidationException

        String defaultValue = null;
        return getOption(optionName, validOptions, defaultValue);
    
protected booleanpreRunInit()
Perform the pre run initialization. This will validate the options as well as retrieve the MBean Server Connection.

throws
CommandValidationException
throws
CommandException
throws
JBIRemoteException

        boolean uploadFlag = false;
        return preRunInit(uploadFlag);
    
protected booleanpreRunInit(boolean uploadFlag)
Perform the pre run initialization. This will validate the options as well as retrieve the MBean Server Connection.

param
uploadFlag The upload flag
throws
CommandValidationException
throws
CommandException
throws
JBIRemoteException

        // Validate the options and opeands
        validateOptions();

        // For Testing only -- Will remove later --
        //validateUsageText();

        // Retrieve the MBean Server Connection and the JBIAdminCommands object.
        mbsc = getMBeanServerConnection(getHost(), 
                                        getPort(), 
                                        getUser(), 
                                        getPassword());
        
        // Retrieve the JBI Admin Command object
        try {
            mJbiAdminCommands = JBIAdminCommandsClientFactory.getInstance(mbsc,uploadFlag);
        }
        catch (Exception e) {
            displayExceptionMessage(e);
        }

        // Make sure we have a valid command object
        if (mJbiAdminCommands == null)
        {
            throw new CommandException(getLocalizedString("CouldNotInvokeCommand",
                                                    new Object[]{name}));
        }
        return true;
    
protected voidprocessJBIAdminAsseblyListResult(java.lang.String result)
Will process the list results for the Service Assemblies

param
result The result xml string

        List list = ServiceAssemblyInfo.readFromXmlTextWithProlog(result);
        if (list.size() == 0)
        {
            CLILogger.getInstance().printDetailMessage (
                    getLocalizedString ("NoElementsToList",new Object[] {result}));
        }
        else
        {
            Iterator it = list.iterator();
            String listBreak = "";
            int count = 0;
            while (it.hasNext())
            {
                ServiceAssemblyInfo info = ((ServiceAssemblyInfo)it.next());
                String assemblyName = info.getName();
                CLILogger.getInstance().printDetailMessage (assemblyName);

                // TBD append global state info to end of name
                //String assemblyName = info.getName();
                //String state = info.getState();
                //String outputString = assemblyName + " : " + state;
                //CLILogger.getInstance().printDetailMessage (outputString);
            }
        }
    
protected voidprocessJBIAdminComponentListResult(java.lang.String result)
Will process the list results for the components (Service Engines, Binding Components and Shared Libraries). was specified, the default value will be returned.

param
result The result xml string

        List list = JBIComponentInfo.readFromXmlText(result);
        if (list.size() == 0)
        {
            CLILogger.getInstance().printDetailMessage (
                    getLocalizedString ("NoElementsToList",new Object[] {result}));
        }
        else
        {
            Iterator it = list.iterator();
            String listBreak = "";
            int count = 0;
            while (it.hasNext())
            {
                JBIComponentInfo info = ((JBIComponentInfo)it.next());
                String componentName = info.getName();
                CLILogger.getInstance().printDetailMessage (componentName);

                // TBD append global state info to end of name
                //String componentName = info.getName();
                //String state = info.getState();
                //String outputString = componentName + " : " + state;
                //CLILogger.getInstance().printDetailMessage (outputString);
            }
        }
    
protected voidprocessJBIAdminResult(java.lang.String result, java.lang.String successKey)
** Still Under Development ** Will process the list results for the Service Assemblies

param
result The result xml string

        JBIManagementMessage mgmtMsg =
            JBIManagementMessage.createJBIManagementMessage(result);
        if (mgmtMsg == null)
        {
            CLILogger.getInstance().printDetailMessage (
                    getLocalizedString (successKey, new Object[] {result}));
        }
        else
        {
            if (mgmtMsg.isSuccessMsg())
            {
                String msg = mgmtMsg.getMessage();
                int index = msg.indexOf(")");
                if (index != -1)
                {
                    msg = msg.substring(index+1);
                }
                CLILogger.getInstance().printDetailMessage (msg);
            }
            else
            {
                String msg = mgmtMsg.getMessage();
                throw new CommandException(msg);
            }
        }
    
protected voidprocessJBIAdminShowAssemblyResult(java.lang.String result, java.lang.String aName)
Will format and display the Service Assembly show results.

param
result the xml string containing the result information
param
aName the name of the service assembly

        List list = ServiceAssemblyInfo.readFromXmlTextWithProlog(result);
        
        if ( list.size() <= 0 )
        {
            CLILogger.getInstance().printDetailMessage (
                    getLocalizedString ("JBINoServiceAssemblyToShow",new Object[] {aName}));
        }
        else
        {
           Iterator itr = list.iterator();
           ServiceAssemblyInfo saInfo = (ServiceAssemblyInfo) itr.next();
           List suInfoList = saInfo.getServiceUnitInfoList();

           String saName = saInfo.getName();
           String saState = saInfo.getState();
           String saDescription = saInfo.getDescription();
           String saSize = Integer.toString(suInfoList.size());
           String formattedSADescription = formatDescription(saDescription,50,16);
           
           CLILogger.getInstance().printDetailMessage ("");
           String SAHeader = getLocalizedString ("JBIServiceAssemblyShowHeader");
           CLILogger.getInstance().printDetailMessage (SAHeader);
           CLILogger.getInstance().printDetailMessage (createFillString('-",SAHeader.length()));
           CLILogger.getInstance().printDetailMessage (
                   getLocalizedString ("JBIServiceAssemblyName",new Object[] {saName}));
           CLILogger.getInstance().printDetailMessage (
                   getLocalizedString ("JBIServiceAssemblyState",new Object[] {saState}));
           CLILogger.getInstance().printDetailMessage (
                   getLocalizedString ("JBIServiceAssemblyServiceUnits",new Object[] {saSize}));
           CLILogger.getInstance().printDetailMessage (
                   getLocalizedString ("JBIServiceAssemblyDescription",new Object[] {formattedSADescription}));

           String indentString = "    ";
           CLILogger.getInstance().printDetailMessage ("");
           String SUHeader = getLocalizedString ("JBIServiceUnitShowHeader");
           CLILogger.getInstance().printDetailMessage (indentString + SUHeader);
           CLILogger.getInstance().printDetailMessage (indentString + createFillString('-",SUHeader.length()));
           boolean firstTime = true;
           for (Iterator suItr = suInfoList.iterator(); suItr.hasNext();)
           {
               ServiceUnitInfo suInfo = (ServiceUnitInfo ) suItr.next();
               String suState = suInfo.getState();
               String suDepoyedOn = suInfo.getDeployedOn();
               String suName = suInfo.getName();
               String suDescription = suInfo.getDescription();
               String formattedSUDescription = formatDescription(suDescription,50,18);
               if (!(firstTime))
               {
                   CLILogger.getInstance().printDetailMessage ("");
               }
               CLILogger.getInstance().printDetailMessage (indentString +
                       getLocalizedString ("JBIServiceUnitName",new Object[] {suName}));
               CLILogger.getInstance().printDetailMessage (indentString +
                       getLocalizedString ("JBIServiceUnitState",new Object[] {suState}));
               CLILogger.getInstance().printDetailMessage (indentString +
                       getLocalizedString ("JBIServiceUnitDeployedOn",new Object[] {suDepoyedOn}));
               CLILogger.getInstance().printDetailMessage (indentString +
                       getLocalizedString ("JBIServiceUnitDescription",new Object[] {formattedSUDescription}));
               firstTime = false;
           }
        }
    
protected voidprocessJBIAdminShowComponentResult(java.lang.String result, java.lang.String aName)
Will format and display the component (binding or engine) show results.

param
result the xml string containing the result information
param
aName the name of the component

        List list = JBIComponentInfo.readFromXmlText(result);
        if (list.size() == 0)
        {
            CLILogger.getInstance().printDetailMessage (
                    getLocalizedString ("JBINoComponentToShow",new Object[] {aName}));
        }
        else
        {
            CLILogger.getInstance().printDetailMessage ("");
            String header = getLocalizedString ("JBIComponentShowHeader");
            CLILogger.getInstance().printDetailMessage (header);
            CLILogger.getInstance().printDetailMessage (createFillString('-",header.length()));

            Iterator it = list.iterator();
            JBIComponentInfo info = ((JBIComponentInfo)it.next());
            String componentName = info.getName();
            String componentState = info.getState();
            String componentDescription = info.getDescription();
            String formattedDescription = formatDescription(componentDescription,50,14);
            CLILogger.getInstance().printDetailMessage (
                    getLocalizedString ("JBIComponentName",new Object[] {componentName}));
            CLILogger.getInstance().printDetailMessage (
                    getLocalizedString ("JBIComponentState",new Object[] {componentState}));
            CLILogger.getInstance().printDetailMessage (
                    getLocalizedString ("JBIComponentDescription",new Object[] {formattedDescription}));
       }
    
protected voidprocessJBIAdminShowLibraryResult(java.lang.String result, java.lang.String aName)
Will format and display the Shared Library show results.

param
result the xml string containing the result information
param
aName the name of the shared library

        List list = JBIComponentInfo.readFromXmlText(result);
        if (list.size() == 0)
        {
            CLILogger.getInstance().printDetailMessage (
                    getLocalizedString ("JBINoLibraryToShow",new Object[] {aName}));
        }
        else
        {
            CLILogger.getInstance().printDetailMessage ("");
            String header = getLocalizedString ("JBISharedLibraryShowHeader");
            CLILogger.getInstance().printDetailMessage (header);
            CLILogger.getInstance().printDetailMessage (createFillString('-",header.length()));

            Iterator it = list.iterator();
            JBIComponentInfo info = ((JBIComponentInfo)it.next());
            String libraryName = info.getName();
            String libraryDescription = info.getDescription();
            String formattedDescription = formatDescription(libraryDescription,50,14);
            CLILogger.getInstance().printDetailMessage (
                    getLocalizedString ("JBISharedLibraryName",new Object[] {libraryName}));
            CLILogger.getInstance().printDetailMessage (
                    getLocalizedString ("JBISharedLibraryDescription",new Object[] {formattedDescription}));
        }
    
protected voidprocessTaskException(java.lang.Exception ex)
Will process the task exception to display the error message.

param
ex the exception to process
throws
CommandException

        JBIManagementMessage mgmtMsg = extractJBIManagementMessage(ex);
        if (mgmtMsg == null)
        {
            displayExceptionMessage(ex);
        }
        else
        {
            // Display the exception message which was returned from the runtime.
            String msg = mgmtMsg.getMessage();
            CLILogger.getInstance().printDetailMessage (msg);
            
            // Display the CLI success or failure message.
            if (msg.trim().startsWith("WARNING")) {
                CLILogger.getInstance().printDetailMessage (
                    getLocalizedString ("CommandSuccessful",new Object[] {name}));
            }
            else {
                CLILogger.getInstance().printDetailMessage (
                    getLocalizedString ("CommandUnSuccessful",new Object[] {name}));
            }
        }
    
protected java.lang.StringvalidateFilePath(java.lang.String filePath)
Method that will validate that the given file path exists and is not a directory.

param
filePath The file path
throws
CommandException
return
String the absolute file path

        return validateFilePath ("FileDoesNotExist",filePath);
    
protected java.lang.StringvalidateFilePath(java.lang.String errorKey, java.lang.String filePath)
Method that will validate that the given file path exists and is not a directory.

param
errorKey The property key value used to retrieve the error message text
param
filePath The file path
return
String the absolute file path
throws
CommandException

        File file = new File(filePath);
        String absolutePath = file.getAbsolutePath();
        if ((!file.exists()) || (file.isDirectory()))
        {
            throw new CommandException(getLocalizedString(errorKey,
                                                    new Object[]{filePath}));
        }
        return absolutePath;
    
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
throws
CommandValidationException


                                                                
        
    
    	return super.validateOptions();