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

UndeployCommand

public class UndeployCommand extends S1ASCommand
Undeploy command
version
$Revision: 1.5 $

Fields Summary
private static final String
CASCADE_OPTION
private static final String
DROPTABLES_OPTION
private static final String
TARGET_OPTION
Constructors Summary
Methods Summary
private java.util.MapcreateDeploymentProperties()
creates the DeployProperties which is used as a parameter to the deploy operation.

        Properties props = new Properties();
        final String cascadeOption   = getOption(CASCADE_OPTION);
        final String dropTablesOption = getOption(DROPTABLES_OPTION);
        final String target = getOption(TARGET_OPTION);                
                
        if (props != null) 
            props.put(DeploymentProperties.TARGET, target);        

     	props.put(DeploymentProperties.NAME, getComponentName() );

        if (cascadeOption != null)
            props.put(DeploymentProperties.CASCADE, cascadeOption);
        if (dropTablesOption != null)
            props.put(Constants.CMP_DROP_TABLES, dropTablesOption);
        return props;
    
private java.lang.StringgetComponentName()
this method returns the componet_name operand

return
component_name

        return (String) getOperands().get(0);
    
public voidrunCommand()
An abstract method that Executes the command

throws
CommandException


                    
       
          
    
        validateOptions();

        DeploymentFacility df = DeploymentFacilityFactory.getDeploymentFacility();
        ServerConnectionIdentifier conn = createServerConnectionIdentifier(
            getHost(), getPort(), getUser(), getPassword());
        df.connect(conn);

        //prepare data
        //Target[] targets = new JESTarget[1];
        final String targetName = getOption(TARGET_OPTION);
        //targets[0] = new JESTarget(targetName, null);
        Map deployOptions = createDeploymentProperties();

        JESProgressObject progressObject = null;
        
        try
        {
            if (df.isConnected())
            {
                CLILogger.getInstance().printDebugMessage("Calling the undeploy with DeployOptions");
                Target[] targets = df.createTargets(new String[]{targetName});
                if (targets == null)
                {
                    //CLILogger.getInstance().printError(getLocalizedString("InvalidTarget"));
                    throw new CommandException(getLocalizedString("InvalidTarget", new Object[] {targetName}));
                }

                progressObject = df.undeploy(targets, getComponentName(), deployOptions);
            } else
            {
                CLILogger.getInstance().printError(
                                   getLocalizedString("CouldNotConnectToDAS"));
            }
        }
        catch (Exception e)
        {
            if (e.getLocalizedMessage() != null)
                CLILogger.getInstance().printDetailMessage(
                    e.getLocalizedMessage());

            throw new CommandException(getLocalizedString(
                "CommandUnSuccessful", new Object[] {name} ), e);
        }

        DeploymentStatus status = df.waitFor(progressObject);
        final String statusString = status.getStageStatusMessage();


        if (status != null &&
            status.getStatus() == DeploymentStatus.FAILURE) {
            throw new CommandException(getLocalizedString(
                "CommandUnSuccessfulWithMsg", new Object[] {name,
                statusString} ));
        } else if (status != null &&
            status.getStatus() == DeploymentStatus.WARNING) {
            CLILogger.getInstance().printDetailMessage(getLocalizedString(
                "CommandSuccessfulWithMsg",
                new Object[] {name, statusString}));
        } else {
            CLILogger.getInstance().printDetailMessage(getLocalizedString(
                "CommandSuccessful", new Object[] {name} ));
        }

    
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

        return super.validateOptions();