示例#1
0
  public MBeanInfo getMBeanInfo() {
    try {
      if (_info == null) {
        // Start with blank lazy lists attributes etc.
        String desc = null;
        Object attributes = null;
        Object constructors = null;
        Object operations = null;
        Object notifications = null;

        // Find list of classes that can influence the mbean
        Class o_class = _managed.getClass();
        Object influences = findInfluences(null, _managed.getClass());

        // Set to record defined items
        Set defined = new HashSet();

        // For each influence
        for (int i = 0; i < LazyList.size(influences); i++) {
          Class oClass = (Class) LazyList.get(influences, i);

          // look for a bundle defining methods
          if (Object.class.equals(oClass)) oClass = ObjectMBean.class;
          String pName = oClass.getPackage().getName();
          String cName = oClass.getName().substring(pName.length() + 1);
          String rName = pName.replace('.', '/') + "/jmx/" + cName + "-mbean";

          try {
            LOG.debug(rName);
            ResourceBundle bundle =
                Loader.getResourceBundle(o_class, rName, true, Locale.getDefault());

            // Extract meta data from bundle
            Enumeration e = bundle.getKeys();
            while (e.hasMoreElements()) {
              String key = (String) e.nextElement();
              String value = bundle.getString(key);

              // Determin if key is for mbean , attribute or for operation
              if (key.equals(cName)) {
                // set the mbean description
                if (desc == null) desc = value;
              } else if (key.indexOf('(') > 0) {
                // define an operation
                if (!defined.contains(key) && key.indexOf('[') < 0) {
                  defined.add(key);
                  operations = LazyList.add(operations, defineOperation(key, value, bundle));
                }
              } else {
                // define an attribute
                if (!defined.contains(key)) {
                  defined.add(key);
                  MBeanAttributeInfo info = defineAttribute(key, value);
                  if (info != null) attributes = LazyList.add(attributes, info);
                }
              }
            }
          } catch (MissingResourceException e) {
            LOG.ignore(e);
          }
        }

        _info =
            new MBeanInfo(
                o_class.getName(),
                desc,
                (MBeanAttributeInfo[]) LazyList.toArray(attributes, MBeanAttributeInfo.class),
                (MBeanConstructorInfo[]) LazyList.toArray(constructors, MBeanConstructorInfo.class),
                (MBeanOperationInfo[]) LazyList.toArray(operations, MBeanOperationInfo.class),
                (MBeanNotificationInfo[])
                    LazyList.toArray(notifications, MBeanNotificationInfo.class));
      }
    } catch (RuntimeException e) {
      LOG.warn(e);
      throw e;
    }
    return _info;
  }