Esempio n. 1
0
  public static OperationParams getAttributeParams(MBeanInfo info, String method, Object args[])
      throws PluginException {

    if (method.startsWith("set") || method.startsWith("get")) {
      method = method.substring(3);
    }

    MBeanAttributeInfo[] attrs = info.getAttributes();
    for (int i = 0; i < attrs.length; i++) {
      MBeanAttributeInfo attr = attrs[i];
      if (!attr.getName().equals(method)) {
        continue;
      }

      String sig = attr.getType();
      if (!hasConverter(sig)) {
        String msg = "Cannot convert String argument to " + sig;
        throw new PluginException(msg);
      }

      OperationParams params = new OperationParams();
      Object value = null;
      try {
        if (args.length > 0) {
          value = convert(sig, (String) args[0]);
        }
      } catch (Exception e) {
        String msg = "Exception converting param '" + args[0] + "' to type '" + sig + "'";
        throw new PluginException(msg + ": " + e);
      }
      if (value != null) {
        params.arguments = new Object[] {value};
      }
      params.isAttribute = true;
      return params;
    }

    return null;
  }