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

AMXCreateResourceCommand

public class AMXCreateResourceCommand extends S1ASCommand
version
$Revision: 1.4 $

Fields Summary
public static final String
DOMAIN_CONFIG_OBJECT_NAME
public static final String
SERVER_CONFIG_OBJECT_NAME
public static final String
CLUSTER_CONFIG_OBJECT_NAME
public static final String
TARGET_NAME
Constructors Summary
Methods Summary
public voiddisplayExceptionMessage(java.lang.Exception e)
This routine will display the exception message if the option --terse is given. This routine will get the root of the exception and display the message. It will then wrap it with CommaneException and throw the exception to be handled by CLI framework.

param
e
throws
CommandException

            //get the root cause of the exception
        Throwable rootException = ExceptionUtil.getRootCause(e);
        
        if (rootException.getLocalizedMessage() != null)
            CLILogger.getInstance().printDetailMessage(rootException.getLocalizedMessage());
        throw new CommandException(getLocalizedString("CommandUnSuccessful",
                                                      new Object[] {name} ), e);

    
private javax.management.ObjectNamegetTargetConfigObjectName(javax.management.MBeanServerConnection mbsc, java.lang.String targetName)
This routine will get the StandaloneServerConfig or ClusterConfig by the given target name.

param
MBeanServerConnection
param
targetName
return
ObjectName

        try {
            ObjectName scON = Util.newObjectName(SERVER_CONFIG_OBJECT_NAME+targetName);
            if (!mbsc.isRegistered(scON))
                scON = Util.newObjectName(CLUSTER_CONFIG_OBJECT_NAME+targetName);
            if (!mbsc.isRegistered(scON))
                throw new CommandException(getLocalizedString("InvalidTargetName"));
        
            return scON;            
        }
        catch (RuntimeOperationsException roe)
        {
            throw new CommandException(roe);
        }
        catch (IOException ioe)
        {
            throw new CommandException(ioe);
        }
    
public voidrunCommand()
An abstract method that Executes the command

throws
CommandException

        if (!validateOptions())
            throw new CommandValidationException("Validation is false");


        //use http connector
        MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), getPort(), 
                                                              getUser(), getPassword());
        final String targetName = (String)getOption(TARGET_NAME);
        
            //if targetName is not null, then try to get the Config ObjectName of the
            //target before creating the resource because we don't want to create
            //the resource if the target does not exist.
        ObjectName scON = (targetName!=null && !targetName.equals(DOMAIN))?
                          getTargetConfigObjectName(mbsc, targetName):null;

        final Object[] params = getParamsInfo();
        final String operationName = getOperationName();
        final String[] types = getTypesInfo();
        
        try {
            Object returnValue = mbsc.invoke(Util.newObjectName(DOMAIN_CONFIG_OBJECT_NAME),
                                             operationName,
                                             params, types);
            if (scON!=null)
            {
                //create reference to the target
                mbsc.invoke(scON, "createResourceRefConfig",
                            new Object[]{new String((String)getOperands().get(0))},
                            new String[]{"java.lang.String"} );
            }
            CLILogger.getInstance().printDetailMessage(getLocalizedString(
                                                       "CommandSuccessful",
                                                       new Object[] {name}));

        }
        catch (Exception e) {
            displayExceptionMessage(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


                                                             
        
    
    	return super.validateOptions();