FileDocCategorySizeDatePackage
PerInterface.javaAPI DocJava SE 6 API8801Tue Jun 10 00:22:04 BST 2008com.sun.jmx.mbeanserver

PerInterface

public final class PerInterface extends Object
Per-MBean-interface behavior. A single instance of this class can be shared by all MBeans of the same kind (Standard MBean or MXBean) that have the same MBean interface.
since
1.6

Fields Summary
private final Class
mbeanInterface
private final MBeanIntrospector
introspector
private final MBeanInfo
mbeanInfo
private final Map
getters
private final Map
setters
private final Map
ops
Constructors Summary
PerInterface(Class mbeanInterface, MBeanIntrospector introspector, MBeanAnalyzer analyzer, MBeanInfo mbeanInfo)

	this.mbeanInterface = mbeanInterface;
	this.introspector = introspector;
        this.mbeanInfo = mbeanInfo;
	analyzer.visit(new InitMaps());
    
Methods Summary
java.lang.ObjectgetAttribute(java.lang.Object resource, java.lang.String attribute, java.lang.Object cookie)


	final M cm = getters.get(attribute);
	if (cm == null) {
	    final String msg;
	    if (setters.containsKey(attribute))
		msg = "Write-only attribute: " + attribute;
	    else
		msg = "No such attribute: " + attribute;
	    throw new AttributeNotFoundException(msg);
	}
	return introspector.invokeM(cm, resource, (Object[]) null, cookie);
    
javax.management.MBeanInfogetMBeanInfo()

	return mbeanInfo;
    
java.lang.ClassgetMBeanInterface()

	return mbeanInterface;
    
java.lang.Objectinvoke(java.lang.Object resource, java.lang.String operation, java.lang.Object[] params, java.lang.String[] signature, java.lang.Object cookie)


	final List<MethodAndSig> list = ops.get(operation);
	if (list == null) {
            final String msg = "No such operation: " + operation;
            return noSuchMethod(msg, resource, operation, params, signature,
                                cookie);
	}
	if (signature == null)
	    signature = new String[0];
	MethodAndSig found = null;
	for (MethodAndSig mas : list) {
	    if (Arrays.equals(mas.signature, signature)) {
		found = mas;
		break;
	    }
	}
	if (found == null) {
	    final String badSig = sigString(signature);
	    final String msg;
	    if (list.size() == 1) {  // helpful exception message
		msg = "Signature mismatch for operation " + operation +
			": " + badSig + " should be " +
			sigString(list.get(0).signature);
	    } else {
		msg = "Operation " + operation + " exists but not with " +
			"this signature: " + badSig;
	    }
	    return noSuchMethod(msg, resource, operation, params, signature,
                                cookie);
	}
	return introspector.invokeM(found.method, resource, params, cookie);
    
booleanisMXBean()

	return introspector.isMXBean();
    
private java.lang.ObjectnoSuchMethod(java.lang.String msg, java.lang.Object resource, java.lang.String operation, java.lang.Object[] params, java.lang.String[] signature, java.lang.Object cookie)


        // Construct the exception that we will probably throw
        final NoSuchMethodException nsme =
            new NoSuchMethodException(operation + sigString(signature));
        final ReflectionException exception =
            new ReflectionException(nsme, msg);

        if (introspector.isMXBean())
            throw exception; // No compatibility requirement here

        // Is the compatibility property set?
        GetPropertyAction act = new GetPropertyAction("jmx.invoke.getters");
        String invokeGettersS;
        try {
            invokeGettersS = AccessController.doPrivileged(act);
        } catch (Exception e) {
            // We don't expect an exception here but if we get one then
            // we'll simply assume that the property is not set.
            invokeGettersS = null;
        }
        if (invokeGettersS == null)
            throw exception;

	int rest = 0;
        Map<String, M> methods = null;
	if (signature == null || signature.length == 0) {
	    if (operation.startsWith("get"))
		rest = 3;
	    else if (operation.startsWith("is"))
		rest = 2;
            if (rest != 0)
                methods = getters;
	} else if (signature != null && signature.length == 1 &&
		   operation.startsWith("set")) {
	    rest = 3;
            methods = setters;
        }

	if (rest != 0) {
	    String attrName = operation.substring(rest);
	    M method = methods.get(attrName);
            if (method != null && introspector.getName(method).equals(operation)) {
                String[] msig = introspector.getSignature(method);
                if ((signature == null && msig.length == 0) ||
                        Arrays.equals(signature, msig)) {
                    return introspector.invokeM(method, resource, params, cookie);
                }
            }
	}

        throw exception;
    
voidsetAttribute(java.lang.Object resource, java.lang.String attribute, java.lang.Object value, java.lang.Object cookie)


	final M cm = setters.get(attribute);
	if (cm == null) {
	    final String msg;
	    if (getters.containsKey(attribute))
		msg = "Read-only attribute: " + attribute;
	    else
		msg = "No such attribute: " + attribute;
	    throw new AttributeNotFoundException(msg);
	}
        introspector.invokeSetter(attribute, cm, resource, value, cookie);
    
private java.lang.StringsigString(java.lang.String[] signature)

	StringBuilder b = new StringBuilder("(");
        if (signature != null) {
            for (String s : signature) {
                if (b.length() > 1)
                    b.append(", ");
                b.append(s);
            }
        }
	return b.append(")").toString();