jdk/src/share/classes/com/sun/jmx/mbeanserver/ConvertingMethod.java
author sjiang
Tue, 02 Apr 2013 10:38:51 +0200
changeset 18220 1d724730bd2c
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
8007467: Better JMX type conversion Reviewed-by: dfuchs, mchung, skoivu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     2
 * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.jmx.mbeanserver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.InvalidObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.lang.reflect.Type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.management.Descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.management.MBeanException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.management.openmbean.OpenDataException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.management.openmbean.OpenType;
18220
1d724730bd2c 8007467: Better JMX type conversion
sjiang
parents: 5506
diff changeset
    36
import sun.reflect.misc.MethodUtil;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
final class ConvertingMethod {
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1699
diff changeset
    39
    static ConvertingMethod from(Method m) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        try {
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1699
diff changeset
    41
            return new ConvertingMethod(m);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        } catch (OpenDataException ode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
            final String msg = "Method " + m.getDeclaringClass().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
                "." + m.getName() + " has parameter or return type that " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
                "cannot be translated into an open type";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
            throw new IllegalArgumentException(msg, ode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    Method getMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        return method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    Descriptor getDescriptor() {
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1699
diff changeset
    55
        return Introspector.descriptorForElement(method);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    Type getGenericReturnType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        return method.getGenericReturnType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    Type[] getGenericParameterTypes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        return method.getGenericParameterTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        return method.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
    70
    OpenType<?> getOpenReturnType() {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
    71
        return returnMapping.getOpenType();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
    74
    OpenType<?>[] getOpenParameterTypes() {
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
    75
        final OpenType<?>[] types = new OpenType<?>[paramMappings.length];
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
    76
        for (int i = 0; i < paramMappings.length; i++)
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
    77
            types[i] = paramMappings[i].getOpenType();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return types;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /* Check that this method will be callable when we are going from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * open types to Java types, for example when we are going from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * an MXBean wrapper to the underlying resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * The parameters will be converted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Java types, so they must be "reconstructible".  The return
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * value will be converted to an Open Type, so if it is convertible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * at all there is no further check needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
    89
    void checkCallFromOpen() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        try {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
    91
            for (MXBeanMapping paramConverter : paramMappings)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                paramConverter.checkReconstructible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        } catch (InvalidObjectException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            throw new IllegalArgumentException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /* Check that this method will be callable when we are going from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * Java types to open types, for example when we are going from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * an MXBean proxy to the open types that it will be mapped to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * The return type will be converted back to a Java type, so it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * must be "reconstructible".  The parameters will be converted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * open types, so if it is convertible at all there is no further
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * check needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   106
    void checkCallToOpen() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        try {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   108
            returnMapping.checkReconstructible();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        } catch (InvalidObjectException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            throw new IllegalArgumentException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    String[] getOpenSignature() {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   115
        if (paramMappings.length == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            return noStrings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   118
        String[] sig = new String[paramMappings.length];
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   119
        for (int i = 0; i < paramMappings.length; i++)
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   120
            sig[i] = paramMappings[i].getOpenClass().getName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return sig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    final Object toOpenReturnValue(MXBeanLookup lookup, Object ret)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            throws OpenDataException {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   126
        return returnMapping.toOpenValue(ret);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    final Object fromOpenReturnValue(MXBeanLookup lookup, Object ret)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            throws InvalidObjectException {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   131
        return returnMapping.fromOpenValue(ret);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    final Object[] toOpenParameters(MXBeanLookup lookup, Object[] params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            throws OpenDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (paramConversionIsIdentity || params == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            return params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        final Object[] oparams = new Object[params.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        for (int i = 0; i < params.length; i++)
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   140
            oparams[i] = paramMappings[i].toOpenValue(params[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        return oparams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   144
    final Object[] fromOpenParameters(Object[] params)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            throws InvalidObjectException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (paramConversionIsIdentity || params == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            return params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        final Object[] jparams = new Object[params.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        for (int i = 0; i < params.length; i++)
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   150
            jparams[i] = paramMappings[i].fromOpenValue(params[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        return jparams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    final Object toOpenParameter(MXBeanLookup lookup,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                                 Object param,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                 int paramNo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        throws OpenDataException {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   158
        return paramMappings[paramNo].toOpenValue(param);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    final Object fromOpenParameter(MXBeanLookup lookup,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                   Object param,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                                   int paramNo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        throws InvalidObjectException {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   165
        return paramMappings[paramNo].fromOpenValue(param);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    Object invokeWithOpenReturn(MXBeanLookup lookup,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                Object obj, Object[] params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            throws MBeanException, IllegalAccessException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                   InvocationTargetException {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   172
        MXBeanLookup old = MXBeanLookup.getLookup();
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   173
        try {
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   174
            MXBeanLookup.setLookup(lookup);
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   175
            return invokeWithOpenReturn(obj, params);
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   176
        } finally {
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   177
            MXBeanLookup.setLookup(old);
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   178
        }
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   179
    }
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   180
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   181
    private Object invokeWithOpenReturn(Object obj, Object[] params)
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   182
            throws MBeanException, IllegalAccessException,
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   183
                   InvocationTargetException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        final Object[] javaParams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        try {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   186
            javaParams = fromOpenParameters(params);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        } catch (InvalidObjectException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            // probably can't happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            final String msg = methodName() + ": cannot convert parameters " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                "from open values: " + e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            throw new MBeanException(e, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
18220
1d724730bd2c 8007467: Better JMX type conversion
sjiang
parents: 5506
diff changeset
   193
        final Object javaReturn = MethodUtil.invoke(method, obj, javaParams);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        try {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   195
            return returnMapping.toOpenValue(javaReturn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            // probably can't happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            final String msg = methodName() + ": cannot convert return " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                "value to open value: " + e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            throw new MBeanException(e, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    private String methodName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return method.getDeclaringClass() + "." + method.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1699
diff changeset
   208
    private ConvertingMethod(Method m) throws OpenDataException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        this.method = m;
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1699
diff changeset
   210
        MXBeanMappingFactory mappingFactory = MXBeanMappingFactory.DEFAULT;
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   211
        returnMapping =
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   212
                mappingFactory.mappingForType(m.getGenericReturnType(), mappingFactory);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        Type[] params = m.getGenericParameterTypes();
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   214
        paramMappings = new MXBeanMapping[params.length];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        boolean identity = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        for (int i = 0; i < params.length; i++) {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   217
            paramMappings[i] = mappingFactory.mappingForType(params[i], mappingFactory);
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   218
            identity &= DefaultMXBeanMappingFactory.isIdentity(paramMappings[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        paramConversionIsIdentity = identity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    private static final String[] noStrings = new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    private final Method method;
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   226
    private final MXBeanMapping returnMapping;
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   227
    private final MXBeanMapping[] paramMappings;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    private final boolean paramConversionIsIdentity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
}