Java MBean getOperation(MBeanInfo info, String opName)

Here you can find the source of getOperation(MBeanInfo info, String opName)

Description

Returns the first operation with the specified name.

License

LGPL

Declaration

public static MBeanOperationInfo getOperation(MBeanInfo info,
        String opName) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import javax.management.MBeanInfo;

import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;

public class Main {
    /**/*from   w  w  w  .  j ava2  s . c  o  m*/
     * Returns the first operation with the specified name.
     */
    public static MBeanOperationInfo getOperation(MBeanInfo info,
            String opName) {
        MBeanOperationInfo[] ops = info.getOperations();
        for (int i = 0; i < ops.length; i++) {
            if (ops[i].getName().equals(opName))
                return ops[i];
        }
        return null;
    }

    /**
     * Returns the first operation that takes the specified number of parameters.
     */
    public static MBeanOperationInfo getOperation(MBeanInfo info,
            String opName, int paramCount) {
        MBeanOperationInfo[] ops = info.getOperations();
        for (int i = 0; i < ops.length; i++) {
            if (ops[i].getName().equals(opName)
                    && ops[i].getSignature().length == paramCount)
                return ops[i];
        }
        return null;
    }

    /**
     * Returns the operation with the specified name and signature.
     * @param signature can be null.
     */
    public static MBeanOperationInfo getOperation(MBeanInfo info,
            String opName, String[] signature) {
        if (signature == null)
            signature = new String[0];

        MBeanOperationInfo[] ops = info.getOperations();
        for (int i = 0; i < ops.length; i++) {
            MBeanOperationInfo op = ops[i];
            if (op.getName().equals(opName)) {
                MBeanParameterInfo[] params = op.getSignature();
                if (params.length == signature.length) {
                    boolean found = true;
                    for (int j = 0; found && j < params.length; j++) {
                        if (!params[j].getType().equals(signature[j]))
                            found = false;
                    }
                    if (found)
                        return op;
                }
            }
        }
        return null;
    }

    /**
     * Returns the operation with the specified name, signature and return type.
     * @param signature can be null.
     */
    public static MBeanOperationInfo getOperation(MBeanInfo info,
            String opName, String[] signature, String returnType) {
        if (signature == null)
            signature = new String[0];

        MBeanOperationInfo[] ops = info.getOperations();
        for (int i = 0; i < ops.length; i++) {
            MBeanOperationInfo op = ops[i];
            if (op.getName().equals(opName)
                    && op.getReturnType().equals(returnType)) {
                MBeanParameterInfo[] params = op.getSignature();
                if (params.length == signature.length) {
                    boolean found = true;
                    for (int j = 0; found && j < params.length; j++) {
                        if (!params[j].getType().equals(signature[j]))
                            found = false;
                    }
                    if (found)
                        return op;
                }
            }
        }
        return null;
    }
}

Related

  1. getMbeanServerConnection(final JMXConnector jmxConnector)
  2. getMBeanServerConnectionForJMXClient()
  3. getMBeanServerDelegateName()
  4. getMBeanServerId(final MBeanServer aMBeanServer)
  5. getMBeanServerObjectName()
  6. getProxy(MBeanServerConnection connection, ObjectName objectName, final Class objectClass)
  7. getServerId(MBeanServer server)
  8. infoArrayEquals(MBeanParameterInfo[] a, MBeanParameterInfo[] a2)
  9. infoEquals(MBeanInfo one, MBeanInfo two)