From 8c238eddce67219c3ad4b8fbe61bbcef17b939ab Mon Sep 17 00:00:00 2001 From: Kevin Walls Date: Mon, 15 Jan 2024 11:12:38 +0000 Subject: [PATCH] 8318707: Remove the Java Management Extension (JMX) Management Applet (m-let) feature Reviewed-by: sspitsyn, dfuchs --- .../com/sun/jmx/defaults/JmxProperties.java | 30 +- .../com/sun/jmx/defaults/ServiceName.java | 10 +- .../ClassLoaderRepositorySupport.java | 14 +- .../security/MBeanServerAccessController.java | 51 +- .../javax/management/loading/MLet.java | 1294 ----------------- .../javax/management/loading/MLetContent.java | 245 ---- .../javax/management/loading/MLetMBean.java | 190 --- .../loading/MLetObjectInputStream.java | 125 -- .../javax/management/loading/MLetParser.java | 279 ---- .../javax/management/loading/PrivateMLet.java | 105 -- .../javax/management/loading/package.html | 21 +- .../Introspector/ClassLeakTest.java | 43 +- .../MBeanServer/PostExceptionTest.java | 33 +- .../management/loading/ArrayClassTest.java | 21 +- .../management/loading/DocumentRootTest.java | 75 - .../loading/GetMBeansFromURLTest.java | 105 -- .../LibraryLoader/LibraryLoaderTest.java | 155 -- .../loading/LibraryLoader/UseNativeLib0.html | 19 - .../loading/LibraryLoader/UseNativeLib1.html | 19 - .../loading/LibraryLoader/jar_src/RandomGen.c | 15 - .../loading/LibraryLoader/jar_src/RandomGen.h | 15 - .../LibraryLoader/jar_src/UseNativeLib.java | 36 - .../jar_src/UseNativeLibMBean.java | 26 - .../loading/LibraryLoader/native.jar | Bin 4223 -> 0 bytes .../loading/MLetCLR/MLetCommand.java | 65 - .../javax/management/loading/MLetCLR/policy | 8 - .../management/loading/MLetContentTest.java | 146 -- .../management/loading/MLetInternalsTest.java | 93 -- .../loading/MletParserLocaleTest.java | 110 -- .../loading/ParserInfiniteLoopTest.java | 123 -- test/jdk/javax/management/loading/mlet1.html | 2 - test/jdk/javax/management/loading/mlet2.html | 2 - test/jdk/javax/management/loading/mlet3.html | 3 - test/jdk/javax/management/loading/mlet4.html | 2 - .../management/mxbean/MXBeanLoadingTest1.java | 48 +- .../management/relation/NonArrayListTest.java | 21 +- .../mandatory/connection/IdleTimeoutTest.java | 20 +- .../mandatory/loading/TargetMBeanTest.java | 37 +- .../notif/NotificationBufferTest.java | 7 +- .../passwordAuthenticator/RMIAltAuthTest.java | 8 +- .../RMIPasswdAuthTest.java | 8 +- 41 files changed, 139 insertions(+), 3490 deletions(-) delete mode 100644 src/java.management/share/classes/javax/management/loading/MLet.java delete mode 100644 src/java.management/share/classes/javax/management/loading/MLetContent.java delete mode 100644 src/java.management/share/classes/javax/management/loading/MLetMBean.java delete mode 100644 src/java.management/share/classes/javax/management/loading/MLetObjectInputStream.java delete mode 100644 src/java.management/share/classes/javax/management/loading/MLetParser.java delete mode 100644 src/java.management/share/classes/javax/management/loading/PrivateMLet.java delete mode 100644 test/jdk/javax/management/loading/DocumentRootTest.java delete mode 100644 test/jdk/javax/management/loading/GetMBeansFromURLTest.java delete mode 100644 test/jdk/javax/management/loading/LibraryLoader/LibraryLoaderTest.java delete mode 100644 test/jdk/javax/management/loading/LibraryLoader/UseNativeLib0.html delete mode 100644 test/jdk/javax/management/loading/LibraryLoader/UseNativeLib1.html delete mode 100644 test/jdk/javax/management/loading/LibraryLoader/jar_src/RandomGen.c delete mode 100644 test/jdk/javax/management/loading/LibraryLoader/jar_src/RandomGen.h delete mode 100644 test/jdk/javax/management/loading/LibraryLoader/jar_src/UseNativeLib.java delete mode 100644 test/jdk/javax/management/loading/LibraryLoader/jar_src/UseNativeLibMBean.java delete mode 100644 test/jdk/javax/management/loading/LibraryLoader/native.jar delete mode 100644 test/jdk/javax/management/loading/MLetCLR/MLetCommand.java delete mode 100644 test/jdk/javax/management/loading/MLetCLR/policy delete mode 100644 test/jdk/javax/management/loading/MLetContentTest.java delete mode 100644 test/jdk/javax/management/loading/MLetInternalsTest.java delete mode 100644 test/jdk/javax/management/loading/MletParserLocaleTest.java delete mode 100644 test/jdk/javax/management/loading/ParserInfiniteLoopTest.java delete mode 100644 test/jdk/javax/management/loading/mlet1.html delete mode 100644 test/jdk/javax/management/loading/mlet2.html delete mode 100644 test/jdk/javax/management/loading/mlet3.html delete mode 100644 test/jdk/javax/management/loading/mlet4.html diff --git a/src/java.management/share/classes/com/sun/jmx/defaults/JmxProperties.java b/src/java.management/share/classes/com/sun/jmx/defaults/JmxProperties.java index 566d0f9d5cd..a70080161af 100644 --- a/src/java.management/share/classes/com/sun/jmx/defaults/JmxProperties.java +++ b/src/java.management/share/classes/com/sun/jmx/defaults/JmxProperties.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,24 +44,14 @@ public class JmxProperties { //------------------------ /** - * References the property that specifies the directory where - * the native libraries will be stored before the MLet Service - * loads them into memory. + * References the property that optionally specifies the class name + * of an alternative MBeanServerBuilder. *

- * Property Name: jmx.mlet.library.dir + * Property Name: javax.management.builder.initial */ public static final String JMX_INITIAL_BUILDER = "javax.management.builder.initial"; - /** - * References the property that specifies the directory where - * the native libraries will be stored before the MLet Service - * loads them into memory. - *

- * Property Name: jmx.mlet.library.dir - */ - public static final String MLET_LIB_DIR = "jmx.mlet.library.dir"; - /** * References the property that specifies the full name of the JMX * specification implemented by this product. @@ -122,18 +112,6 @@ public class JmxProperties { public static final Logger MBEANSERVER_LOGGER = System.getLogger(MBEANSERVER_LOGGER_NAME); - /** - * Logger name for MLet service information. - */ - public static final String MLET_LOGGER_NAME = - "javax.management.mlet"; - - /** - * Logger for MLet service information. - */ - public static final Logger MLET_LOGGER = - System.getLogger(MLET_LOGGER_NAME); - /** * Logger name for Monitor information. */ diff --git a/src/java.management/share/classes/com/sun/jmx/defaults/ServiceName.java b/src/java.management/share/classes/com/sun/jmx/defaults/ServiceName.java index 8f742dff0f8..b1948178483 100644 --- a/src/java.management/share/classes/com/sun/jmx/defaults/ServiceName.java +++ b/src/java.management/share/classes/com/sun/jmx/defaults/ServiceName.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,14 +44,6 @@ public class ServiceName { public static final String DELEGATE = "JMImplementation:type=MBeanServerDelegate" ; - /** - * The default key properties for registering the class loader of the - * MLet service. - *
- * The value is type=MLet. - */ - public static final String MLET = "type=MLet"; - /** * The default domain. *
diff --git a/src/java.management/share/classes/com/sun/jmx/mbeanserver/ClassLoaderRepositorySupport.java b/src/java.management/share/classes/com/sun/jmx/mbeanserver/ClassLoaderRepositorySupport.java index 38050ca0d7a..a73e46e6020 100644 --- a/src/java.management/share/classes/com/sun/jmx/mbeanserver/ClassLoaderRepositorySupport.java +++ b/src/java.management/share/classes/com/sun/jmx/mbeanserver/ClassLoaderRepositorySupport.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -206,18 +206,6 @@ final class ClassLoaderRepositorySupport if (MBEANSERVER_LOGGER.isLoggable(Level.TRACE)) { MBEANSERVER_LOGGER.log(Level.TRACE, "Trying loader = " + cl); } - /* We used to have a special case for "instanceof - MLet" here, where we invoked the method - loadClass(className, null) to prevent infinite - recursion. But the rule whereby the MLet only - consults loaders that precede it in the CLR (via - loadClassBefore) means that the recursion can't - happen, and the test here caused some legitimate - classloading to fail. For example, if you have - dependencies C->D->E with loaders {E D C} in the - CLR in that order, you would expect to be able to - load C. The problem is that while resolving D, CLR - delegation is disabled, so it can't find E. */ return Class.forName(className, false, cl); } catch (ClassNotFoundException e) { // OK: continue with next class diff --git a/src/java.management/share/classes/com/sun/jmx/remote/security/MBeanServerAccessController.java b/src/java.management/share/classes/com/sun/jmx/remote/security/MBeanServerAccessController.java index ac9c8cfada9..c94750e99ff 100644 --- a/src/java.management/share/classes/com/sun/jmx/remote/security/MBeanServerAccessController.java +++ b/src/java.management/share/classes/com/sun/jmx/remote/security/MBeanServerAccessController.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -75,12 +75,11 @@ import javax.management.remote.MBeanServerForwarder; * inappropriate.

* *

If there is no SecurityManager, then the access controller will refuse - * to create an MBean that is a ClassLoader, which includes MLets, or to - * execute the method addURL on an MBean that is an MLet. This prevents + * to create an MBean that is a ClassLoader. This prevents * people from opening security holes unintentionally. Otherwise, it * would not be obvious that granting write access grants the ability to * download and execute arbitrary code in the target MBean server. Advanced - * users who do want the ability to use MLets are presumably advanced enough + * users who do want an MBean which is a ClassLoader are presumably advanced enough * to handle policy files and security managers.

*/ public abstract class MBeanServerAccessController @@ -468,7 +467,6 @@ public abstract class MBeanServerAccessController MBeanException, ReflectionException { checkWrite(); - checkMLetMethods(name, operationName); return getMBeanServer().invoke(name, operationName, params, signature); } @@ -620,49 +618,6 @@ public abstract class MBeanServerAccessController "manager is installed."); } - private void checkMLetMethods(ObjectName name, String operation) - throws InstanceNotFoundException { - // Check if security manager installed - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - return; - } - // Check for addURL and getMBeansFromURL methods - if (!operation.equals("addURL") && - !operation.equals("getMBeansFromURL")) { - return; - } - // Check if MBean is instance of MLet - if (!getMBeanServer().isInstanceOf(name, - "javax.management.loading.MLet")) { - return; - } - // Throw security exception - if (operation.equals("addURL")) { // addURL - throw new SecurityException("Access denied! MLet method addURL " + - "cannot be invoked unless a security manager is installed."); - } else { // getMBeansFromURL - // Whether or not calling getMBeansFromURL is allowed is controlled - // by the value of the "jmx.remote.x.mlet.allow.getMBeansFromURL" - // system property. If the value of this property is true, calling - // the MLet's getMBeansFromURL method is allowed. The default value - // for this property is false. - final String propName = "jmx.remote.x.mlet.allow.getMBeansFromURL"; - GetPropertyAction propAction = new GetPropertyAction(propName); - @SuppressWarnings("removal") - String propValue = AccessController.doPrivileged(propAction); - boolean allowGetMBeansFromURL = "true".equalsIgnoreCase(propValue); - if (!allowGetMBeansFromURL) { - throw new SecurityException("Access denied! MLet method " + - "getMBeansFromURL cannot be invoked unless a " + - "security manager is installed or the system property " + - "-Djmx.remote.x.mlet.allow.getMBeansFromURL=true " + - "is specified."); - } - } - } - //------------------ // PRIVATE VARIABLES //------------------ diff --git a/src/java.management/share/classes/javax/management/loading/MLet.java b/src/java.management/share/classes/javax/management/loading/MLet.java deleted file mode 100644 index aacf73e4821..00000000000 --- a/src/java.management/share/classes/javax/management/loading/MLet.java +++ /dev/null @@ -1,1294 +0,0 @@ -/* - * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javax.management.loading; - -import com.sun.jmx.defaults.ServiceName; - -import com.sun.jmx.remote.util.EnvHelp; - -import java.io.Externalizable; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInput; -import java.io.ObjectInputStream; -import java.io.ObjectOutput; -import java.lang.reflect.Constructor; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLStreamHandlerFactory; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.lang.System.Logger.Level; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; - -import javax.management.InstanceAlreadyExistsException; -import javax.management.InstanceNotFoundException; -import javax.management.MBeanException; -import javax.management.MBeanRegistration; -import javax.management.MBeanRegistrationException; -import javax.management.MBeanServer; -import javax.management.NotCompliantMBeanException; -import javax.management.ObjectInstance; -import javax.management.ObjectName; -import javax.management.ReflectionException; - -import static com.sun.jmx.defaults.JmxProperties.MLET_LIB_DIR; -import static com.sun.jmx.defaults.JmxProperties.MLET_LOGGER; -import javax.management.ServiceNotFoundException; - -/** - * Allows you to instantiate and register one or several MBeans in the MBean server - * coming from a remote URL. M-let is a shortcut for management applet. The m-let service does this - * by loading an m-let text file, which specifies information on the MBeans to be obtained. - * The information on each MBean is specified in a single instance of a tag, called the MLET tag. - * The location of the m-let text file is specified by a URL. - *

- * The MLET tag has the following syntax: - *

- * <MLET
- * CODE = class | OBJECT = serfile
- * ARCHIVE = "archiveList"
- * [CODEBASE = codebaseURL]
- * [NAME = mbeanname]
- * [VERSION = version]
- * >
- * [arglist]
- * </MLET> - *

- * where: - *

- *
CODE = class
- *
- * This attribute specifies the full Java class name, including package name, of the MBean to be obtained. - * The compiled .class file of the MBean must be contained in one of the .jar files specified by the ARCHIVE - * attribute. Either CODE or OBJECT must be present. - *
- *
OBJECT = serfile
- *
- * This attribute specifies the .ser file that contains a serialized representation of the MBean to be obtained. - * This file must be contained in one of the .jar files specified by the ARCHIVE attribute. If the .jar file contains a directory hierarchy, specify the path of the file within this hierarchy. Otherwise a match will not be found. Either CODE or OBJECT must be present. - *
- *
ARCHIVE = "archiveList"
- *
- * This mandatory attribute specifies one or more .jar files - * containing MBeans or other resources used by - * the MBean to be obtained. One of the .jar files must contain the file specified by the CODE or OBJECT attribute. - * If archivelist contains more than one file: - *
    - *
  • Each file must be separated from the one that follows it by a comma (,). - *
  • archivelist must be enclosed in double quote marks. - *
- * All .jar files in archivelist must be stored in the directory specified by the code base URL. - *
- *
CODEBASE = codebaseURL
- *
- * This optional attribute specifies the code base URL of the MBean to be obtained. It identifies the directory that contains - * the .jar files specified by the ARCHIVE attribute. Specify this attribute only if the .jar files are not in the same - * directory as the m-let text file. If this attribute is not specified, the base URL of the m-let text file is used. - *
- *
NAME = mbeanname
- *
- * This optional attribute specifies the object name to be assigned to the - * MBean instance when the m-let service registers it. If - * mbeanname starts with the colon character (:), the domain - * part of the object name is the default domain of the MBean server, - * as returned by {@link javax.management.MBeanServer#getDefaultDomain()}. - *
- *
VERSION = version
- *
- * This optional attribute specifies the version number of the MBean and - * associated .jar files to be obtained. This version number can - * be used to specify that the .jar files are loaded from the - * server to update those stored locally in the cache the next time the m-let - * text file is loaded. version must be a series of non-negative - * decimal integers each separated by a period from the one that precedes it. - *
- *
arglist
- *
- * This optional attribute specifies a list of one or more parameters for the - * MBean to be instantiated. This list describes the parameters to be passed the MBean's constructor. - * Use the following syntax to specify each item in - * arglist: - *
- *
<ARG TYPE=argumentType VALUE=value>
- *
where: - *
    - *
  • argumentType is the type of the argument that will be passed as parameter to the MBean's constructor.
- *
- *
- *

The arguments' type in the argument list should be a Java primitive type or a Java basic type - * (java.lang.Boolean, java.lang.Byte, java.lang.Short, java.lang.Long, java.lang.Integer, java.lang.Float, java.lang.Double, java.lang.String). - *

- *
- * - * When an m-let text file is loaded, an - * instance of each MBean specified in the file is created and registered. - *

- * The m-let service extends the java.net.URLClassLoader and can be used to load remote classes - * and jar files in the VM of the agent. - *

Note - The MLet class loader uses the {@link javax.management.MBeanServerFactory#getClassLoaderRepository(javax.management.MBeanServer)} - * to load classes that could not be found in the loaded jar files. - * - * @deprecated This API is part of Management Applets (m-lets), which is a legacy feature that allows loading - * of remote MBeans. This feature is not usable without a Security Manager, which is deprecated and subject to - * removal in a future release. Consequently, this API is also deprecated and subject to removal. There is no replacement. - * - * @since 1.5 - */ -@Deprecated(since="20", forRemoval=true) -@SuppressWarnings("removal") -public class MLet extends java.net.URLClassLoader - implements MLetMBean, MBeanRegistration, Externalizable { - - private static final long serialVersionUID = 3636148327800330130L; - - /* - * ------------------------------------------ - * PRIVATE VARIABLES - * ------------------------------------------ - */ - - /** - * The reference to the MBean server. - * @serial - */ - @SuppressWarnings("serial") // Type of field is not Serializable - private MBeanServer server = null; - - - /** - * The list of instances of the MLetContent - * class found at the specified URL. - * @serial - */ - @SuppressWarnings("serial") // Type of field is not Serializable - private List mletList = new ArrayList<>(); - - - /** - * The directory used for storing libraries locally before they are loaded. - */ - private String libraryDirectory; - - - /** - * The object name of the MLet Service. - * @serial - */ - private ObjectName mletObjectName = null; - - /** - * The URLs of the MLet Service. - * @serial - */ - private URL[] myUrls = null; - - /** - * What ClassLoaderRepository, if any, to use if this MLet - * doesn't find an asked-for class. - */ - private transient ClassLoaderRepository currentClr; - - /** - * True if we should consult the {@link ClassLoaderRepository} - * when we do not find a class ourselves. - */ - private transient boolean delegateToCLR; - - /** - * objects maps from primitive classes to primitive object classes. - */ - @SuppressWarnings("serial") // Type of field is not Serializable - private Map> primitiveClasses = new HashMap<>(8) ; - { - primitiveClasses.put(Boolean.TYPE.toString(), Boolean.class); - primitiveClasses.put(Character.TYPE.toString(), Character.class); - primitiveClasses.put(Byte.TYPE.toString(), Byte.class); - primitiveClasses.put(Short.TYPE.toString(), Short.class); - primitiveClasses.put(Integer.TYPE.toString(), Integer.class); - primitiveClasses.put(Long.TYPE.toString(), Long.class); - primitiveClasses.put(Float.TYPE.toString(), Float.class); - primitiveClasses.put(Double.TYPE.toString(), Double.class); - - } - - - /* - * ------------------------------------------ - * CONSTRUCTORS - * ------------------------------------------ - */ - - /* - * The constructor stuff would be considerably simplified if our - * parent, URLClassLoader, specified that its one- and - * two-argument constructors were equivalent to its - * three-argument constructor with trailing null arguments. But - * it doesn't, which prevents us from having all the constructors - * but one call this(...args...). - */ - - /** - * Constructs a new MLet using the default delegation parent ClassLoader. - */ - public MLet() { - this(new URL[0]); - } - - /** - * Constructs a new MLet for the specified URLs using the default - * delegation parent ClassLoader. The URLs will be searched in - * the order specified for classes and resources after first - * searching in the parent class loader. - * - * @param urls The URLs from which to load classes and resources. - * - */ - public MLet(URL[] urls) { - this(urls, true); - } - - /** - * Constructs a new MLet for the given URLs. The URLs will be - * searched in the order specified for classes and resources - * after first searching in the specified parent class loader. - * The parent argument will be used as the parent class loader - * for delegation. - * - * @param urls The URLs from which to load classes and resources. - * @param parent The parent class loader for delegation. - * - */ - public MLet(URL[] urls, ClassLoader parent) { - this(urls, parent, true); - } - - /** - * Constructs a new MLet for the specified URLs, parent class - * loader, and URLStreamHandlerFactory. The parent argument will - * be used as the parent class loader for delegation. The factory - * argument will be used as the stream handler factory to obtain - * protocol handlers when creating new URLs. - * - * @param urls The URLs from which to load classes and resources. - * @param parent The parent class loader for delegation. - * @param factory The URLStreamHandlerFactory to use when creating URLs. - * - */ - public MLet(URL[] urls, - ClassLoader parent, - URLStreamHandlerFactory factory) { - this(urls, parent, factory, true); - } - - /** - * Constructs a new MLet for the specified URLs using the default - * delegation parent ClassLoader. The URLs will be searched in - * the order specified for classes and resources after first - * searching in the parent class loader. - * - * @param urls The URLs from which to load classes and resources. - * @param delegateToCLR True if, when a class is not found in - * either the parent ClassLoader or the URLs, the MLet should delegate - * to its containing MBeanServer's {@link ClassLoaderRepository}. - * - */ - public MLet(URL[] urls, boolean delegateToCLR) { - super(urls); - init(delegateToCLR); - } - - /** - * Constructs a new MLet for the given URLs. The URLs will be - * searched in the order specified for classes and resources - * after first searching in the specified parent class loader. - * The parent argument will be used as the parent class loader - * for delegation. - * - * @param urls The URLs from which to load classes and resources. - * @param parent The parent class loader for delegation. - * @param delegateToCLR True if, when a class is not found in - * either the parent ClassLoader or the URLs, the MLet should delegate - * to its containing MBeanServer's {@link ClassLoaderRepository}. - * - */ - public MLet(URL[] urls, ClassLoader parent, boolean delegateToCLR) { - super(urls, parent); - init(delegateToCLR); - } - - /** - * Constructs a new MLet for the specified URLs, parent class - * loader, and URLStreamHandlerFactory. The parent argument will - * be used as the parent class loader for delegation. The factory - * argument will be used as the stream handler factory to obtain - * protocol handlers when creating new URLs. - * - * @param urls The URLs from which to load classes and resources. - * @param parent The parent class loader for delegation. - * @param factory The URLStreamHandlerFactory to use when creating URLs. - * @param delegateToCLR True if, when a class is not found in - * either the parent ClassLoader or the URLs, the MLet should delegate - * to its containing MBeanServer's {@link ClassLoaderRepository}. - * - */ - public MLet(URL[] urls, - ClassLoader parent, - URLStreamHandlerFactory factory, - boolean delegateToCLR) { - super(urls, parent, factory); - init(delegateToCLR); - } - - private void init(boolean delegateToCLR) { - this.delegateToCLR = delegateToCLR; - - try { - libraryDirectory = System.getProperty(MLET_LIB_DIR); - if (libraryDirectory == null) - libraryDirectory = getTmpDir(); - } catch (SecurityException e) { - // OK : We don't do AccessController.doPrivileged, but we don't - // stop the user from creating an MLet just because they - // can't read the MLET_LIB_DIR or java.io.tmpdir properties - // either. - } - } - - - /* - * ------------------------------------------ - * PUBLIC METHODS - * ------------------------------------------ - */ - - - /** - * Appends the specified URL to the list of URLs to search for classes and - * resources. - */ - public void addURL(URL url) { - if (!Arrays.asList(getURLs()).contains(url)) - super.addURL(url); - } - - /** - * Appends the specified URL to the list of URLs to search for classes and - * resources. - * @exception ServiceNotFoundException The specified URL is malformed. - */ - public void addURL(String url) throws ServiceNotFoundException { - try { - @SuppressWarnings("deprecation") - URL ur = new URL(url); - if (!Arrays.asList(getURLs()).contains(ur)) - super.addURL(ur); - } catch (MalformedURLException e) { - if (MLET_LOGGER.isLoggable(Level.DEBUG)) { - MLET_LOGGER.log(Level.DEBUG, "Malformed URL: " + url, e); - } - throw new - ServiceNotFoundException("The specified URL is malformed"); - } - } - - /** Returns the search path of URLs for loading classes and resources. - * This includes the original list of URLs specified to the constructor, - * along with any URLs subsequently appended by the addURL() method. - */ - public URL[] getURLs() { - return super.getURLs(); - } - - /** - * Loads a text file containing MLET tags that define the MBeans to - * be added to the MBean server. The location of the text file is specified by - * a URL. The MBeans specified in the MLET file will be instantiated and - * registered in the MBean server. - * - * @param url The URL of the text file to be loaded as URL object. - * - * @return A set containing one entry per MLET tag in the m-let text file loaded. - * Each entry specifies either the ObjectInstance for the created MBean, or a throwable object - * (that is, an error or an exception) if the MBean could not be created. - * - * @exception ServiceNotFoundException One of the following errors has occurred: The m-let text file does - * not contain an MLET tag, the m-let text file is not found, a mandatory - * attribute of the MLET tag is not specified, the value of url is - * null. - * @exception IllegalStateException MLet MBean is not registered with an MBeanServer. - */ - public Set getMBeansFromURL(URL url) - throws ServiceNotFoundException { - if (url == null) { - throw new ServiceNotFoundException("The specified URL is null"); - } - return getMBeansFromURL(url.toString()); - } - - /** - * Loads a text file containing MLET tags that define the MBeans to - * be added to the MBean server. The location of the text file is specified by - * a URL. The MBeans specified in the MLET file will be instantiated and - * registered in the MBean server. - * - * @param url The URL of the text file to be loaded as String object. - * - * @return A set containing one entry per MLET tag in the m-let - * text file loaded. Each entry specifies either the - * ObjectInstance for the created MBean, or a throwable object - * (that is, an error or an exception) if the MBean could not be - * created. - * - * @exception ServiceNotFoundException One of the following - * errors has occurred: The m-let text file does not contain an - * MLET tag, the m-let text file is not found, a mandatory - * attribute of the MLET tag is not specified, the url is - * malformed. - * @exception IllegalStateException MLet MBean is not registered - * with an MBeanServer. - * - */ - public Set getMBeansFromURL(String url) - throws ServiceNotFoundException { - - if (server == null) { - throw new IllegalStateException("This MLet MBean is not " + - "registered with an MBeanServer."); - } - // Parse arguments - if (url == null) { - MLET_LOGGER.log(Level.TRACE, "URL is null"); - throw new ServiceNotFoundException("The specified URL is null"); - } else { - url = url.replace(File.separatorChar,'/'); - } - if (MLET_LOGGER.isLoggable(Level.TRACE)) { - MLET_LOGGER.log(Level.TRACE, ""); - } - - // Parse URL - try { - MLetParser parser = new MLetParser(); - mletList = parser.parseURL(url); - } catch (Exception e) { - final String msg = - "Problems while parsing URL [" + url + - "], got exception [" + e.toString() + "]"; - MLET_LOGGER.log(Level.TRACE, msg); - throw EnvHelp.initCause(new ServiceNotFoundException(msg), e); - } - - // Check that the list of MLets is not empty - if (mletList.size() == 0) { - final String msg = - "File " + url + " not found or MLET tag not defined in file"; - MLET_LOGGER.log(Level.TRACE, msg); - throw new ServiceNotFoundException(msg); - } - - // Walk through the list of MLets - Set mbeans = new HashSet<>(); - for (MLetContent elmt : mletList) { - // Initialize local variables - String code = elmt.getCode(); - if (code != null) { - if (code.endsWith(".class")) { - code = code.substring(0, code.length() - 6); - } - } - String name = elmt.getName(); - URL codebase = elmt.getCodeBase(); - String version = elmt.getVersion(); - String serName = elmt.getSerializedObject(); - String jarFiles = elmt.getJarFiles(); - URL documentBase = elmt.getDocumentBase(); - - // Display debug information - if (MLET_LOGGER.isLoggable(Level.TRACE)) { - final StringBuilder strb = new StringBuilder() - .append("\n\tMLET TAG = ").append(elmt.getAttributes()) - .append("\n\tCODEBASE = ").append(codebase) - .append("\n\tARCHIVE = ").append(jarFiles) - .append("\n\tCODE = ").append(code) - .append("\n\tOBJECT = ").append(serName) - .append("\n\tNAME = ").append(name) - .append("\n\tVERSION = ").append(version) - .append("\n\tDOCUMENT URL = ").append(documentBase); - MLET_LOGGER.log(Level.TRACE, strb::toString); - } - - // Load classes from JAR files - StringTokenizer st = new StringTokenizer(jarFiles, ",", false); - while (st.hasMoreTokens()) { - String tok = st.nextToken().trim(); - if (MLET_LOGGER.isLoggable(Level.TRACE)) { - MLET_LOGGER.log(Level.TRACE, - "Load archive for codebase <" + codebase + - ">, file <" + tok + ">"); - } - // Check which is the codebase to be used for loading the jar file. - // If we are using the base MLet implementation then it will be - // always the remote server but if the service has been extended in - // order to support caching and versioning then this method will - // return the appropriate one. - // - try { - codebase = check(version, codebase, tok, elmt); - } catch (Exception ex) { - MLET_LOGGER.log(Level.DEBUG, - "Got unexpected exception", ex); - mbeans.add(ex); - continue; - } - - // Appends the specified JAR file URL to the list of - // URLs to search for classes and resources. - try { - @SuppressWarnings("deprecation") - var u = new URL(codebase.toString() + tok); - if (!Arrays.asList(getURLs()) - .contains(u)) { - addURL(codebase + tok); - } - } catch (MalformedURLException me) { - // OK : Ignore jar file if its name provokes the - // URL to be an invalid one. - } - - } - // Instantiate the class specified in the - // CODE or OBJECT section of the MLet tag - // - Object o; - ObjectInstance objInst; - - if (code != null && serName != null) { - final String msg = - "CODE and OBJECT parameters cannot be specified at the " + - "same time in tag MLET"; - MLET_LOGGER.log(Level.TRACE, msg); - mbeans.add(new Error(msg)); - continue; - } - if (code == null && serName == null) { - final String msg = - "Either CODE or OBJECT parameter must be specified in " + - "tag MLET"; - MLET_LOGGER.log(Level.TRACE, msg); - mbeans.add(new Error(msg)); - continue; - } - try { - if (code != null) { - - List signat = elmt.getParameterTypes(); - List stringPars = elmt.getParameterValues(); - List objectPars = new ArrayList<>(); - - for (int i = 0; i < signat.size(); i++) { - objectPars.add(constructParameter(stringPars.get(i), - signat.get(i))); - } - if (signat.isEmpty()) { - if (name == null) { - objInst = server.createMBean(code, null, - mletObjectName); - } else { - objInst = server.createMBean(code, - new ObjectName(name), - mletObjectName); - } - } else { - Object[] parms = objectPars.toArray(); - String[] signature = new String[signat.size()]; - signat.toArray(signature); - if (MLET_LOGGER.isLoggable(Level.TRACE)) { - final StringBuilder strb = new StringBuilder(); - for (int i = 0; i < signature.length; i++) { - strb.append("\n\tSignature = ") - .append(signature[i]) - .append("\t\nParams = ") - .append(parms[i]); - } - MLET_LOGGER.log(Level.TRACE, strb::toString); - } - if (name == null) { - objInst = - server.createMBean(code, null, mletObjectName, - parms, signature); - } else { - objInst = - server.createMBean(code, new ObjectName(name), - mletObjectName, parms, - signature); - } - } - } else { - o = loadSerializedObject(codebase,serName); - if (name == null) { - server.registerMBean(o, null); - } else { - server.registerMBean(o, new ObjectName(name)); - } - objInst = new ObjectInstance(name, o.getClass().getName()); - } - } catch (ReflectionException ex) { - MLET_LOGGER.log(Level.TRACE, "ReflectionException", ex); - mbeans.add(ex); - continue; - } catch (InstanceAlreadyExistsException ex) { - MLET_LOGGER.log(Level.TRACE, - "InstanceAlreadyExistsException", ex); - mbeans.add(ex); - continue; - } catch (MBeanRegistrationException ex) { - MLET_LOGGER.log(Level.TRACE, "MBeanRegistrationException", ex); - mbeans.add(ex); - continue; - } catch (MBeanException ex) { - MLET_LOGGER.log(Level.TRACE, "MBeanException", ex); - mbeans.add(ex); - continue; - } catch (NotCompliantMBeanException ex) { - MLET_LOGGER.log(Level.TRACE, - "NotCompliantMBeanException", ex); - mbeans.add(ex); - continue; - } catch (InstanceNotFoundException ex) { - MLET_LOGGER.log(Level.TRACE, - "InstanceNotFoundException", ex); - mbeans.add(ex); - continue; - } catch (IOException ex) { - MLET_LOGGER.log(Level.TRACE, "IOException", ex); - mbeans.add(ex); - continue; - } catch (SecurityException ex) { - MLET_LOGGER.log(Level.TRACE, "SecurityException", ex); - mbeans.add(ex); - continue; - } catch (Exception ex) { - MLET_LOGGER.log(Level.TRACE, "Exception", ex); - mbeans.add(ex); - continue; - } catch (Error ex) { - MLET_LOGGER.log(Level.TRACE, "Error", ex); - mbeans.add(ex); - continue; - } - mbeans.add(objInst); - } - return mbeans; - } - - /** - * Gets the current directory used by the library loader for - * storing native libraries before they are loaded into memory. - * - * @return The current directory used by the library loader. - * - * @see #setLibraryDirectory - * - * @throws UnsupportedOperationException if this implementation - * does not support storing native libraries in this way. - */ - public synchronized String getLibraryDirectory() { - return libraryDirectory; - } - - /** - * Sets the directory used by the library loader for storing - * native libraries before they are loaded into memory. - * - * @param libdir The directory used by the library loader. - * - * @see #getLibraryDirectory - * - * @throws UnsupportedOperationException if this implementation - * does not support storing native libraries in this way. - */ - public synchronized void setLibraryDirectory(String libdir) { - libraryDirectory = libdir; - } - - /** - * Allows the m-let to perform any operations it needs before - * being registered in the MBean server. If the ObjectName is - * null, the m-let provides a default name for its registration - * <defaultDomain>:type=MLet - * - * @param server The MBean server in which the m-let will be registered. - * @param name The object name of the m-let. - * - * @return The name of the m-let registered. - * - * @exception java.lang.Exception This exception should be caught by the MBean server and re-thrown - *as an MBeanRegistrationException. - */ - public ObjectName preRegister(MBeanServer server, ObjectName name) - throws Exception { - - // Initialize local pointer to the MBean server - setMBeanServer(server); - - // If no name is specified return a default name for the MLet - if (name == null) { - name = new ObjectName(server.getDefaultDomain() + ":" + ServiceName.MLET); - } - - this.mletObjectName = name; - return this.mletObjectName; - } - - /** - * Allows the m-let to perform any operations needed after having been - * registered in the MBean server or after the registration has failed. - * - * @param registrationDone Indicates whether or not the m-let has - * been successfully registered in the MBean server. The value - * false means that either the registration phase has failed. - * - */ - public void postRegister (Boolean registrationDone) { - } - - /** - * Allows the m-let to perform any operations it needs before being unregistered - * by the MBean server. - * - * @exception java.lang.Exception This exception should be caught - * by the MBean server and re-thrown as an - * MBeanRegistrationException. - */ - public void preDeregister() throws java.lang.Exception { - } - - - /** - * Allows the m-let to perform any operations needed after having been - * unregistered in the MBean server. - */ - public void postDeregister() { - } - - /** - *

Save this MLet's contents to the given {@link ObjectOutput}. - * Not all implementations support this method. Those that do not - * throw {@link UnsupportedOperationException}. A subclass may - * override this method to support it or to change the format of - * the written data.

- * - *

The format of the written data is not specified, but if - * an implementation supports {@link #writeExternal} it must - * also support {@link #readExternal} in such a way that what is - * written by the former can be read by the latter.

- * - * @param out The object output stream to write to. - * - * @exception IOException If a problem occurred while writing. - * @exception UnsupportedOperationException If this - * implementation does not support this operation. - */ - public void writeExternal(ObjectOutput out) - throws IOException, UnsupportedOperationException { - throw new UnsupportedOperationException("MLet.writeExternal"); - } - - /** - *

Restore this MLet's contents from the given {@link ObjectInput}. - * Not all implementations support this method. Those that do not - * throw {@link UnsupportedOperationException}. A subclass may - * override this method to support it or to change the format of - * the read data.

- * - *

The format of the read data is not specified, but if an - * implementation supports {@link #readExternal} it must also - * support {@link #writeExternal} in such a way that what is - * written by the latter can be read by the former.

- * - * @param in The object input stream to read from. - * - * @exception IOException if a problem occurred while reading. - * @exception ClassNotFoundException if the class for the object - * being restored cannot be found. - * @exception UnsupportedOperationException if this - * implementation does not support this operation. - */ - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException, - UnsupportedOperationException { - throw new UnsupportedOperationException("MLet.readExternal"); - } - - /* - * ------------------------------------------ - * PACKAGE METHODS - * ------------------------------------------ - */ - - /** - *

Load a class, using the given {@link ClassLoaderRepository} if - * the class is not found in this MLet's URLs. The given - * ClassLoaderRepository can be null, in which case a {@link - * ClassNotFoundException} occurs immediately if the class is not - * found in this MLet's URLs.

- * - * @param name The name of the class we want to load. - * @param clr The ClassLoaderRepository that will be used to search - * for the given class, if it is not found in this - * ClassLoader. May be null. - * @return The resulting Class object. - * @exception ClassNotFoundException The specified class could not be - * found in this ClassLoader nor in the given - * ClassLoaderRepository. - * - */ - public synchronized Class loadClass(String name, - ClassLoaderRepository clr) - throws ClassNotFoundException { - final ClassLoaderRepository before=currentClr; - try { - currentClr = clr; - return loadClass(name); - } finally { - currentClr = before; - } - } - - /* - * ------------------------------------------ - * PROTECTED METHODS - * ------------------------------------------ - */ - - /** - * This is the main method for class loaders that is being redefined. - * - * @param name The name of the class. - * - * @return The resulting Class object. - * - * @exception ClassNotFoundException The specified class could not be - * found. - */ - protected Class findClass(String name) throws ClassNotFoundException { - /* currentClr is context sensitive - used to avoid recursion - in the class loader repository. (This is no longer - necessary with the new CLR semantics but is kept for - compatibility with code that might have called the - two-parameter loadClass explicitly.) */ - return findClass(name, currentClr); - } - - /** - * Called by {@link MLet#findClass(java.lang.String)}. - * - * @param name The name of the class that we want to load/find. - * @param clr The ClassLoaderRepository that can be used to search - * for the given class. This parameter is - * null when called from within the - * {@link javax.management.MBeanServerFactory#getClassLoaderRepository(javax.management.MBeanServer) Class Loader Repository}. - * @exception ClassNotFoundException The specified class could not be - * found. - * - **/ - Class findClass(String name, ClassLoaderRepository clr) - throws ClassNotFoundException { - Class c = null; - MLET_LOGGER.log(Level.TRACE, name); - // Try looking in the JAR: - try { - c = super.findClass(name); - if (MLET_LOGGER.isLoggable(Level.TRACE)) { - MLET_LOGGER.log(Level.TRACE, - "Class " + name + " loaded through MLet classloader"); - } - } catch (ClassNotFoundException e) { - // Drop through - if (MLET_LOGGER.isLoggable(Level.TRACE)) { - MLET_LOGGER.log(Level.TRACE, - "Class " + name + " not found locally"); - } - } - // if we are not called from the ClassLoaderRepository - if (c == null && delegateToCLR && clr != null) { - // Try the classloader repository: - // - try { - if (MLET_LOGGER.isLoggable(Level.TRACE)) { - MLET_LOGGER.log(Level.TRACE, - "Class " + name + " : looking in CLR"); - } - c = clr.loadClassBefore(this, name); - // The loadClassBefore method never returns null. - // If the class is not found we get an exception. - if (MLET_LOGGER.isLoggable(Level.TRACE)) { - MLET_LOGGER.log(Level.TRACE, - "Class " + name + " loaded through " + - "the default classloader repository"); - } - } catch (ClassNotFoundException e) { - // Drop through - if (MLET_LOGGER.isLoggable(Level.TRACE)) { - MLET_LOGGER.log(Level.TRACE, - "Class " + name + " not found in CLR"); - } - } - } - if (c == null) { - MLET_LOGGER.log(Level.TRACE, "Failed to load class " + name); - throw new ClassNotFoundException(name); - } - return c; - } - - /** - * Returns the absolute path name of a native library. The VM - * invokes this method to locate the native libraries that belong - * to classes loaded with this class loader. Libraries are - * searched in the JAR files using first just the native library - * name and if not found the native library name together with - * the architecture-specific path name - * (OSName/OSArch/OSVersion/lib/nativelibname), i.e. - *

- * the library stat on Solaris SPARC 5.7 will be searched in the JAR file as: - *

    - *
  1. libstat.so - *
  2. SunOS/sparc/5.7/lib/libstat.so - *
- * the library stat on Windows NT 4.0 will be searched in the JAR file as: - *
    - *
  1. stat.dll - *
  2. WindowsNT/x86/4.0/lib/stat.dll - *
- * - *

More specifically, let {@code nativelibname} be the result of - * {@link System#mapLibraryName(java.lang.String) - * System.mapLibraryName}{@code (libname)}. Then the following names are - * searched in the JAR files, in order:
- * {@code nativelibname}
- * {@code ///lib/}{@code nativelibname}
- * where {@code } means {@code System.getProperty(X)} with any - * spaces in the result removed, and {@code /} stands for the - * file separator character ({@link File#separator}). - *

- * If this method returns null, i.e. the libraries - * were not found in any of the JAR files loaded with this class - * loader, the VM searches the library along the path specified - * as the java.library.path property. - * - * @param libname The library name. - * - * @return The absolute path of the native library. - */ - protected String findLibrary(String libname) { - - String abs_path; - String mth = "findLibrary"; - - // Get the platform-specific string representing a native library. - // - String nativelibname = System.mapLibraryName(libname); - - // - // See if the native library is accessible as a resource through the JAR file. - // - if (MLET_LOGGER.isLoggable(Level.TRACE)) { - MLET_LOGGER.log(Level.TRACE, - "Search " + libname + " in all JAR files"); - } - - // First try to locate the library in the JAR file using only - // the native library name. e.g. if user requested a load - // for "foo" on Solaris SPARC 5.7 we try to load "libfoo.so" - // from the JAR file. - // - if (MLET_LOGGER.isLoggable(Level.TRACE)) { - MLET_LOGGER.log(Level.TRACE, - "loadLibraryAsResource(" + nativelibname + ")"); - } - abs_path = loadLibraryAsResource(nativelibname); - if (abs_path != null) { - if (MLET_LOGGER.isLoggable(Level.TRACE)) { - MLET_LOGGER.log(Level.TRACE, - nativelibname + " loaded, absolute path = " + abs_path); - } - return abs_path; - } - - // Next try to locate it using the native library name and - // the architecture-specific path name. e.g. if user - // requested a load for "foo" on Solaris SPARC 5.7 we try to - // load "SunOS/sparc/5.7/lib/libfoo.so" from the JAR file. - // - nativelibname = removeSpace(System.getProperty("os.name")) + File.separator + - removeSpace(System.getProperty("os.arch")) + File.separator + - removeSpace(System.getProperty("os.version")) + File.separator + - "lib" + File.separator + nativelibname; - if (MLET_LOGGER.isLoggable(Level.TRACE)) { - MLET_LOGGER.log(Level.TRACE, - "loadLibraryAsResource(" + nativelibname + ")"); - } - - abs_path = loadLibraryAsResource(nativelibname); - if (abs_path != null) { - if (MLET_LOGGER.isLoggable(Level.TRACE)) { - MLET_LOGGER.log(Level.TRACE, - nativelibname + " loaded, absolute path = " + abs_path); - } - return abs_path; - } - - // - // All paths exhausted, library not found in JAR file. - // - - if (MLET_LOGGER.isLoggable(Level.TRACE)) { - MLET_LOGGER.log(Level.TRACE, - libname + " not found in any JAR file"); - MLET_LOGGER.log(Level.TRACE, - "Search " + libname + " along the path " + - "specified as the java.library.path property"); - } - - // Let the VM search the library along the path - // specified as the java.library.path property. - // - return null; - } - - - /* - * ------------------------------------------ - * PRIVATE METHODS - * ------------------------------------------ - */ - - private String getTmpDir() { - // JDK 1.4 - String tmpDir = System.getProperty("java.io.tmpdir"); - if (tmpDir != null) return tmpDir; - - // JDK < 1.4 - File tmpFile = null; - try { - // Try to guess the system temporary dir... - tmpFile = File.createTempFile("tmp","jmx"); - if (tmpFile == null) return null; - final File tmpDirFile = tmpFile.getParentFile(); - if (tmpDirFile == null) return null; - return tmpDirFile.getAbsolutePath(); - } catch (Exception x) { - MLET_LOGGER.log(Level.DEBUG, - "Failed to determine system temporary dir"); - return null; - } finally { - // Cleanup ... - if (tmpFile!=null) { - try { - boolean deleted = tmpFile.delete(); - if (!deleted) { - MLET_LOGGER.log(Level.DEBUG, - "Failed to delete temp file"); - } - } catch (Exception x) { - MLET_LOGGER.log(Level.DEBUG, - "Failed to delete temporary file", x); - } - } - } - } - - /** - * Search the specified native library in any of the JAR files - * loaded by this classloader. If the library is found copy it - * into the library directory and return the absolute path. If - * the library is not found then return null. - */ - private synchronized String loadLibraryAsResource(String libname) { - try { - InputStream is = getResourceAsStream( - libname.replace(File.separatorChar,'/')); - if (is != null) { - try { - File directory = new File(libraryDirectory); - directory.mkdirs(); - File file = Files.createTempFile(directory.toPath(), - libname + ".", null) - .toFile(); - file.deleteOnExit(); - Files.copy(is, file.toPath(), StandardCopyOption.REPLACE_EXISTING); - return file.getAbsolutePath(); - } finally { - is.close(); - } - } - } catch (Exception e) { - MLET_LOGGER.log(Level.DEBUG, - "Failed to load library : " + libname, e); - return null; - } - return null; - } - - /** - * Removes any white space from a string. This is used to - * convert strings such as "Windows NT" to "WindowsNT". - */ - private static String removeSpace(String s) { - return s.trim().replace(" ", ""); - } - - /** - *

This method is to be overridden when extending this service to - * support caching and versioning. It is called from {@link - * #getMBeansFromURL getMBeansFromURL} when the version, - * codebase, and jarfile have been extracted from the MLet file, - * and can be used to verify that it is all right to load the - * given MBean, or to replace the given URL with a different one.

- * - *

The default implementation of this method returns - * codebase unchanged.

- * - * @param version The version number of the .jar - * file stored locally. - * @param codebase The base URL of the remote .jar file. - * @param jarfile The name of the .jar file to be loaded. - * @param mlet The MLetContent instance that - * represents the MLET tag. - * - * @return the codebase to use for the loaded MBean. The returned - * value should not be null. - * - * @exception Exception if the MBean is not to be loaded for some - * reason. The exception will be added to the set returned by - * {@link #getMBeansFromURL getMBeansFromURL}. - * - */ - protected URL check(String version, URL codebase, String jarfile, - MLetContent mlet) - throws Exception { - return codebase; - } - - /** - * Loads the serialized object specified by the OBJECT - * attribute of the MLET tag. - * - * @param codebase The codebase. - * @param filename The name of the file containing the serialized object. - * @return The serialized object. - * @exception ClassNotFoundException The specified serialized - * object could not be found. - * @exception IOException An I/O error occurred while loading - * serialized object. - */ - private Object loadSerializedObject(URL codebase, String filename) - throws IOException, ClassNotFoundException { - if (filename != null) { - filename = filename.replace(File.separatorChar,'/'); - } - if (MLET_LOGGER.isLoggable(Level.TRACE)) { - MLET_LOGGER.log(Level.TRACE, codebase.toString() + filename); - } - InputStream is = getResourceAsStream(filename); - if (is != null) { - try { - ObjectInputStream ois = new MLetObjectInputStream(is, this); - Object serObject = ois.readObject(); - ois.close(); - return serObject; - } catch (IOException | ClassNotFoundException e) { - if (MLET_LOGGER.isLoggable(Level.DEBUG)) { - MLET_LOGGER.log(Level.DEBUG, - "Exception while deserializing " + filename, e); - } - throw e; - } - } else { - if (MLET_LOGGER.isLoggable(Level.DEBUG)) { - MLET_LOGGER.log(Level.DEBUG, "Error: File " + filename + - " containing serialized object not found"); - } - throw new Error("File " + filename + " containing serialized object not found"); - } - } - - /** - * Converts the String value of the constructor's parameter to - * a basic Java object with the type of the parameter. - */ - private Object constructParameter(String param, String type) { - // check if it is a primitive type - Class c = primitiveClasses.get(type); - if (c != null) { - try { - Constructor cons = - c.getConstructor(String.class); - Object[] oo = new Object[1]; - oo[0]=param; - return(cons.newInstance(oo)); - - } catch (Exception e) { - MLET_LOGGER.log(Level.DEBUG, "Got unexpected exception", e); - } - } - return switch (type) { - case "java.lang.Boolean" -> Boolean.valueOf(param); - case "java.lang.Byte" -> Byte.valueOf(param); - case "java.lang.Short" -> Short.valueOf(param); - case "java.lang.Long" -> Long.valueOf(param); - case "java.lang.Integer" -> Integer.valueOf(param); - case "java.lang.Float" -> Float.valueOf(param); - case "java.lang.Double" -> Double.valueOf(param); - default -> param; - }; - } - - @SuppressWarnings("removal") - private synchronized void setMBeanServer(final MBeanServer server) { - this.server = server; - PrivilegedAction act = - new PrivilegedAction<>() { - public ClassLoaderRepository run() { - return server.getClassLoaderRepository(); - } - }; - currentClr = AccessController.doPrivileged(act); - } - -} diff --git a/src/java.management/share/classes/javax/management/loading/MLetContent.java b/src/java.management/share/classes/javax/management/loading/MLetContent.java deleted file mode 100644 index 638f7b38c21..00000000000 --- a/src/java.management/share/classes/javax/management/loading/MLetContent.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javax.management.loading; - - -// java import - -import java.net.URL; -import java.net.MalformedURLException; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * This class represents the contents of the MLET tag. - * It can be consulted by a subclass of {@link MLet} that overrides - * the {@link MLet#check MLet.check} method. - * - * @deprecated This API is part of Management Applets (m-lets), which is a legacy feature that allows loading - * of remote MBeans. This feature is not usable without a Security Manager, which is deprecated and subject to - * removal in a future release. Consequently, this API is also deprecated and subject to removal. There is no replacement. - * - * @since 1.6 - */ -@Deprecated(since="20", forRemoval=true) -public class MLetContent { - - /** - * A map of the attributes of the MLET tag - * and their values. - */ - private Map attributes; - - /** - * An ordered list of the TYPE attributes that appeared in nested - * <PARAM> tags. - */ - private List types; - - /** - * An ordered list of the VALUE attributes that appeared in nested - * <PARAM> tags. - */ - private List values; - - /** - * The MLet text file's base URL. - */ - private URL documentURL; - /** - * The base URL. - */ - private URL baseURL; - - - /** - * Creates an MLet instance initialized with attributes read - * from an MLET tag in an MLet text file. - * - * @param url The URL of the MLet text file containing the - * MLET tag. - * @param attributes A map of the attributes of the MLET tag. - * The keys in this map are the attribute names in lowercase, for - * example codebase. The values are the associated attribute - * values. - * @param types A list of the TYPE attributes that appeared in nested - * <PARAM> tags. - * @param values A list of the VALUE attributes that appeared in nested - * <PARAM> tags. - */ - public MLetContent(URL url, Map attributes, - List types, List values) { - this.documentURL = url; - this.attributes = Collections.unmodifiableMap(attributes); - this.types = Collections.unmodifiableList(types); - this.values = Collections.unmodifiableList(values); - - // Initialize baseURL - // - String att = getParameter("codebase"); - if (att != null) { - if (!att.endsWith("/")) { - att += "/"; - } - try { - @SuppressWarnings("deprecation") - var _unused = baseURL = new URL(documentURL, att); - } catch (MalformedURLException e) { - // OK : Move to next block as baseURL could not be initialized. - } - } - if (baseURL == null) { - String file = documentURL.getFile(); - int i = file.lastIndexOf('/'); - if (i >= 0 && i < file.length() - 1) { - try { - @SuppressWarnings("deprecation") - var _unused = baseURL = new URL(documentURL, file.substring(0, i + 1)); - } catch (MalformedURLException e) { - // OK : Move to next block as baseURL could not be initialized. - } - } - } - if (baseURL == null) - baseURL = documentURL; - - } - - // GETTERS AND SETTERS - //-------------------- - - /** - * Gets the attributes of the MLET tag. The keys in - * the returned map are the attribute names in lowercase, for - * example codebase. The values are the associated - * attribute values. - * @return A map of the attributes of the MLET tag - * and their values. - */ - public Map getAttributes() { - return attributes; - } - - /** - * Gets the MLet text file's base URL. - * @return The MLet text file's base URL. - */ - public URL getDocumentBase() { - return documentURL; - } - - /** - * Gets the code base URL. - * @return The code base URL. - */ - public URL getCodeBase() { - return baseURL; - } - - /** - * Gets the list of .jar files specified by the ARCHIVE - * attribute of the MLET tag. - * @return A comma-separated list of .jar file names. - */ - public String getJarFiles() { - return getParameter("archive"); - } - - /** - * Gets the value of the CODE - * attribute of the MLET tag. - * @return The value of the CODE - * attribute of the MLET tag. - */ - public String getCode() { - return getParameter("code"); - } - - /** - * Gets the value of the OBJECT - * attribute of the MLET tag. - * @return The value of the OBJECT - * attribute of the MLET tag. - */ - public String getSerializedObject() { - return getParameter("object"); - } - - /** - * Gets the value of the NAME - * attribute of the MLET tag. - * @return The value of the NAME - * attribute of the MLET tag. - */ - public String getName() { - return getParameter("name"); - } - - - /** - * Gets the value of the VERSION - * attribute of the MLET tag. - * @return The value of the VERSION - * attribute of the MLET tag. - */ - public String getVersion() { - return getParameter("version"); - } - - /** - * Gets the list of values of the TYPE attribute in - * each nested <PARAM> tag within the MLET - * tag. - * @return the list of types. - */ - public List getParameterTypes() { - return types; - } - - /** - * Gets the list of values of the VALUE attribute in - * each nested <PARAM> tag within the MLET - * tag. - * @return the list of values. - */ - public List getParameterValues() { - return values; - } - - /** - * Gets the value of the specified - * attribute of the MLET tag. - * - * @param name A string representing the name of the attribute. - * @return The value of the specified - * attribute of the MLET tag. - */ - private String getParameter(String name) { - return attributes.get(name.toLowerCase()); - } - -} diff --git a/src/java.management/share/classes/javax/management/loading/MLetMBean.java b/src/java.management/share/classes/javax/management/loading/MLetMBean.java deleted file mode 100644 index 1e57cef9be7..00000000000 --- a/src/java.management/share/classes/javax/management/loading/MLetMBean.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javax.management.loading; - -import java.net.URL; -import java.io.InputStream; -import java.io.IOException; -import java.util.Set; -import java.util.Enumeration; - -import javax.management.*; - - - -/** - * Exposes the remote management interface of the MLet - * MBean. - * - * @deprecated This API is part of Management Applets (m-lets), which is a legacy feature that allows loading - * of remote MBeans. This feature is not usable without a Security Manager, which is deprecated and subject to - * removal in a future release. Consequently, this API is also deprecated and subject to removal. There is no replacement. - * - * @since 1.5 - */ -@Deprecated(since="20", forRemoval=true) -public interface MLetMBean { - - /** - * Loads a text file containing MLET tags that define the MBeans - * to be added to the MBean server. The location of the text file is - * specified by a URL. The text file is read using the UTF-8 - * encoding. The MBeans specified in the MLET file will be - * instantiated and registered in the MBean server. - * - * @param url The URL of the text file to be loaded as String object. - * - * @return A set containing one entry per MLET tag in the m-let - * text file loaded. Each entry specifies either the - * ObjectInstance for the created MBean, or a throwable object - * (that is, an error or an exception) if the MBean could not be - * created. - * - * @exception ServiceNotFoundException One of the following errors - * has occurred: The m-let text file does not contain an MLET tag, - * the m-let text file is not found, a mandatory attribute of the - * MLET tag is not specified, the value of url is malformed. - */ - public Set getMBeansFromURL(String url) - throws ServiceNotFoundException; - - /** - * Loads a text file containing MLET tags that define the MBeans - * to be added to the MBean server. The location of the text file is - * specified by a URL. The text file is read using the UTF-8 - * encoding. The MBeans specified in the MLET file will be - * instantiated and registered in the MBean server. - * - * @param url The URL of the text file to be loaded as URL object. - * - * @return A set containing one entry per MLET tag in the m-let - * text file loaded. Each entry specifies either the - * ObjectInstance for the created MBean, or a throwable object - * (that is, an error or an exception) if the MBean could not be - * created. - * - * @exception ServiceNotFoundException One of the following errors - * has occurred: The m-let text file does not contain an MLET tag, - * the m-let text file is not found, a mandatory attribute of the - * MLET tag is not specified, the value of url is null. - */ - public Set getMBeansFromURL(URL url) - throws ServiceNotFoundException; - - /** - * Appends the specified URL to the list of URLs to search for classes and - * resources. - * - * @param url the URL to add. - */ - public void addURL(URL url) ; - - /** - * Appends the specified URL to the list of URLs to search for classes and - * resources. - * - * @param url the URL to add. - * - * @exception ServiceNotFoundException The specified URL is malformed. - */ - public void addURL(String url) throws ServiceNotFoundException; - - /** - * Returns the search path of URLs for loading classes and resources. - * This includes the original list of URLs specified to the constructor, - * along with any URLs subsequently appended by the addURL() method. - * - * @return the list of URLs. - */ - public URL[] getURLs(); - - /** Finds the resource with the given name. - * A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is - * independent of the location of the code. - * The name of a resource is a "/"-separated path name that identifies the resource. - * - * @param name The resource name - * - * @return An URL for reading the resource, or null if the resource could not be found or the caller doesn't have adequate privileges to get the - * resource. - */ - public URL getResource(String name); - - /** Returns an input stream for reading the specified resource. The search order is described in the documentation for - * getResource(String). - * - * @param name The resource name - * - * @return An input stream for reading the resource, or null if the resource could not be found - * - */ - public InputStream getResourceAsStream(String name); - - /** - * Finds all the resources with the given name. A resource is some - * data (images, audio, text, etc) that can be accessed by class - * code in a way that is independent of the location of the code. - * The name of a resource is a "/"-separated path name that - * identifies the resource. - * - * @param name The resource name. - * - * @return An enumeration of URL to the resource. If no resources - * could be found, the enumeration will be empty. Resources that - * cannot be accessed will not be in the enumeration. - * - * @exception IOException if an I/O exception occurs when - * searching for resources. - */ - public Enumeration getResources(String name) throws IOException; - - /** - * Gets the current directory used by the library loader for - * storing native libraries before they are loaded into memory. - * - * @return The current directory used by the library loader. - * - * @see #setLibraryDirectory - * - * @throws UnsupportedOperationException if this implementation - * does not support storing native libraries in this way. - */ - public String getLibraryDirectory(); - - /** - * Sets the directory used by the library loader for storing - * native libraries before they are loaded into memory. - * - * @param libdir The directory used by the library loader. - * - * @see #getLibraryDirectory - * - * @throws UnsupportedOperationException if this implementation - * does not support storing native libraries in this way. - */ - public void setLibraryDirectory(String libdir); - - } diff --git a/src/java.management/share/classes/javax/management/loading/MLetObjectInputStream.java b/src/java.management/share/classes/javax/management/loading/MLetObjectInputStream.java deleted file mode 100644 index 159fa85b22e..00000000000 --- a/src/java.management/share/classes/javax/management/loading/MLetObjectInputStream.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javax.management.loading; - - -// java import - -import java.io.*; -import java.lang.reflect.Array; - - -/** - * This subclass of ObjectInputStream delegates loading of classes to - * an existing MLetClassLoader. - * - * @since 1.5 - */ -@Deprecated(since="20", forRemoval=true) -class MLetObjectInputStream extends ObjectInputStream { - - @SuppressWarnings("removal") - private MLet loader; - - /** - * Loader must be non-null; - */ - @SuppressWarnings("removal") - public MLetObjectInputStream(InputStream in, MLet loader) - throws IOException, StreamCorruptedException { - - super(in); - if (loader == null) { - throw new IllegalArgumentException("Illegal null argument to MLetObjectInputStream"); - } - this.loader = loader; - } - - private Class primitiveType(char c) { - switch(c) { - case 'B': - return Byte.TYPE; - - case 'C': - return Character.TYPE; - - case 'D': - return Double.TYPE; - - case 'F': - return Float.TYPE; - - case 'I': - return Integer.TYPE; - - case 'J': - return Long.TYPE; - - case 'S': - return Short.TYPE; - - case 'Z': - return Boolean.TYPE; - } - return null; - } - - /** - * Use the given ClassLoader rather than using the system class - */ - @Override - protected Class resolveClass(ObjectStreamClass objectstreamclass) - throws IOException, ClassNotFoundException { - - String s = objectstreamclass.getName(); - if (s.startsWith("[")) { - int i; - for (i = 1; s.charAt(i) == '['; i++); - Class class1; - if (s.charAt(i) == 'L') { - class1 = loader.loadClass(s.substring(i + 1, s.length() - 1)); - } else { - if (s.length() != i + 1) - throw new ClassNotFoundException(s); - class1 = primitiveType(s.charAt(i)); - } - int ai[] = new int[i]; - for (int j = 0; j < i; j++) - ai[j] = 0; - - return Array.newInstance(class1, ai).getClass(); - } else { - return loader.loadClass(s); - } - } - - /** - * Returns the ClassLoader being used - */ - public ClassLoader getClassLoader() { - return loader; - } -} diff --git a/src/java.management/share/classes/javax/management/loading/MLetParser.java b/src/java.management/share/classes/javax/management/loading/MLetParser.java deleted file mode 100644 index 41bb9d35878..00000000000 --- a/src/java.management/share/classes/javax/management/loading/MLetParser.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javax.management.loading; - -import static com.sun.jmx.defaults.JmxProperties.MLET_LOGGER; -import static java.nio.charset.StandardCharsets.UTF_8; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.lang.System.Logger.Level; - -/** - * This class is used for parsing URLs. - * - * @since 1.5 - */ -@Deprecated(since="20", forRemoval=true) -class MLetParser { - -/* - * ------------------------------------------ - * PRIVATE VARIABLES - * ------------------------------------------ - */ - - /** - * The current character - */ - private int c; - - /** - * Tag to parse. - */ - private static String tag = "mlet"; - - - /* - * ------------------------------------------ - * CONSTRUCTORS - * ------------------------------------------ - */ - - /** - * Create an MLet parser object - */ - public MLetParser() { - } - - /* - * ------------------------------------------ - * PUBLIC METHODS - * ------------------------------------------ - */ - - /** - * Scan spaces. - */ - public void skipSpace(Reader in) throws IOException { - while ((c >= 0) && ((c == ' ') || (c == '\t') || (c == '\n') || (c == '\r'))) { - c = in.read(); - } - } - - /** - * Scan identifier - */ - public String scanIdentifier(Reader in) throws IOException { - StringBuilder buf = new StringBuilder(); - while (true) { - if (((c >= 'a') && (c <= 'z')) || - ((c >= 'A') && (c <= 'Z')) || - ((c >= '0') && (c <= '9')) || (c == '_')) { - buf.append((char)c); - c = in.read(); - } else { - return buf.toString(); - } - } - } - - /** - * Scan tag - */ - public Map scanTag(Reader in) throws IOException { - Map atts = new HashMap<>(); - skipSpace(in); - while (c >= 0 && c != '>') { - if (c == '<') - throw new IOException("Missing '>' in tag"); - String att = scanIdentifier(in); - String val = ""; - skipSpace(in); - if (c == '=') { - int quote = -1; - c = in.read(); - skipSpace(in); - if ((c == '\'') || (c == '\"')) { - quote = c; - c = in.read(); - } - StringBuilder buf = new StringBuilder(); - while ((c > 0) && - (((quote < 0) && (c != ' ') && (c != '\t') && - (c != '\n') && (c != '\r') && (c != '>')) - || ((quote >= 0) && (c != quote)))) { - buf.append((char)c); - c = in.read(); - } - if (c == quote) { - c = in.read(); - } - skipSpace(in); - val = buf.toString(); - } - atts.put(att.toLowerCase(Locale.ENGLISH), val); - skipSpace(in); - } - return atts; - } - - /** - * Scan an html file for {@literal } tags. - */ - @SuppressWarnings("removal") - public List parse(URL url) throws IOException { - // Warning Messages - String requiresTypeWarning = " tag requires type parameter."; - String requiresValueWarning = " tag requires value parameter."; - String paramOutsideWarning = " tag outside ... ."; - String requiresCodeWarning = " tag requires either code or object parameter."; - String requiresJarsWarning = " tag requires archive parameter."; - - URLConnection conn; - - conn = url.openConnection(); - Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), - UTF_8)); - - // The original URL may have been redirected - this - // sets it to whatever URL/codebase we ended up getting - // - url = conn.getURL(); - - List mlets = new ArrayList<>(); - Map atts = null; - - List types = new ArrayList<>(); - List values = new ArrayList<>(); - - // debug("parse","*** Parsing " + url ); - while(true) { - c = in.read(); - if (c == -1) - break; - if (c == '<') { - c = in.read(); - if (c == '/') { - c = in.read(); - String nm = scanIdentifier(in); - if (c != '>') - throw new IOException("Missing '>' in tag"); - if (nm.equalsIgnoreCase(tag)) { - if (atts != null) { - mlets.add(new MLetContent(url, atts, types, values)); - } - atts = null; - types = new ArrayList<>(); - values = new ArrayList<>(); - } - } else { - String nm = scanIdentifier(in); - if (nm.equalsIgnoreCase("arg")) { - Map t = scanTag(in); - String att = t.get("type"); - if (att == null) { - MLET_LOGGER.log(Level.TRACE, requiresTypeWarning); - throw new IOException(requiresTypeWarning); - } else { - if (atts != null) { - types.add(att); - } else { - MLET_LOGGER.log(Level.TRACE, paramOutsideWarning); - throw new IOException(paramOutsideWarning); - } - } - String val = t.get("value"); - if (val == null) { - MLET_LOGGER.log(Level.TRACE, requiresValueWarning); - throw new IOException(requiresValueWarning); - } else { - if (atts != null) { - values.add(val); - } else { - MLET_LOGGER.log(Level.TRACE, paramOutsideWarning); - throw new IOException(paramOutsideWarning); - } - } - } else { - if (nm.equalsIgnoreCase(tag)) { - atts = scanTag(in); - if (atts.get("code") == null && atts.get("object") == null) { - MLET_LOGGER.log(Level.TRACE, requiresCodeWarning); - throw new IOException(requiresCodeWarning); - } - if (atts.get("archive") == null) { - MLET_LOGGER.log(Level.TRACE, requiresJarsWarning); - throw new IOException(requiresJarsWarning); - } - } - } - } - } - } - in.close(); - return mlets; - } - - /** - * Parse the document pointed by the URL urlname - */ - @SuppressWarnings("removal") - public List parseURL(String urlname) throws IOException { - // Parse the document - // - URL url; - if (urlname.indexOf(':') <= 1) { - String userDir = System.getProperty("user.dir"); - String prot; - if (userDir.charAt(0) == '/' || - userDir.charAt(0) == File.separatorChar) { - prot = "file:"; - } else { - prot = "file:/"; - } - url = - new URL(prot + userDir.replace(File.separatorChar, '/') + "/"); - url = new URL(url, urlname); - } else { - url = new URL(urlname); - } - // Return list of parsed MLets - // - return parse(url); - } - -} diff --git a/src/java.management/share/classes/javax/management/loading/PrivateMLet.java b/src/java.management/share/classes/javax/management/loading/PrivateMLet.java deleted file mode 100644 index 372db255b72..00000000000 --- a/src/java.management/share/classes/javax/management/loading/PrivateMLet.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javax.management.loading; - -import java.net.URL; -import java.net.URLStreamHandlerFactory; - -/** - * An MLet that is not added to the {@link ClassLoaderRepository}. - * This class acts exactly like its parent class, {@link MLet}, with - * one exception. When a PrivateMLet is registered in an MBean - * server, it is not added to that MBean server's {@link - * ClassLoaderRepository}. This is true because this class implements - * the interface {@link PrivateClassLoader}. - * - * @deprecated This API is part of Management Applets (m-lets), which is a legacy feature that allows loading - * of remote MBeans. This feature is not usable without a Security Manager, which is deprecated and subject to - * removal in a future release. Consequently, this API is also deprecated and subject to removal. There is no replacement. - * - * @since 1.5 - */ -@Deprecated(since="20", forRemoval=true) -@SuppressWarnings({"serial", "removal"}) // Externalizable class w/o no-arg c'tor -public class PrivateMLet extends MLet implements PrivateClassLoader { - private static final long serialVersionUID = 2503458973393711979L; - - /** - * Constructs a new PrivateMLet for the specified URLs using the - * default delegation parent ClassLoader. The URLs will be - * searched in the order specified for classes and resources - * after first searching in the parent class loader. - * - * @param urls The URLs from which to load classes and resources. - * @param delegateToCLR True if, when a class is not found in - * either the parent ClassLoader or the URLs, the MLet should delegate - * to its containing MBeanServer's {@link ClassLoaderRepository}. - * - */ - public PrivateMLet(URL[] urls, boolean delegateToCLR) { - super(urls, delegateToCLR); - } - - /** - * Constructs a new PrivateMLet for the given URLs. The URLs will - * be searched in the order specified for classes and resources - * after first searching in the specified parent class loader. - * The parent argument will be used as the parent class loader - * for delegation. - * - * @param urls The URLs from which to load classes and resources. - * @param parent The parent class loader for delegation. - * @param delegateToCLR True if, when a class is not found in - * either the parent ClassLoader or the URLs, the MLet should delegate - * to its containing MBeanServer's {@link ClassLoaderRepository}. - * - */ - public PrivateMLet(URL[] urls, ClassLoader parent, boolean delegateToCLR) { - super(urls, parent, delegateToCLR); - } - - /** - * Constructs a new PrivateMLet for the specified URLs, parent - * class loader, and URLStreamHandlerFactory. The parent argument - * will be used as the parent class loader for delegation. The - * factory argument will be used as the stream handler factory to - * obtain protocol handlers when creating new URLs. - * - * @param urls The URLs from which to load classes and resources. - * @param parent The parent class loader for delegation. - * @param factory The URLStreamHandlerFactory to use when creating URLs. - * @param delegateToCLR True if, when a class is not found in - * either the parent ClassLoader or the URLs, the MLet should delegate - * to its containing MBeanServer's {@link ClassLoaderRepository}. - * - */ - public PrivateMLet(URL[] urls, - ClassLoader parent, - URLStreamHandlerFactory factory, - boolean delegateToCLR) { - super(urls, parent, factory, delegateToCLR); - } -} diff --git a/src/java.management/share/classes/javax/management/loading/package.html b/src/java.management/share/classes/javax/management/loading/package.html index e9d4909d69d..0174f574ab4 100644 --- a/src/java.management/share/classes/javax/management/loading/package.html +++ b/src/java.management/share/classes/javax/management/loading/package.html @@ -2,7 +2,7 @@ javax.management.loading package