490 }
491
492 /**
493 * Returns the ordered key property list that will be used to build the
494 * MBean tree. If the "com.sun.tools.jconsole.mbeans.keyPropertyList" system
495 * property is not specified, then the ordered key property list used
496 * to build the MBean tree will be the one returned by the method
497 * ObjectName.getKeyPropertyListString() with "type" as first key,
498 * and "j2eeType" as second key, if present. If any of the keys specified
499 * in the comma-separated key property list does not apply to the given
500 * MBean then it will be discarded.
501 */
502 private static String getKeyPropertyListString(ObjectName mbean) {
503 String props = mbean.getKeyPropertyListString();
504 Map<String, String> map = extractKeyValuePairs(props, mbean);
505 StringBuilder sb = new StringBuilder();
506 // Add the key/value pairs to the buffer following the
507 // key order defined by the "orderedKeyPropertyList"
508 for (String key : orderedKeyPropertyList) {
509 if (map.containsKey(key)) {
510 sb.append(key + "=" + map.get(key) + ",");
511 map.remove(key);
512 }
513 }
514 // Add the remaining key/value pairs to the buffer
515 for (Map.Entry<String, String> entry : map.entrySet()) {
516 sb.append(entry.getKey() + "=" + entry.getValue() + ",");
517 }
518 String orderedKeyPropertyListString = sb.toString();
519 orderedKeyPropertyListString = orderedKeyPropertyListString.substring(
520 0, orderedKeyPropertyListString.length() - 1);
521 return orderedKeyPropertyListString;
522 }
523
524 // Call on EDT
525 public void addMetadataNodes(DefaultMutableTreeNode node) {
526 XMBean mbean = (XMBean) ((XNodeInfo) node.getUserObject()).getData();
527 DefaultTreeModel model = (DefaultTreeModel) getModel();
528 MBeanInfoNodesSwingWorker sw =
529 new MBeanInfoNodesSwingWorker(model, node, mbean);
530 if (sw != null) {
531 sw.execute();
532 }
533 }
534
535 private static class MBeanInfoNodesSwingWorker
536 extends SwingWorker<Object[], Void> {
605 new Object[]{mbean, mbai}, mbai.getName(), null);
606 attribute.setUserObject(attributeUO);
607 attribute.setAllowsChildren(false);
608 attributes.add(attribute);
609 }
610 }
611 // MBeanOperationInfo node
612 //
613 if (oi != null && oi.length > 0) {
614 DefaultMutableTreeNode operations = new DefaultMutableTreeNode();
615 XNodeInfo operationsUO = new XNodeInfo(Type.OPERATIONS, mbean,
616 Messages.OPERATIONS, null);
617 operations.setUserObject(operationsUO);
618 node.insert(operations, childIndex++);
619 for (MBeanOperationInfo mboi : oi) {
620 // Compute the operation's tool tip text:
621 // "operationname(param1type,param2type,...)"
622 //
623 StringBuilder sb = new StringBuilder();
624 for (MBeanParameterInfo mbpi : mboi.getSignature()) {
625 sb.append(mbpi.getType() + ",");
626 }
627 String signature = sb.toString();
628 if (signature.length() > 0) {
629 // Remove the trailing ','
630 //
631 signature = signature.substring(0, signature.length() - 1);
632 }
633 String toolTipText = mboi.getName() + "(" + signature + ")";
634 // Create operation node
635 //
636 DefaultMutableTreeNode operation = new DefaultMutableTreeNode();
637 XNodeInfo operationUO = new XNodeInfo(Type.OPERATION,
638 new Object[]{mbean, mboi}, mboi.getName(), toolTipText);
639 operation.setUserObject(operationUO);
640 operation.setAllowsChildren(false);
641 operations.add(operation);
642 }
643 }
644 // MBeanNotificationInfo node
645 //
|
490 }
491
492 /**
493 * Returns the ordered key property list that will be used to build the
494 * MBean tree. If the "com.sun.tools.jconsole.mbeans.keyPropertyList" system
495 * property is not specified, then the ordered key property list used
496 * to build the MBean tree will be the one returned by the method
497 * ObjectName.getKeyPropertyListString() with "type" as first key,
498 * and "j2eeType" as second key, if present. If any of the keys specified
499 * in the comma-separated key property list does not apply to the given
500 * MBean then it will be discarded.
501 */
502 private static String getKeyPropertyListString(ObjectName mbean) {
503 String props = mbean.getKeyPropertyListString();
504 Map<String, String> map = extractKeyValuePairs(props, mbean);
505 StringBuilder sb = new StringBuilder();
506 // Add the key/value pairs to the buffer following the
507 // key order defined by the "orderedKeyPropertyList"
508 for (String key : orderedKeyPropertyList) {
509 if (map.containsKey(key)) {
510 sb.append(key).append('=').append(map.get(key)).append(',');
511 map.remove(key);
512 }
513 }
514 // Add the remaining key/value pairs to the buffer
515 for (Map.Entry<String, String> entry : map.entrySet()) {
516 sb.append(entry.getKey()).append('=').append(entry.getValue()).append(',');
517 }
518 String orderedKeyPropertyListString = sb.toString();
519 orderedKeyPropertyListString = orderedKeyPropertyListString.substring(
520 0, orderedKeyPropertyListString.length() - 1);
521 return orderedKeyPropertyListString;
522 }
523
524 // Call on EDT
525 public void addMetadataNodes(DefaultMutableTreeNode node) {
526 XMBean mbean = (XMBean) ((XNodeInfo) node.getUserObject()).getData();
527 DefaultTreeModel model = (DefaultTreeModel) getModel();
528 MBeanInfoNodesSwingWorker sw =
529 new MBeanInfoNodesSwingWorker(model, node, mbean);
530 if (sw != null) {
531 sw.execute();
532 }
533 }
534
535 private static class MBeanInfoNodesSwingWorker
536 extends SwingWorker<Object[], Void> {
605 new Object[]{mbean, mbai}, mbai.getName(), null);
606 attribute.setUserObject(attributeUO);
607 attribute.setAllowsChildren(false);
608 attributes.add(attribute);
609 }
610 }
611 // MBeanOperationInfo node
612 //
613 if (oi != null && oi.length > 0) {
614 DefaultMutableTreeNode operations = new DefaultMutableTreeNode();
615 XNodeInfo operationsUO = new XNodeInfo(Type.OPERATIONS, mbean,
616 Messages.OPERATIONS, null);
617 operations.setUserObject(operationsUO);
618 node.insert(operations, childIndex++);
619 for (MBeanOperationInfo mboi : oi) {
620 // Compute the operation's tool tip text:
621 // "operationname(param1type,param2type,...)"
622 //
623 StringBuilder sb = new StringBuilder();
624 for (MBeanParameterInfo mbpi : mboi.getSignature()) {
625 sb.append(mbpi.getType()).append(',');
626 }
627 String signature = sb.toString();
628 if (signature.length() > 0) {
629 // Remove the trailing ','
630 //
631 signature = signature.substring(0, signature.length() - 1);
632 }
633 String toolTipText = mboi.getName() + "(" + signature + ")";
634 // Create operation node
635 //
636 DefaultMutableTreeNode operation = new DefaultMutableTreeNode();
637 XNodeInfo operationUO = new XNodeInfo(Type.OPERATION,
638 new Object[]{mbean, mboi}, mboi.getName(), toolTipText);
639 operation.setUserObject(operationUO);
640 operation.setAllowsChildren(false);
641 operations.add(operation);
642 }
643 }
644 // MBeanNotificationInfo node
645 //
|