(MBeanServerConnection mbsc, ObjectInstance instance, String subCommand)
| 416 | } |
| 417 | |
| 418 | public static Object doSubCommand(MBeanServerConnection mbsc, ObjectInstance instance, String subCommand) |
| 419 | throws Exception { |
| 420 | // First, handle special case of our being asked to destroy a bean. |
| 421 | if (subCommand.equals("destroy")) { |
| 422 | mbsc.unregisterMBean(instance.getObjectName()); |
| 423 | return null; |
| 424 | } else if (subCommand.startsWith(CREATE_CMD_PREFIX)) { |
| 425 | throw new IllegalArgumentException("You cannot call create " + "on an already existing bean."); |
| 426 | } |
| 427 | |
| 428 | // Get attribute and operation info. |
| 429 | MBeanAttributeInfo[] attributeInfo = mbsc.getMBeanInfo(instance.getObjectName()).getAttributes(); |
| 430 | MBeanOperationInfo[] operationInfo = mbsc.getMBeanInfo(instance.getObjectName()).getOperations(); |
| 431 | // Now, bdbje JMX bean doesn't follow the convention of attributes |
| 432 | // having uppercase first letter and operations having lowercase |
| 433 | // first letter. But most beans do. Be prepared to handle the bdbje |
| 434 | // case. |
| 435 | Object result = null; |
| 436 | if (Character.isUpperCase(subCommand.charAt(0))) { |
| 437 | // Probably an attribute. |
| 438 | if (!isFeatureInfo(attributeInfo, subCommand) && isFeatureInfo(operationInfo, subCommand)) { |
| 439 | // Its not an attribute name. Looks like its name of an |
| 440 | // operation. Try it. |
| 441 | result = doBeanOperation(mbsc, instance, subCommand, operationInfo); |
| 442 | } else { |
| 443 | // Then it is an attribute OR its not an attribute name nor |
| 444 | // operation name and the below invocation will throw a |
| 445 | // AttributeNotFoundException. |
| 446 | result = doAttributeOperation(mbsc, instance, subCommand, attributeInfo); |
| 447 | } |
| 448 | } else { |
| 449 | // Must be an operation. |
| 450 | if (!isFeatureInfo(operationInfo, subCommand) && isFeatureInfo(attributeInfo, subCommand)) { |
| 451 | // Its not an operation name but looks like it could be an |
| 452 | // attribute name. Try it. |
| 453 | result = doAttributeOperation(mbsc, instance, subCommand, attributeInfo); |
| 454 | } else { |
| 455 | // Its an operation name OR its neither operation nor attribute |
| 456 | // name and the below will throw a NoSuchMethodException. |
| 457 | result = doBeanOperation(mbsc, instance, subCommand, operationInfo); |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | // Look at the result. Is it of composite or tabular type? |
| 462 | // If so, convert to a String representation. |
| 463 | if (result instanceof CompositeData) { |
| 464 | result = recurseCompositeData(new StringBuffer("\n"), "", "", (CompositeData) result); |
| 465 | } else if (result instanceof TabularData) { |
| 466 | result = recurseTabularData(new StringBuffer("\n"), "", "", (TabularData) result); |
| 467 | } else if (result instanceof String[]) { |
| 468 | String[] strs = (String[]) result; |
| 469 | StringBuffer buffer = new StringBuffer("\n"); |
| 470 | for (int i = 0; i < strs.length; i++) { |
| 471 | buffer.append(strs[i]); |
| 472 | buffer.append("\n"); |
| 473 | } |
| 474 | result = buffer; |
| 475 | } else if (result instanceof AttributeList) { |
no test coverage detected