jdk/src/java.management/share/classes/javax/management/loading/MLet.java
author jbachorik
Thu, 11 Sep 2014 12:54:02 +0200
changeset 26484 871db348e647
parent 25859 3317bb8137f4
child 43235 da1786d695b6
permissions -rw-r--r--
8058089: api/javax_management/loading/MLetArgsSupport.html\#MLetArgsSupportTest0001 fails because of java.lang.IllegalArgumentException (argument type mismatch) Reviewed-by: dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
26484
871db348e647 8058089: api/javax_management/loading/MLetArgsSupport.html\#MLetArgsSupportTest0001 fails because of java.lang.IllegalArgumentException (argument type mismatch)
jbachorik
parents: 25859
diff changeset
     2
 * Copyright (c) 1999, 2014, 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: 1703
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: 1703
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: 1703
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1703
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1703
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 javax.management.loading;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
// Java import
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.jmx.defaults.JmxProperties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.jmx.defaults.ServiceName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.jmx.remote.util.EnvHelp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.Externalizable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.FileOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.ObjectInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.ObjectOutput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.lang.reflect.Constructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.net.URLStreamHandlerFactory;
13041
8477cb6992be 7143606: File.createTempFile should be improved for temporary files created by the platform.
robm
parents: 5506
diff changeset
    47
import java.nio.file.Files;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.util.logging.Level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import javax.management.InstanceAlreadyExistsException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import javax.management.InstanceNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import javax.management.MBeanException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import javax.management.MBeanRegistration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import javax.management.MBeanRegistrationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import javax.management.NotCompliantMBeanException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import javax.management.ObjectInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
import javax.management.ReflectionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
import static com.sun.jmx.defaults.JmxProperties.MLET_LIB_DIR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
import static com.sun.jmx.defaults.JmxProperties.MLET_LOGGER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
import com.sun.jmx.defaults.ServiceName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
import javax.management.ServiceNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * Allows you to instantiate and register one or several MBeans in the MBean server
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * coming from a remote URL. M-let is a shortcut for management applet. The m-let service does this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * by loading an m-let text file, which specifies information on the MBeans to be obtained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * The information on each MBean is specified in a single instance of a tag, called the MLET tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * The location of the m-let text file is specified by a URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * The <CODE>MLET</CODE> tag has the following syntax:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * &lt;<CODE>MLET</CODE><BR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *      <CODE>CODE = </CODE><VAR>class</VAR><CODE> | OBJECT = </CODE><VAR>serfile</VAR><BR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *      <CODE>ARCHIVE = &quot;</CODE><VAR>archiveList</VAR><CODE>&quot;</CODE><BR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *      <CODE>[CODEBASE = </CODE><VAR>codebaseURL</VAR><CODE>]</CODE><BR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *      <CODE>[NAME = </CODE><VAR>mbeanname</VAR><CODE>]</CODE><BR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *      <CODE>[VERSION = </CODE><VAR>version</VAR><CODE>]</CODE><BR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * &gt;<BR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *      <CODE>[</CODE><VAR>arglist</VAR><CODE>]</CODE><BR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * &lt;<CODE>/MLET</CODE>&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * where:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <DL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * <DT><CODE>CODE = </CODE><VAR>class</VAR></DT>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * <DD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * This attribute specifies the full Java class name, including package name, of the MBean to be obtained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * The compiled <CODE>.class</CODE> file of the MBean must be contained in one of the <CODE>.jar</CODE> files specified by the <CODE>ARCHIVE</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * attribute. Either <CODE>CODE</CODE> or <CODE>OBJECT</CODE> must be present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * </DD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * <DT><CODE>OBJECT = </CODE><VAR>serfile</VAR></DT>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * <DD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * This attribute specifies the <CODE>.ser</CODE> file that contains a serialized representation of the MBean to be obtained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * This file must be contained in one of the <CODE>.jar</CODE> files specified by the <CODE>ARCHIVE</CODE> attribute. If the <CODE>.jar</CODE> file contains a directory hierarchy, specify the path of the file within this hierarchy. Otherwise  a match will not be found. Either <CODE>CODE</CODE> or <CODE>OBJECT</CODE> must be present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * </DD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * <DT><CODE>ARCHIVE = &quot;</CODE><VAR>archiveList</VAR><CODE>&quot;</CODE></DT>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * <DD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * This mandatory attribute specifies one or more <CODE>.jar</CODE> files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * containing MBeans or other resources used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * the MBean to be obtained. One of the <CODE>.jar</CODE> files must contain the file specified by the <CODE>CODE</CODE> or <CODE>OBJECT</CODE> attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * If archivelist contains more than one file:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * <LI>Each file must be separated from the one that follows it by a comma (,).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <LI><VAR>archivelist</VAR> must be enclosed in double quote marks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * All <CODE>.jar</CODE> files in <VAR>archivelist</VAR> must be stored in the directory specified by the code base URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * </DD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * <DT><CODE>CODEBASE = </CODE><VAR>codebaseURL</VAR></DT>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * <DD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * This optional attribute specifies the code base URL of the MBean to be obtained. It identifies the directory that contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * the <CODE>.jar</CODE> files specified by the <CODE>ARCHIVE</CODE> attribute. Specify this attribute only if the <CODE>.jar</CODE> files are not in the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * directory as the m-let text file. If this attribute is not specified, the base URL of the m-let text file is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * </DD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * <DT><CODE>NAME = </CODE><VAR>mbeanname</VAR></DT>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * <DD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * This optional attribute specifies the object name to be assigned to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * MBean instance when the m-let service registers it. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * <VAR>mbeanname</VAR> starts with the colon character (:), the domain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * part of the object name is the default domain of the MBean server,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * as returned by {@link javax.management.MBeanServer#getDefaultDomain()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * </DD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * <DT><CODE>VERSION = </CODE><VAR>version</VAR></DT>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * <DD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * This optional attribute specifies the version number of the MBean and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * associated <CODE>.jar</CODE> files to be obtained. This version number can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * be used to specify that the <CODE>.jar</CODE> files are loaded from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * server to update those stored locally in the cache the next time the m-let
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * text file is loaded. <VAR>version</VAR> must be a series of non-negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * decimal integers each separated by a period from the one that precedes it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * </DD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <DT><VAR>arglist</VAR></DT>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * <DD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * This optional attribute specifies a list of one or more parameters for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * MBean to be instantiated. This list describes the parameters to be passed the MBean's constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * Use the following syntax to specify each item in
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 14014
diff changeset
   148
 * <VAR>arglist</VAR>:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * <DL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * <DT>&lt;<CODE>ARG TYPE=</CODE><VAR>argumentType</VAR> <CODE>VALUE=</CODE><VAR>value</VAR>&gt;</DT>
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 14014
diff changeset
   151
 * <DD>where:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * <LI><VAR>argumentType</VAR> is the type of the argument that will be passed as parameter to the MBean's constructor.</UL>
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 14014
diff changeset
   154
 * </DD>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * </DL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * <P>The arguments' type in the argument list should be a Java primitive type or a Java basic type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * (<CODE>java.lang.Boolean, java.lang.Byte, java.lang.Short, java.lang.Long, java.lang.Integer, java.lang.Float, java.lang.Double, java.lang.String</CODE>).
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 14014
diff changeset
   158
 * </DD>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * </DL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * When an m-let text file is loaded, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * instance of each MBean specified in the file is created and registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * The m-let service extends the <CODE>java.net.URLClassLoader</CODE> and can be used to load remote classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * and jar files in the VM of the agent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * <p><STRONG>Note - </STRONG> The <CODE>MLet</CODE> class loader uses the {@link javax.management.MBeanServerFactory#getClassLoaderRepository(javax.management.MBeanServer)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * to load classes that could not be found in the loaded jar files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
public class MLet extends java.net.URLClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     implements MLetMBean, MBeanRegistration, Externalizable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     private static final long serialVersionUID = 3636148327800330130L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *   PRIVATE VARIABLES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
      * The reference to the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
      * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     private MBeanServer server = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
      * The list of instances of the <CODE>MLetContent</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
      * class found at the specified URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
      * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     private List<MLetContent> mletList = new ArrayList<MLetContent>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
      * The directory used for storing libraries locally before they are loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     private String libraryDirectory;
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
      * The object name of the MLet Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
      * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     private ObjectName mletObjectName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
      * The URLs of the MLet Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
      * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     private URL[] myUrls = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
      * What ClassLoaderRepository, if any, to use if this MLet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
      * doesn't find an asked-for class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     private transient ClassLoaderRepository currentClr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
      * True if we should consult the {@link ClassLoaderRepository}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
      * when we do not find a class ourselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     private transient boolean delegateToCLR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
      * objects maps from primitive classes to primitive object classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     private Map<String,Class<?>> primitiveClasses =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
         new HashMap<String,Class<?>>(8) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
         primitiveClasses.put(Boolean.TYPE.toString(), Boolean.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
         primitiveClasses.put(Character.TYPE.toString(), Character.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
         primitiveClasses.put(Byte.TYPE.toString(), Byte.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
         primitiveClasses.put(Short.TYPE.toString(), Short.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
         primitiveClasses.put(Integer.TYPE.toString(), Integer.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
         primitiveClasses.put(Long.TYPE.toString(), Long.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
         primitiveClasses.put(Float.TYPE.toString(), Float.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
         primitiveClasses.put(Double.TYPE.toString(), Double.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
      * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
      *  CONSTRUCTORS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
      * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
      * The constructor stuff would be considerably simplified if our
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
      * parent, URLClassLoader, specified that its one- and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
      * two-argument constructors were equivalent to its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
      * three-argument constructor with trailing null arguments.  But
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
      * it doesn't, which prevents us from having all the constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
      * but one call this(...args...).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
      * Constructs a new MLet using the default delegation parent ClassLoader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     public MLet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
         this(new URL[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
      * Constructs a new MLet for the specified URLs using the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
      * delegation parent ClassLoader.  The URLs will be searched in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
      * the order specified for classes and resources after first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
      * searching in the parent class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
      * @param  urls  The URLs from which to load classes and resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     public MLet(URL[] urls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
         this(urls, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
      * Constructs a new MLet for the given URLs. The URLs will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
      * searched in the order specified for classes and resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
      * after first searching in the specified parent class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
      * The parent argument will be used as the parent class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
      * for delegation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
      * @param  urls  The URLs from which to load classes and resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
      * @param  parent The parent class loader for delegation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     public MLet(URL[] urls, ClassLoader parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
         this(urls, parent, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
      * Constructs a new MLet for the specified URLs, parent class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
      * loader, and URLStreamHandlerFactory. The parent argument will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
      * be used as the parent class loader for delegation. The factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
      * argument will be used as the stream handler factory to obtain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
      * protocol handlers when creating new URLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
      * @param  urls  The URLs from which to load classes and resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
      * @param  parent The parent class loader for delegation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
      * @param  factory  The URLStreamHandlerFactory to use when creating URLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     public MLet(URL[] urls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                 ClassLoader parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                 URLStreamHandlerFactory factory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
         this(urls, parent, factory, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
      * Constructs a new MLet for the specified URLs using the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
      * delegation parent ClassLoader.  The URLs will be searched in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
      * the order specified for classes and resources after first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
      * searching in the parent class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
      * @param  urls  The URLs from which to load classes and resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
      * @param  delegateToCLR  True if, when a class is not found in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
      * either the parent ClassLoader or the URLs, the MLet should delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
      * to its containing MBeanServer's {@link ClassLoaderRepository}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     public MLet(URL[] urls, boolean delegateToCLR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
         super(urls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
         init(delegateToCLR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
      * Constructs a new MLet for the given URLs. The URLs will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
      * searched in the order specified for classes and resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
      * after first searching in the specified parent class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
      * The parent argument will be used as the parent class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
      * for delegation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
      * @param  urls  The URLs from which to load classes and resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
      * @param  parent The parent class loader for delegation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
      * @param  delegateToCLR  True if, when a class is not found in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
      * either the parent ClassLoader or the URLs, the MLet should delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
      * to its containing MBeanServer's {@link ClassLoaderRepository}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     public MLet(URL[] urls, ClassLoader parent, boolean delegateToCLR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
         super(urls, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         init(delegateToCLR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
      * Constructs a new MLet for the specified URLs, parent class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
      * loader, and URLStreamHandlerFactory. The parent argument will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
      * be used as the parent class loader for delegation. The factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
      * argument will be used as the stream handler factory to obtain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
      * protocol handlers when creating new URLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
      * @param  urls  The URLs from which to load classes and resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
      * @param  parent The parent class loader for delegation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
      * @param  factory  The URLStreamHandlerFactory to use when creating URLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
      * @param  delegateToCLR  True if, when a class is not found in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
      * either the parent ClassLoader or the URLs, the MLet should delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
      * to its containing MBeanServer's {@link ClassLoaderRepository}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     public MLet(URL[] urls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                 ClassLoader parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                 URLStreamHandlerFactory factory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                 boolean delegateToCLR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
         super(urls, parent, factory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
         init(delegateToCLR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     private void init(boolean delegateToCLR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
         this.delegateToCLR = delegateToCLR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
             libraryDirectory = System.getProperty(MLET_LIB_DIR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
             if (libraryDirectory == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                 libraryDirectory = getTmpDir();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
         } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
             // OK : We don't do AccessController.doPrivileged, but we don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
             //      stop the user from creating an MLet just because they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
             //      can't read the MLET_LIB_DIR or java.io.tmpdir properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
             //      either.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
      * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
      *  PUBLIC METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
      * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
      * Appends the specified URL to the list of URLs to search for classes and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
      * resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     public void addURL(URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
         if (!Arrays.asList(getURLs()).contains(url))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
             super.addURL(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
      * Appends the specified URL to the list of URLs to search for classes and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
      * resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
      * @exception ServiceNotFoundException The specified URL is malformed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     public void addURL(String url) throws ServiceNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
             URL ur = new URL(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
             if (!Arrays.asList(getURLs()).contains(ur))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                 super.addURL(ur);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
         } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
             if (MLET_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                 MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                         "addUrl", "Malformed URL: " + url, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
             throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                 ServiceNotFoundException("The specified URL is malformed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     /** Returns the search path of URLs for loading classes and resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
      * This includes the original list of URLs specified to the constructor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
      * along with any URLs subsequently appended by the addURL() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     public URL[] getURLs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
         return super.getURLs();
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
      * Loads a text file containing MLET tags that define the MBeans to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
      * be added to the MBean server. The location of the text file is specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
      * a URL. The MBeans specified in the MLET file will be instantiated and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
      * registered in the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
      * @param url The URL of the text file to be loaded as URL object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
      * @return  A set containing one entry per MLET tag in the m-let text file loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
      * Each entry specifies either the ObjectInstance for the created MBean, or a throwable object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
      * (that is, an error or an exception) if the MBean could not be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
      * @exception ServiceNotFoundException One of the following errors has occurred: The m-let text file does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
      * not contain an MLET tag, the m-let text file is not found, a mandatory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
      * attribute of the MLET tag is not specified, the value of url is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
      * null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
      * @exception IllegalStateException MLet MBean is not registered with an MBeanServer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     public Set<Object> getMBeansFromURL(URL url)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
             throws ServiceNotFoundException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
         if (url == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
             throw new ServiceNotFoundException("The specified URL is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
         return getMBeansFromURL(url.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
      * Loads a text file containing MLET tags that define the MBeans to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
      * be added to the MBean server. The location of the text file is specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
      * a URL. The MBeans specified in the MLET file will be instantiated and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
      * registered in the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
      * @param url The URL of the text file to be loaded as String object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
      * @return A set containing one entry per MLET tag in the m-let
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
      * text file loaded.  Each entry specifies either the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
      * ObjectInstance for the created MBean, or a throwable object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
      * (that is, an error or an exception) if the MBean could not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
      * created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
      * @exception ServiceNotFoundException One of the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
      * errors has occurred: The m-let text file does not contain an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
      * MLET tag, the m-let text file is not found, a mandatory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
      * attribute of the MLET tag is not specified, the url is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
      * malformed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
      * @exception IllegalStateException MLet MBean is not registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
      * with an MBeanServer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     public Set<Object> getMBeansFromURL(String url)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
             throws ServiceNotFoundException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
         String mth = "getMBeansFromURL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
         if (server == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
             throw new IllegalStateException("This MLet MBean is not " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                                             "registered with an MBeanServer.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
         // Parse arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
         if (url == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
             MLET_LOGGER.logp(Level.FINER, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                     mth, "URL is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
             throw new ServiceNotFoundException("The specified URL is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
         } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
             url = url.replace(File.separatorChar,'/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
         if (MLET_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
             MLET_LOGGER.logp(Level.FINER, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                     mth, "<URL = " + url + ">");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
         // Parse URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
             MLetParser parser = new MLetParser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
             mletList = parser.parseURL(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
         } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
             final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                 "Problems while parsing URL [" + url +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                 "], got exception [" + e.toString() + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
             MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
             throw EnvHelp.initCause(new ServiceNotFoundException(msg), e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
         // Check that the list of MLets is not empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
         if (mletList.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
             final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                 "File " + url + " not found or MLET tag not defined in file";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
             MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
             throw new ServiceNotFoundException(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
         // Walk through the list of MLets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
         Set<Object> mbeans = new HashSet<Object>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
         for (MLetContent elmt : mletList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
             // Initialize local variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
             String code = elmt.getCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
             if (code != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                 if (code.endsWith(".class")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                     code = code.substring(0, code.length() - 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
             String name = elmt.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
             URL codebase = elmt.getCodeBase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
             String version = elmt.getVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
             String serName = elmt.getSerializedObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
             String jarFiles = elmt.getJarFiles();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
             URL documentBase = elmt.getDocumentBase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
             // Display debug information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
             if (MLET_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                 final StringBuilder strb = new StringBuilder()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                 .append("\n\tMLET TAG     = ").append(elmt.getAttributes())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                 .append("\n\tCODEBASE     = ").append(codebase)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                 .append("\n\tARCHIVE      = ").append(jarFiles)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                 .append("\n\tCODE         = ").append(code)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                 .append("\n\tOBJECT       = ").append(serName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                 .append("\n\tNAME         = ").append(name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                 .append("\n\tVERSION      = ").append(version)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                 .append("\n\tDOCUMENT URL = ").append(documentBase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                         mth, strb.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
             // Load classes from JAR files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
             StringTokenizer st = new StringTokenizer(jarFiles, ",", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
             while (st.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                 String tok = st.nextToken().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                 if (MLET_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                     MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                             "Load archive for codebase <" + codebase +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                             ">, file <" + tok + ">");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                 // Check which is the codebase to be used for loading the jar file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                 // If we are using the base MLet implementation then it will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                 // always the remote server but if the service has been extended in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                 // order to support caching and versioning then this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                 // return the appropriate one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                 //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                 try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                     codebase = check(version, codebase, tok, elmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                 } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                     MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                             mth, "Got unexpected exception", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                     mbeans.add(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                     continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                 // Appends the specified JAR file URL to the list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                 // URLs to search for classes and resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                 try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                     if (!Arrays.asList(getURLs())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                         .contains(new URL(codebase.toString() + tok))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                         addURL(codebase + tok);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                 } catch (MalformedURLException me) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                     // OK : Ignore jar file if its name provokes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                     // URL to be an invalid one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
             // Instantiate the class specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
             // CODE or OBJECT section of the MLet tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
             //
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   595
             Object o;
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   596
             ObjectInstance objInst;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
             if (code != null && serName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                 final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                     "CODE and OBJECT parameters cannot be specified at the " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                     "same time in tag MLET";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                 mbeans.add(new Error(msg));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                 continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
             if (code == null && serName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                 final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                     "Either CODE or OBJECT parameter must be specified in " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                     "tag MLET";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                 mbeans.add(new Error(msg));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                 continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
             try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                 if (code != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                     List<String> signat = elmt.getParameterTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                     List<String> stringPars = elmt.getParameterValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                     List<Object> objectPars = new ArrayList<Object>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                     for (int i = 0; i < signat.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                         objectPars.add(constructParameter(stringPars.get(i),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                                                           signat.get(i)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                     if (signat.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                         if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                             objInst = server.createMBean(code, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                                                          mletObjectName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                         } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                             objInst = server.createMBean(code,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                                                          new ObjectName(name),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                                                          mletObjectName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                     } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                         Object[] parms = objectPars.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                         String[] signature = new String[signat.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                         signat.toArray(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                         if (MLET_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                             final StringBuilder strb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                             for (int i = 0; i < signature.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                                 strb.append("\n\tSignature     = ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                                 .append(signature[i])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                                 .append("\t\nParams        = ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                                 .append(parms[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                             MLET_LOGGER.logp(Level.FINEST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                                     MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                                     mth, strb.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                         if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                             objInst =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                                 server.createMBean(code, null, mletObjectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                                                    parms, signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                         } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                             objInst =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                                 server.createMBean(code, new ObjectName(name),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                                                    mletObjectName, parms,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                                                    signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                 } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                     o = loadSerializedObject(codebase,serName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                     if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                         server.registerMBean(o, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                     } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                         server.registerMBean(o,  new ObjectName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                     objInst = new ObjectInstance(name, o.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
             } catch (ReflectionException  ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                         "ReflectionException", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                 mbeans.add(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                 continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
             } catch (InstanceAlreadyExistsException  ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                         "InstanceAlreadyExistsException", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                 mbeans.add(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                 continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
             } catch (MBeanRegistrationException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                         "MBeanRegistrationException", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                 mbeans.add(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                 continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
             } catch (MBeanException  ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                         "MBeanException", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                 mbeans.add(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                 continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
             } catch (NotCompliantMBeanException  ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                         "NotCompliantMBeanException", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                 mbeans.add(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                 continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
             } catch (InstanceNotFoundException   ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                         "InstanceNotFoundException", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                 mbeans.add(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                 continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
             } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                         "IOException", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                 mbeans.add(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                 continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
             } catch (SecurityException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                         "SecurityException", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                 mbeans.add(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                 continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
             } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                         "Exception", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                 mbeans.add(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                 continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
             } catch (Error ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                         "Error", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                 mbeans.add(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                 continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
             mbeans.add(objInst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
         return mbeans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
      * Gets the current directory used by the library loader for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
      * storing native libraries before they are loaded into memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
      * @return The current directory used by the library loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
      * @see #setLibraryDirectory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
      * @throws UnsupportedOperationException if this implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
      * does not support storing native libraries in this way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     public synchronized String getLibraryDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
         return libraryDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
      * Sets the directory used by the library loader for storing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
      * native libraries before they are loaded into memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
      * @param libdir The directory used by the library loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
      * @see #getLibraryDirectory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
      * @throws UnsupportedOperationException if this implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
      * does not support storing native libraries in this way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     public synchronized void setLibraryDirectory(String libdir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
         libraryDirectory = libdir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
      * Allows the m-let to perform any operations it needs before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
      * being registered in the MBean server. If the ObjectName is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
      * null, the m-let provides a default name for its registration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
      * &lt;defaultDomain&gt;:type=MLet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
      * @param server The MBean server in which the m-let will be registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
      * @param name The object name of the m-let.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
      * @return  The name of the m-let registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
      * @exception java.lang.Exception This exception should be caught by the MBean server and re-thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
      *as an MBeanRegistrationException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     public ObjectName preRegister(MBeanServer server, ObjectName name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
             throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
         // Initialize local pointer to the MBean server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
         setMBeanServer(server);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
         // If no name is specified return a default name for the MLet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
         if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
             name = new ObjectName(server.getDefaultDomain() + ":" + ServiceName.MLET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        this.mletObjectName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        return this.mletObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
      * Allows the m-let to perform any operations needed after having been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
      * registered in the MBean server or after the registration has failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
      * @param registrationDone Indicates whether or not the m-let has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
      * been successfully registered in the MBean server. The value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
      * false means that either the registration phase has failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     public void postRegister (Boolean registrationDone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
      * Allows the m-let to perform any operations it needs before being unregistered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
      * by the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
      *
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 13041
diff changeset
   801
      * @exception java.lang.Exception This exception should be caught
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
      * by the MBean server and re-thrown as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
      * MBeanRegistrationException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     public void preDeregister() throws java.lang.Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
      * Allows the m-let to perform any operations needed after having been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
      * unregistered in the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     public void postDeregister() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
      * <p>Save this MLet's contents to the given {@link ObjectOutput}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
      * Not all implementations support this method.  Those that do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
      * throw {@link UnsupportedOperationException}.  A subclass may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
      * override this method to support it or to change the format of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
      * the written data.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
      * <p>The format of the written data is not specified, but if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
      * an implementation supports {@link #writeExternal} it must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
      * also support {@link #readExternal} in such a way that what is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
      * written by the former can be read by the latter.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
      * @param out The object output stream to write to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
      * @exception IOException If a problem occurred while writing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
      * @exception UnsupportedOperationException If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
      * implementation does not support this operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     public void writeExternal(ObjectOutput out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
             throws IOException, UnsupportedOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
         throw new UnsupportedOperationException("MLet.writeExternal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
      * <p>Restore this MLet's contents from the given {@link ObjectInput}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
      * Not all implementations support this method.  Those that do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
      * throw {@link UnsupportedOperationException}.  A subclass may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
      * override this method to support it or to change the format of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
      * the read data.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
      * <p>The format of the read data is not specified, but if an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
      * implementation supports {@link #readExternal} it must also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
      * support {@link #writeExternal} in such a way that what is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
      * written by the latter can be read by the former.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
      * @param in The object input stream to read from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
      * @exception IOException if a problem occurred while reading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
      * @exception ClassNotFoundException if the class for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
      * being restored cannot be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
      * @exception UnsupportedOperationException if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
      * implementation does not support this operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     public void readExternal(ObjectInput in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
             throws IOException, ClassNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                    UnsupportedOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
         throw new UnsupportedOperationException("MLet.readExternal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
      * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
      *  PACKAGE METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
      * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
      * <p>Load a class, using the given {@link ClassLoaderRepository} if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
      * the class is not found in this MLet's URLs.  The given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
      * ClassLoaderRepository can be null, in which case a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
      * ClassNotFoundException} occurs immediately if the class is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
      * found in this MLet's URLs.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
      * @param name The name of the class we want to load.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
      * @param clr  The ClassLoaderRepository that will be used to search
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
      *             for the given class, if it is not found in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
      *             ClassLoader.  May be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
      * @return The resulting Class object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
      * @exception ClassNotFoundException The specified class could not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
      *            found in this ClassLoader nor in the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
      *            ClassLoaderRepository.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     public synchronized Class<?> loadClass(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                                            ClassLoaderRepository clr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
              throws ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
         final ClassLoaderRepository before=currentClr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
             currentClr = clr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
             return loadClass(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
         } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
             currentClr = before;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
      * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
      *  PROTECTED METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
      * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
      * This is the main method for class loaders that is being redefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
      * @param name The name of the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
      * @return The resulting Class object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
      * @exception ClassNotFoundException The specified class could not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
      *            found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     protected Class<?> findClass(String name) throws ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
         /* currentClr is context sensitive - used to avoid recursion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            in the class loader repository.  (This is no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            necessary with the new CLR semantics but is kept for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            compatibility with code that might have called the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            two-parameter loadClass explicitly.)  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
         return findClass(name, currentClr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
      * Called by {@link MLet#findClass(java.lang.String)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
      * @param name The name of the class that we want to load/find.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
      * @param clr The ClassLoaderRepository that can be used to search
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
      *            for the given class. This parameter is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
      *            <code>null</code> when called from within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
      *            {@link javax.management.MBeanServerFactory#getClassLoaderRepository(javax.management.MBeanServer) Class Loader Repository}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
      * @exception ClassNotFoundException The specified class could not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
      *            found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
      **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     Class<?> findClass(String name, ClassLoaderRepository clr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
         throws ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
         Class<?> c = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
         MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), "findClass", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
         // Try looking in the JAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
             c = super.findClass(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
             if (MLET_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                         "findClass",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                         "Class " + name + " loaded through MLet classloader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
         } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
             // Drop through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
             if (MLET_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                 MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                         "findClass",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                         "Class " + name + " not found locally");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
         // if we are not called from the ClassLoaderRepository
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
         if (c == null && delegateToCLR && clr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
             // Try the classloader repository:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
             //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
             try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                 if (MLET_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                     MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                             "findClass",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                             "Class " + name + " : looking in CLR");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                 c = clr.loadClassBefore(this, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                 // The loadClassBefore method never returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                 // If the class is not found we get an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                 if (MLET_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                     MLET_LOGGER.logp(Level.FINER, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                             "findClass",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                             "Class " + name + " loaded through " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                             "the default classloader repository");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
             } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                 // Drop through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                 if (MLET_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                     MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                             "findClass",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                             "Class " + name + " not found in CLR");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
         if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
             MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                     "findClass", "Failed to load class " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
             throw new ClassNotFoundException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
         return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
      * Returns the absolute path name of a native library. The VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
      * invokes this method to locate the native libraries that belong
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
      * to classes loaded with this class loader. Libraries are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
      * searched in the JAR files using first just the native library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
      * name and if not found the native library name together with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
      * the architecture-specific path name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
      * (<code>OSName/OSArch/OSVersion/lib/nativelibname</code>), i.e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
      * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
      * the library stat on Solaris SPARC 5.7 will be searched in the JAR file as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
      * <OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
      * <LI>libstat.so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
      * <LI>SunOS/sparc/5.7/lib/libstat.so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
      * </OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
      * the library stat on Windows NT 4.0 will be searched in the JAR file as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
      * <OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
      * <LI>stat.dll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
      * <LI>WindowsNT/x86/4.0/lib/stat.dll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
      * </OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
      * <p>More specifically, let <em>{@code nativelibname}</em> be the result of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
      * {@link System#mapLibraryName(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
      * System.mapLibraryName}{@code (libname)}.  Then the following names are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
      * searched in the JAR files, in order:<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
      * <em>{@code nativelibname}</em><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
      * {@code <os.name>/<os.arch>/<os.version>/lib/}<em>{@code nativelibname}</em><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
      * where {@code <X>} means {@code System.getProperty(X)} with any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
      * spaces in the result removed, and {@code /} stands for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
      * file separator character ({@link File#separator}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
      * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
      * If this method returns <code>null</code>, i.e. the libraries
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
      * were not found in any of the JAR files loaded with this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
      * loader, the VM searches the library along the path specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
      * as the <code>java.library.path</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
      * @param libname The library name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
      * @return The absolute path of the native library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     protected String findLibrary(String libname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
         String abs_path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
         String mth = "findLibrary";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
         // Get the platform-specific string representing a native library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
         //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
         String nativelibname = System.mapLibraryName(libname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
         //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
         // See if the native library is accessible as a resource through the JAR file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
         //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
         if (MLET_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
             MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                     "Search " + libname + " in all JAR files");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
         // First try to locate the library in the JAR file using only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
         // the native library name.  e.g. if user requested a load
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
         // for "foo" on Solaris SPARC 5.7 we try to load "libfoo.so"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
         // from the JAR file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
         //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
         if (MLET_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
             MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                     "loadLibraryAsResource(" + nativelibname + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
         abs_path = loadLibraryAsResource(nativelibname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
         if (abs_path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
             if (MLET_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                         nativelibname + " loaded, absolute path = " + abs_path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
             return abs_path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
         // Next try to locate it using the native library name and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
         // the architecture-specific path name.  e.g. if user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
         // requested a load for "foo" on Solaris SPARC 5.7 we try to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
         // load "SunOS/sparc/5.7/lib/libfoo.so" from the JAR file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
         //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
         nativelibname = removeSpace(System.getProperty("os.name")) + File.separator +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
             removeSpace(System.getProperty("os.arch")) + File.separator +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
             removeSpace(System.getProperty("os.version")) + File.separator +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
             "lib" + File.separator + nativelibname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
         if (MLET_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
             MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                     "loadLibraryAsResource(" + nativelibname + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
         abs_path = loadLibraryAsResource(nativelibname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
         if (abs_path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
             if (MLET_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                         nativelibname + " loaded, absolute path = " + abs_path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
             return abs_path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
         //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
         // All paths exhausted, library not found in JAR file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
         //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
         if (MLET_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
             MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                     libname + " not found in any JAR file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
             MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                     "Search " + libname + " along the path " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                     "specified as the java.library.path property");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
         // Let the VM search the library along the path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
         // specified as the java.library.path property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
         //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
         return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
      * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
      *  PRIVATE METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
      * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     private String getTmpDir() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
         // JDK 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
         String tmpDir = System.getProperty("java.io.tmpdir");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
         if (tmpDir != null) return tmpDir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
         // JDK < 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
         File tmpFile = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
             // Try to guess the system temporary dir...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
             tmpFile = File.createTempFile("tmp","jmx");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
             if (tmpFile == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
             final File tmpDirFile = tmpFile.getParentFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
             if (tmpDirFile == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
             return tmpDirFile.getAbsolutePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
         } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
             MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                     "getTmpDir", "Failed to determine system temporary dir");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
             return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
         } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
             // Cleanup ...
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1135
             if (tmpFile!=null) {
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1136
                 try {
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1137
                     boolean deleted = tmpFile.delete();
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1138
                     if (!deleted) {
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1139
                         MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1140
                                 "getTmpDir", "Failed to delete temp file");
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1141
                     }
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1142
                 } catch (Exception x) {
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1143
                     MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1144
                             "getTmpDir", "Failed to delete temporary file", x);
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1145
                 }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
      * Search the specified native library in any of the JAR files
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
      * loaded by this classloader.  If the library is found copy it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
      * into the library directory and return the absolute path.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
      * the library is not found then return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     private synchronized String loadLibraryAsResource(String libname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
         try {
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1158
             InputStream is = getResourceAsStream(
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1159
                     libname.replace(File.separatorChar,'/'));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
             if (is != null) {
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1161
                 try {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1162
                     File directory = new File(libraryDirectory);
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1163
                     directory.mkdirs();
13041
8477cb6992be 7143606: File.createTempFile should be improved for temporary files created by the platform.
robm
parents: 5506
diff changeset
  1164
                     File file = Files.createTempFile(directory.toPath(),
8477cb6992be 7143606: File.createTempFile should be improved for temporary files created by the platform.
robm
parents: 5506
diff changeset
  1165
                                                      libname + ".", null)
8477cb6992be 7143606: File.createTempFile should be improved for temporary files created by the platform.
robm
parents: 5506
diff changeset
  1166
                                      .toFile();
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1167
                     file.deleteOnExit();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1168
                     FileOutputStream fileOutput = new FileOutputStream(file);
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1169
                     try {
1703
a28fa559929a 6405891: MLet: could be improved to load a native lib
sjiang
parents: 1510
diff changeset
  1170
                         byte[] buf = new byte[4096];
a28fa559929a 6405891: MLet: could be improved to load a native lib
sjiang
parents: 1510
diff changeset
  1171
                         int n;
a28fa559929a 6405891: MLet: could be improved to load a native lib
sjiang
parents: 1510
diff changeset
  1172
                         while ((n = is.read(buf)) >= 0) {
a28fa559929a 6405891: MLet: could be improved to load a native lib
sjiang
parents: 1510
diff changeset
  1173
                            fileOutput.write(buf, 0, n);
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1174
                         }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1175
                     } finally {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1176
                         fileOutput.close();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1177
                     }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1178
                     if (file.exists()) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1179
                         return file.getAbsolutePath();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1180
                     }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1181
                 } finally {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1182
                     is.close();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
         } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
             MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                     "loadLibraryAsResource",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                     "Failed to load library : " + libname, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
             return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
         return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    * Removes any white space from a string. This is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
    * convert strings such as "Windows NT" to "WindowsNT".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    */
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1198
     private static String removeSpace(String s) {
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1199
         return s.trim().replace(" ", "");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
      * <p>This method is to be overridden when extending this service to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
      * support caching and versioning.  It is called from {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
      * #getMBeansFromURL getMBeansFromURL} when the version,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
      * codebase, and jarfile have been extracted from the MLet file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
      * and can be used to verify that it is all right to load the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
      * given MBean, or to replace the given URL with a different one.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
      * <p>The default implementation of this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
      * <code>codebase</code> unchanged.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
      * @param version The version number of the <CODE>.jar</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
      * file stored locally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
      * @param codebase The base URL of the remote <CODE>.jar</CODE> file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
      * @param jarfile The name of the <CODE>.jar</CODE> file to be loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
      * @param mlet The <CODE>MLetContent</CODE> instance that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
      * represents the <CODE>MLET</CODE> tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
      * @return the codebase to use for the loaded MBean.  The returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
      * value should not be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
      * @exception Exception if the MBean is not to be loaded for some
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
      * reason.  The exception will be added to the set returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
      * {@link #getMBeansFromURL getMBeansFromURL}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     protected URL check(String version, URL codebase, String jarfile,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                         MLetContent mlet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
             throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
         return codebase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * Loads the serialized object specified by the <CODE>OBJECT</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * attribute of the <CODE>MLET</CODE> tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * @param codebase The <CODE>codebase</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * @param filename The name of the file containing the serialized object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * @return The serialized object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * @exception ClassNotFoundException The specified serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * object could not be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * @exception IOException An I/O error occurred while loading
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * serialized object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     private Object loadSerializedObject(URL codebase, String filename)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
             throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        if (filename != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            filename = filename.replace(File.separatorChar,'/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        if (MLET_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            MLET_LOGGER.logp(Level.FINER, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                    "loadSerializedObject", codebase.toString() + filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        InputStream is = getResourceAsStream(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        if (is != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                ObjectInputStream ois = new MLetObjectInputStream(is, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                Object serObject = ois.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                ois.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                return serObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                if (MLET_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                    MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                            "loadSerializedObject",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                            "Exception while deserializing " + filename, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                if (MLET_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
                    MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                            "loadSerializedObject",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                            "Exception while deserializing " + filename, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
            if (MLET_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                        "loadSerializedObject", "Error: File " + filename +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                        " containing serialized object not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            throw new Error("File " + filename + " containing serialized object not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
      * Converts the String value of the constructor's parameter to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
      * a basic Java object with the type of the parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     private  Object constructParameter(String param, String type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
         // check if it is a primitive type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
         Class<?> c = primitiveClasses.get(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
         if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                Constructor<?> cons =
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  1297
                    c.getConstructor(String.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                Object[] oo = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                oo[0]=param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                return(cons.newInstance(oo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            } catch (Exception  e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                        "constructParameter", "Got unexpected exception", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        if (type.compareTo("java.lang.Boolean") == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
             return Boolean.valueOf(param);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        if (type.compareTo("java.lang.Byte") == 0)
25187
08aff438def8 8048874: Replace uses of 'new Byte', 'new Short' and 'new Character' with appropriate alternative across core classes
prappo
parents: 25186
diff changeset
  1310
             return Byte.valueOf(param);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        if (type.compareTo("java.lang.Short") == 0)
25187
08aff438def8 8048874: Replace uses of 'new Byte', 'new Short' and 'new Character' with appropriate alternative across core classes
prappo
parents: 25186
diff changeset
  1312
             return Short.valueOf(param);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        if (type.compareTo("java.lang.Long") == 0)
25186
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 23010
diff changeset
  1314
             return Long.valueOf(param);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        if (type.compareTo("java.lang.Integer") == 0)
26484
871db348e647 8058089: api/javax_management/loading/MLetArgsSupport.html\#MLetArgsSupportTest0001 fails because of java.lang.IllegalArgumentException (argument type mismatch)
jbachorik
parents: 25859
diff changeset
  1316
             return Integer.valueOf(param);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        if (type.compareTo("java.lang.Float") == 0)
26484
871db348e647 8058089: api/javax_management/loading/MLetArgsSupport.html\#MLetArgsSupportTest0001 fails because of java.lang.IllegalArgumentException (argument type mismatch)
jbachorik
parents: 25859
diff changeset
  1318
             return Float.valueOf(param);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        if (type.compareTo("java.lang.Double") == 0)
26484
871db348e647 8058089: api/javax_management/loading/MLetArgsSupport.html\#MLetArgsSupportTest0001 fails because of java.lang.IllegalArgumentException (argument type mismatch)
jbachorik
parents: 25859
diff changeset
  1320
             return Double.valueOf(param);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        if (type.compareTo("java.lang.String") == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
             return param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        return param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    private synchronized void setMBeanServer(final MBeanServer server) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        this.server = server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        PrivilegedAction<ClassLoaderRepository> act =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
            new PrivilegedAction<ClassLoaderRepository>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                public ClassLoaderRepository run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                    return server.getClassLoaderRepository();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        currentClr = AccessController.doPrivileged(act);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
}