Methods Summary |
---|
public void | displayExceptionMessage(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.
//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 void | displayMap(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.Map | getResourcesFromTarget(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.
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.ObjectName | getTargetConfigObjectName(javax.management.MBeanServerConnection mbsc, java.lang.String targetName)This routine will get the StandaloneServerConfig or ClusterConfig
by the given target name.
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 void | runCommand()An abstract method that Executes the command
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 boolean | validateOptions()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 super.validateOptions();
|