jdk/src/share/classes/com/sun/jmx/mbeanserver/MBeanInstantiator.java
author emcmanus
Wed, 21 Oct 2009 17:33:18 +0200
changeset 4156 acaa49a2768a
parent 1705 08644ea24ce6
child 5506 202f599c92aa
permissions -rw-r--r--
6851617: Remove JSR 255 (JMX API 2.0) from JDK 7 Summary: See http://weblogs.java.net/blog/2009/06/16/jsr-255-jmx-api-20-postponed Reviewed-by: dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 526
diff changeset
     2
 * Copyright 2000-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.ByteArrayInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.lang.reflect.Constructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.logging.Level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.management.InstanceNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.management.MBeanException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.management.NotCompliantMBeanException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.management.OperationsException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.ReflectionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.RuntimeErrorException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.management.RuntimeMBeanException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.management.RuntimeOperationsException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.reflect.misc.ReflectUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Implements the MBeanInstantiator interface. Provides methods for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * instantiating objects, finding the class given its name and using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * different class loaders, deserializing objects in the context of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * given class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public class MBeanInstantiator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private final ModifiableClassLoaderRepository clr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    //    private MetaData meta = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    MBeanInstantiator(ModifiableClassLoaderRepository clr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        this.clr = clr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * This methods tests if the MBean class makes it possible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * instantiate an MBean of this class in the MBeanServer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * e.g. it must have a public constructor, be a concrete class...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
    73
    public void testCreation(Class<?> c) throws NotCompliantMBeanException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        Introspector.testCreation(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Loads the class with the specified name using this object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Default Loader Repository.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     **/
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
    81
    public Class<?> findClassWithDefaultLoaderRepository(String className)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        throws ReflectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
    84
        Class<?> theClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (className == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            throw new RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                IllegalArgumentException("The class name cannot be null"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                             "Exception occurred during object instantiation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            if (clr == null) throw new ClassNotFoundException(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            theClass = clr.loadClass(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        catch (ClassNotFoundException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            throw new ReflectionException(ee,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
       "The MBean class could not be loaded by the default loader repository");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        return theClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Gets the class for the specified class name using the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Interceptor's classloader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   108
    public Class<?> findClass(String className, ClassLoader loader)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        throws ReflectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return loadClass(className,loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Gets the class for the specified class name using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   118
    public Class<?> findClass(String className, ObjectName aLoader)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        throws ReflectionException, InstanceNotFoundException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (aLoader == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            throw new RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                IllegalArgumentException(), "Null loader passed in parameter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        // Retrieve the class loader from the repository
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        ClassLoader loader = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            if (clr!=null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                loader = clr.getClassLoader(aLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        if (loader == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            throw new InstanceNotFoundException("The loader named " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                       aLoader + " is not registered in the MBeanServer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return findClass(className,loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Return an array of Class corresponding to the given signature, using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * the specified class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   143
    public Class<?>[] findSignatureClasses(String signature[],
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   144
                                           ClassLoader loader)
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   145
        throws ReflectionException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (signature == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        final ClassLoader aLoader = loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        final int length= signature.length;
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   150
        final Class<?> tab[]=new Class<?>[length];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (length == 0) return tab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            for (int i= 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                // Start handling primitive types (int. boolean and so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                // forth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   159
                final Class<?> primCla = primitiveClasses.get(signature[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                if (primCla != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    tab[i] = primCla;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                // Ok we do not have a primitive type ! We need to build
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                // the signature of the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                if (aLoader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    // We need to load the class through the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    // loader of the target object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    tab[i] = Class.forName(signature[i], false, aLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    // Load through the default class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    tab[i] = findClass(signature[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                       this.getClass().getClassLoader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                MBEANSERVER_LOGGER.logp(Level.FINEST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                        MBeanInstantiator.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                        "findSignatureClasses",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                        "The parameter class could not be found", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            throw new ReflectionException(e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                      "The parameter class could not be found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        } catch (RuntimeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                MBEANSERVER_LOGGER.logp(Level.FINEST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        MBeanInstantiator.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                        "findSignatureClasses",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                        "Unexpected exception", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return tab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Instantiates an object given its class, using its empty constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * The call returns a reference to the newly created object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   206
    public Object instantiate(Class<?> theClass)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        throws ReflectionException, MBeanException {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   208
        Object moi;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        // ------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        // ------------------------------
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   213
        Constructor<?> cons = findConstructor(theClass, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (cons == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            throw new ReflectionException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                NoSuchMethodException("No such constructor"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        // Instantiate the new object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            ReflectUtil.checkPackageAccess(theClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            moi= cons.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        } catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            // Wrap the exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            Throwable t = e.getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            if (t instanceof RuntimeException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                throw new RuntimeMBeanException((RuntimeException)t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                   "RuntimeException thrown in the MBean's empty constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            } else if (t instanceof Error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                throw new RuntimeErrorException((Error) t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                   "Error thrown in the MBean's empty constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                throw new MBeanException((Exception) t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                   "Exception thrown in the MBean's empty constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        } catch (NoSuchMethodError error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            throw new ReflectionException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                NoSuchMethodException("No constructor"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                          "No such constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        } catch (InstantiationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            throw new ReflectionException(e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            "Exception thrown trying to invoke the MBean's empty constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        } catch (IllegalAccessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            throw new ReflectionException(e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            "Exception thrown trying to invoke the MBean's empty constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            throw new ReflectionException(e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            "Exception thrown trying to invoke the MBean's empty constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return moi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Instantiates an object given its class, the parameters and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * signature of its constructor The call returns a reference to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * the newly created object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   260
    public Object instantiate(Class<?> theClass, Object params[],
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                              String signature[], ClassLoader loader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        throws ReflectionException, MBeanException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        // Instantiate the new object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        // ------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        // ------------------------------
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   267
        final Class<?>[] tab;
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   268
        Object moi;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            // Build the signature of the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            ClassLoader aLoader= theClass.getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            // Build the signature of the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            tab =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                ((signature == null)?null:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                 findSignatureClasses(signature,aLoader));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        // Exception IllegalArgumentException raised in Jdk1.1.8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            throw new ReflectionException(e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    "The constructor parameter classes could not be loaded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        // Query the metadata service to get the right constructor
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   286
        Constructor<?> cons = findConstructor(theClass, tab);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if (cons == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            throw new ReflectionException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                NoSuchMethodException("No such constructor"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            ReflectUtil.checkPackageAccess(theClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            moi = cons.newInstance(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        catch (NoSuchMethodError error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            throw new ReflectionException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                NoSuchMethodException("No such constructor found"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                          "No such constructor" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        catch (InstantiationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            throw new ReflectionException(e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                "Exception thrown trying to invoke the MBean's constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        catch (IllegalAccessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            throw new ReflectionException(e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                "Exception thrown trying to invoke the MBean's constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            // Wrap the exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            Throwable th = e.getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            if (th instanceof RuntimeException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                throw new RuntimeMBeanException((RuntimeException)th,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                      "RuntimeException thrown in the MBean's constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            } else if (th instanceof Error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                throw new RuntimeErrorException((Error) th,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                      "Error thrown in the MBean's constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                throw new MBeanException((Exception) th,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                      "Exception thrown in the MBean's constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        return moi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * De-serializes a byte array in the context of a classloader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @param loader the classloader to use for de-serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @param data The byte array to be de-sererialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @return  The de-serialized object stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @exception OperationsException Any of the usual Input/Output related
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public ObjectInputStream deserialize(ClassLoader loader, byte[] data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        throws OperationsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        // Check parameter validity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        if (data == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            throw new  RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                IllegalArgumentException(), "Null data passed in parameter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (data.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            throw new  RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                IllegalArgumentException(), "Empty data passed in parameter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        // Object deserialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        ByteArrayInputStream bIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        ObjectInputStream    objIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        bIn   = new ByteArrayInputStream(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            objIn = new ObjectInputStreamWithLoader(bIn,loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            throw new OperationsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                     "An IOException occurred trying to de-serialize the data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        return objIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * De-serializes a byte array in the context of a given MBean class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * <P>The class loader is the one that loaded the class with name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * "className".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * <P>The name of the class loader to be used for loading the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * class is specified. If null, a default one has to be provided (for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * MBean Server, its own class loader will be used).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @param className The name of the class whose class loader should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *  be used for the de-serialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @param data The byte array to be de-sererialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @param loaderName The name of the class loader to be used for loading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * the specified class. If null, a default one has to be provided (for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * MBean Server, its own class loader will be used).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @return  The de-serialized object stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @exception InstanceNotFoundException The specified class loader MBean is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @exception OperationsException Any of the usual Input/Output related
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @exception ReflectionException The specified class could not be loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * by the specified class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public ObjectInputStream deserialize(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                                         ObjectName loaderName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                                         byte[] data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                                         ClassLoader loader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        throws InstanceNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
               OperationsException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
               ReflectionException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        // Check parameter validity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (data == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            throw new  RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                IllegalArgumentException(), "Null data passed in parameter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        if (data.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            throw new  RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                IllegalArgumentException(), "Empty data passed in parameter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        if (className == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            throw new  RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
             IllegalArgumentException(), "Null className passed in parameter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   410
        Class<?> theClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        if (loaderName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            // Load the class using the agent class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            theClass = findClass(className, loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            // Get the class loader MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                ClassLoader instance = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                if (clr!=null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    instance = clr.getClassLoader(loaderName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                if (instance == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    throw new ClassNotFoundException(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                theClass = Class.forName(className, false, instance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                throw new ReflectionException(e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                               "The MBean class could not be loaded by the " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                               loaderName.toString() + " class loader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        // Object deserialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        ByteArrayInputStream bIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        ObjectInputStream    objIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        bIn   = new ByteArrayInputStream(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            objIn = new ObjectInputStreamWithLoader(bIn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                                           theClass.getClassLoader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            throw new OperationsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    "An IOException occurred trying to de-serialize the data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        return objIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * Instantiates an object using the list of all class loaders registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * in the MBean Interceptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * (using its {@link javax.management.loading.ClassLoaderRepository}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * <P>The object's class should have a public constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * <P>It returns a reference to the newly created object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * <P>The newly created object is not registered in the MBean Interceptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @param className The class name of the object to be instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @return The newly instantiated object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @exception ReflectionException Wraps a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * <CODE>java.lang.ClassNotFoundException</CODE> or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * object's constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @exception MBeanException The constructor of the object has thrown an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @exception RuntimeOperationsException Wraps a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * <CODE>java.lang.IllegalArgumentException</CODE>: the className passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    public Object instantiate(String className)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        throws ReflectionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        MBeanException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        return instantiate(className, (Object[]) null, (String[]) null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * Instantiates an object using the class Loader specified by its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * <CODE>ObjectName</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * <P>If the loader name is null, a default one has to be provided (for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * MBean Server, the ClassLoader that loaded it will be used).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * <P>The object's class should have a public constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * <P>It returns a reference to the newly created object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * <P>The newly created object is not registered in the MBean Interceptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @param className The class name of the MBean to be instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @param loaderName The object name of the class loader to be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @return The newly instantiated object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @exception ReflectionException Wraps a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * <CODE>java.lang.ClassNotFoundException</CODE> or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * object's constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * @exception MBeanException The constructor of the object has thrown an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @exception InstanceNotFoundException The specified class loader is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * registered in the MBeanServerInterceptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @exception RuntimeOperationsException Wraps a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * <CODE>java.lang.IllegalArgumentException</CODE>: the className passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    public Object instantiate(String className, ObjectName loaderName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                              ClassLoader loader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        throws ReflectionException, MBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
               InstanceNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        return instantiate(className, loaderName, (Object[]) null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                           (String[]) null, loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * Instantiates an object using the list of all class loaders registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * in the MBean server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * (using its {@link javax.management.loading.ClassLoaderRepository}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * <P>The object's class should have a public constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * <P>The call returns a reference to the newly created object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * <P>The newly created object is not registered in the MBean Interceptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * @param className The class name of the object to be instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @param params An array containing the parameters of the constructor to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * be invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @param signature An array containing the signature of the constructor to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * be invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @return The newly instantiated object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * @exception ReflectionException Wraps a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * <CODE>java.lang.ClassNotFoundException</CODE> or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * object's constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @exception MBeanException The constructor of the object has thrown an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @exception RuntimeOperationsException Wraps a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * <CODE>java.lang.IllegalArgumentException</CODE>: the className passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    public Object instantiate(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                              Object params[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                              String signature[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                              ClassLoader loader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        throws ReflectionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        MBeanException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   550
        Class<?> theClass = findClassWithDefaultLoaderRepository(className);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        return instantiate(theClass, params, signature, loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * Instantiates an object. The class loader to be used is identified by its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * object name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * <P>If the object name of the loader is null, a default has to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * provided (for example, for a MBean Server, the ClassLoader that loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * it will be used).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * <P>The object's class should have a public constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * <P>The call returns a reference to the newly created object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * <P>The newly created object is not registered in the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @param className The class name of the object to be instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @param params An array containing the parameters of the constructor to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * be invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @param signature An array containing the signature of the constructor to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * be invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @param loaderName The object name of the class loader to be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @return The newly instantiated object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * @exception ReflectionException Wraps a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * <CODE>java.lang.ClassNotFoundException</CODE> or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * object's constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @exception MBeanException The constructor of the object has thrown an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * @exception InstanceNotFoundException The specified class loader is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * registered in the MBean Interceptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @exception RuntimeOperationsException Wraps a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * <CODE>java.lang.IllegalArgumentException</CODE>: the className passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    public Object instantiate(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                              ObjectName loaderName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                              Object params[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                              String signature[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                              ClassLoader loader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        throws ReflectionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
               MBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        InstanceNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        // ------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        // ------------------------------
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   598
        Class<?> theClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        if (loaderName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            theClass = findClass(className, loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            theClass = findClass(className, loaderName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        return instantiate(theClass, params, signature, loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * Return the Default Loader Repository used by this instantiator object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    public ModifiableClassLoaderRepository getClassLoaderRepository() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        return clr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * Load a class with the specified loader, or with this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * class loader if the specified loader is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     **/
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   620
    static Class<?> loadClass(String className, ClassLoader loader)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        throws ReflectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   623
        Class<?> theClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        if (className == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            throw new RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                IllegalArgumentException("The class name cannot be null"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                              "Exception occurred during object instantiation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            if (loader == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                loader = MBeanInstantiator.class.getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            if (loader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                theClass = Class.forName(className, false, loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                theClass = Class.forName(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            throw new ReflectionException(e,
1705
08644ea24ce6 6780803: Wrong parameter name in description of EventClient::addListeners()
emcmanus
parents: 1702
diff changeset
   639
            "The MBean class could not be loaded");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        return theClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * Load the classes specified in the signature with the given loader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * or with this object class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     **/
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   650
    static Class<?>[] loadSignatureClasses(String signature[],
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   651
                                           ClassLoader loader)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        throws  ReflectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        if (signature == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        final ClassLoader aLoader =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
           (loader==null?MBeanInstantiator.class.getClassLoader():loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        final int length= signature.length;
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   658
        final Class<?> tab[]=new Class<?>[length];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        if (length == 0) return tab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            for (int i= 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                // Start handling primitive types (int. boolean and so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                // forth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   667
                final Class<?> primCla = primitiveClasses.get(signature[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                if (primCla != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                    tab[i] = primCla;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                // Ok we do not have a primitive type ! We need to build
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                // the signature of the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                // We need to load the class through the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                // loader of the target object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                tab[i] = Class.forName(signature[i], false, aLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                MBEANSERVER_LOGGER.logp(Level.FINEST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                        MBeanInstantiator.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                        "findSignatureClasses",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                        "The parameter class could not be found", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            throw new ReflectionException(e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                      "The parameter class could not be found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        } catch (RuntimeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                MBEANSERVER_LOGGER.logp(Level.FINEST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                        MBeanInstantiator.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                        "findSignatureClasses",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                        "Unexpected exception", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        return tab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    private Constructor<?> findConstructor(Class<?> c, Class<?>[] params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            return c.getConstructor(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    private static final Map<String, Class<?>> primitiveClasses = Util.newMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    static {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   713
        for (Class<?> c : new Class<?>[] {byte.class, short.class, int.class,
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   714
                                          long.class, float.class, double.class,
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   715
                                          char.class, boolean.class})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            primitiveClasses.put(c.getName(), c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
}