FileDocCategorySizeDatePackage
ConvertingMethod.javaAPI DocJava SE 6 API6879Tue Jun 10 00:22:02 BST 2008com.sun.jmx.mbeanserver

ConvertingMethod

public final class ConvertingMethod extends Object
author
Eamonn McManus

Fields Summary
private static final OpenType[]
noOpenTypes
private static final String[]
noStrings
private final Method
method
private final OpenConverter
returnConverter
private final OpenConverter[]
paramConverters
private final boolean
paramConversionIsIdentity
Constructors Summary
private ConvertingMethod(Method m)

	this.method = m;
	returnConverter = OpenConverter.toConverter(m.getGenericReturnType());
	Type[] params = m.getGenericParameterTypes();
	paramConverters = new OpenConverter[params.length];
	boolean identity = true;
	for (int i = 0; i < params.length; i++) {
	    paramConverters[i] = OpenConverter.toConverter(params[i]);
	    identity &= paramConverters[i].isIdentity();
	}
	paramConversionIsIdentity = identity;
    
Methods Summary
voidcheckCallFromOpen()

        try {
            for (OpenConverter paramConverter : paramConverters)
                paramConverter.checkReconstructible();
        } catch (InvalidObjectException e) {
            throw new IllegalArgumentException(e);
        }
    
voidcheckCallToOpen()

        try {
            returnConverter.checkReconstructible();
        } catch (InvalidObjectException e) {
            throw new IllegalArgumentException(e);
        }
    
static com.sun.jmx.mbeanserver.ConvertingMethodfrom(java.lang.reflect.Method m)

	try {
	    return new ConvertingMethod(m);
	} catch (OpenDataException ode) {
	    final String msg = "Method " + m.getDeclaringClass().getName() +
		"." + m.getName() + " has parameter or return type that " +
		"cannot be translated into an open type";
	    throw new IllegalArgumentException(msg, ode);
	}
    
final java.lang.ObjectfromOpenParameter(com.sun.jmx.mbeanserver.MXBeanLookup lookup, java.lang.Object param, int paramNo)

        return paramConverters[paramNo].fromOpenValue(lookup, param);
    
final java.lang.Object[]fromOpenParameters(com.sun.jmx.mbeanserver.MXBeanLookup lookup, java.lang.Object[] params)

	if (paramConversionIsIdentity || params == null)
	    return params;
	final Object[] jparams = new Object[params.length];
	for (int i = 0; i < params.length; i++)
	    jparams[i] = paramConverters[i].fromOpenValue(lookup, params[i]);
	return jparams;
    
final java.lang.ObjectfromOpenReturnValue(com.sun.jmx.mbeanserver.MXBeanLookup lookup, java.lang.Object ret)

	return returnConverter.fromOpenValue(lookup, ret);
    
javax.management.DescriptorgetDescriptor()

        return Introspector.descriptorForElement(method);
    
java.lang.reflect.Type[]getGenericParameterTypes()

        return method.getGenericParameterTypes();
    
java.lang.reflect.TypegetGenericReturnType()

        return method.getGenericReturnType();
    
java.lang.reflect.MethodgetMethod()

	return method;
    
java.lang.StringgetName()

	return method.getName();
    
javax.management.openmbean.OpenType[]getOpenParameterTypes()

	final OpenType[] types = new OpenType[paramConverters.length];
	for (int i = 0; i < paramConverters.length; i++)
	    types[i] = paramConverters[i].getOpenType();
	return types;
    
javax.management.openmbean.OpenTypegetOpenReturnType()

	return returnConverter.getOpenType();
    
java.lang.String[]getOpenSignature()

	if (paramConverters.length == 0)
	    return noStrings;

	String[] sig = new String[paramConverters.length];
	for (int i = 0; i < paramConverters.length; i++)
	    sig[i] = paramConverters[i].getOpenClass().getName();
	return sig;
    
java.lang.ObjectinvokeWithOpenReturn(com.sun.jmx.mbeanserver.MXBeanLookup lookup, java.lang.Object obj, java.lang.Object[] params)

	final Object[] javaParams;
	try {
	    javaParams = fromOpenParameters(lookup, params);
	} catch (InvalidObjectException e) {
	    // probably can't happen
	    final String msg = methodName() + ": cannot convert parameters " +
		"from open values: " + e;
	    throw new MBeanException(e, msg);
	}
	final Object javaReturn = method.invoke(obj, javaParams);
	try {
	    return returnConverter.toOpenValue(lookup, javaReturn);
	} catch (OpenDataException e) {
	    // probably can't happen
	    final String msg = methodName() + ": cannot convert return " +
		"value to open value: " + e;
	    throw new MBeanException(e, msg);
	}
    
private java.lang.StringmethodName()

	return method.getDeclaringClass() + "." + method.getName();
    
final java.lang.ObjecttoOpenParameter(com.sun.jmx.mbeanserver.MXBeanLookup lookup, java.lang.Object param, int paramNo)

        return paramConverters[paramNo].toOpenValue(lookup, param);
    
final java.lang.Object[]toOpenParameters(com.sun.jmx.mbeanserver.MXBeanLookup lookup, java.lang.Object[] params)

	if (paramConversionIsIdentity || params == null)
	    return params;
	final Object[] oparams = new Object[params.length];
	for (int i = 0; i < params.length; i++)
	    oparams[i] = paramConverters[i].toOpenValue(lookup, params[i]);
	return oparams;
    
final java.lang.ObjecttoOpenReturnValue(com.sun.jmx.mbeanserver.MXBeanLookup lookup, java.lang.Object ret)

	return returnConverter.toOpenValue(lookup, ret);