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

AMXListResourcesCommand

public class AMXListResourcesCommand 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 voiddisplayMap(java.lang.String msg, java.util.Map m)
Display a Map to System.out.

        final Set keySet = m.keySet();
        if (keySet.isEmpty()) {
            CLILogger.getInstance().printDetailMessage(
                getLocalizedString("NoElementsToList"));
            return;
        }
        final Iterator keyIter = keySet.iterator();
        
        while (keyIter.hasNext()) {
            final String valueName = (String)keyIter.next();
            CLILogger.getInstance().printMessage(msg + " " + valueName );
        }
    
private java.util.MapgetResourcesFromTarget(javax.management.MBeanServerConnection mbsc, javax.management.ObjectName targetON, java.util.Map candidates)
Given the Server/Cluster ObjectName, get all the referenced resources. Then loop through the given resources in the DomainConfig to determine the referenced resources in the ObjectName.

param
mbsc
param
targetON
return
Map of the referenced resources

        Object resourceRefs = mbsc.invoke(targetON,
                                          "getContaineeObjectNameMap",
                                          new Object[]{new String(XTypes.RESOURCE_REF_CONFIG)},
                                          new String[]{"java.lang.String"});

        final Set resourceKeySet = ((Map)resourceRefs).keySet();
        final Iterator resourceKeyIter = resourceKeySet.iterator();
        Map resMap = new HashMap();
        while (resourceKeyIter.hasNext()) {
            final String valueName = (String)resourceKeyIter.next();
            CLILogger.getInstance().printDebugMessage("Candidate = " + valueName );
            if (candidates.containsKey(valueName)) {
                resMap.put(valueName, candidates.get(valueName));
            }
        }
        return resMap;
    
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 Vector vTargetName = getOperands();
        final String targetName = (vTargetName.size()>0)?(String)vTargetName.get(0):null;
        
            //if targetName is not null, then try to get the Config ObjectName of the
            //target.
        ObjectName targetON = (targetName!=null && !targetName.equals(DOMAIN))?
                              getTargetConfigObjectName(mbsc, targetName):null;
        
        final Object[] params = getParamsInfo();
        final String operationName = getOperationName();
        final String[] types = getTypesInfo();
        final String j2eeType = (String) ((Vector) getProperty(PARAMS)).get(0);

        try {
            Object resources = mbsc.invoke(Util.newObjectName(DOMAIN_CONFIG_OBJECT_NAME),
                                           operationName,
                                           params, types);

            Map candidates = (Map)resources;

            if (targetON != null ) {
                candidates = getResourcesFromTarget(mbsc, targetON, candidates);
            }
            displayMap("", (Map)candidates);
            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();