src/java.rmi/share/classes/java/rmi/server/RMIClassLoaderSpi.java
author rriggs
Wed, 02 Oct 2019 13:57:03 -0400
changeset 58446 5c83830390ba
parent 47216 71c04702a3d5
permissions -rw-r--r--
8231663: Incorrect GPL header in some RMI/SQL package-info.java files Reviewed-by: bpb, iris, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2006, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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 java.rmi.server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <code>RMIClassLoaderSpi</code> is the service provider interface for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <code>RMIClassLoader</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * In particular, an <code>RMIClassLoaderSpi</code> instance provides an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * implementation of the following static methods of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <code>RMIClassLoader</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <li>{@link RMIClassLoader#loadClass(URL,String)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <li>{@link RMIClassLoader#loadClass(String,String)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <li>{@link RMIClassLoader#loadClass(String,String,ClassLoader)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <li>{@link RMIClassLoader#loadProxyClass(String,String[],ClassLoader)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <li>{@link RMIClassLoader#getClassLoader(String)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <li>{@link RMIClassLoader#getClassAnnotation(Class)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * When one of those methods is invoked, its behavior is to delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * to a corresponding method on an instance of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * The details of how each method delegates to the provider instance is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * described in the documentation for each particular method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * See the documentation for {@link RMIClassLoader} for a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * of how a provider instance is chosen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author      Peter Jones
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author      Laird Dornin
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @see         RMIClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public abstract class RMIClassLoaderSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Provides the implementation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * {@link RMIClassLoader#loadClass(URL,String)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * {@link RMIClassLoader#loadClass(String,String)}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * {@link RMIClassLoader#loadClass(String,String,ClassLoader)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Loads a class from a codebase URL path, optionally using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * supplied loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Typically, a provider implementation will attempt to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * resolve the named class using the given <code>defaultLoader</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * if specified, before attempting to resolve the class from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * codebase URL path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * <p>An implementation of this method must either return a class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * with the given name or throw an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param   codebase the list of URLs (separated by spaces) to load
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * the class from, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param   name the name of the class to load
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param   defaultLoader additional contextual class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * to use, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @return  the <code>Class</code> object representing the loaded class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @throws  MalformedURLException if <code>codebase</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * non-<code>null</code> and contains an invalid URL, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * if <code>codebase</code> is <code>null</code> and a provider-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * URL used to load classes is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @throws  ClassNotFoundException if a definition for the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * could not be found at the specified location
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public abstract Class<?> loadClass(String codebase, String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                       ClassLoader defaultLoader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        throws MalformedURLException, ClassNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Provides the implementation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * {@link RMIClassLoader#loadProxyClass(String,String[],ClassLoader)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Loads a dynamic proxy class (see {@link java.lang.reflect.Proxy}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * that implements a set of interfaces with the given names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * from a codebase URL path, optionally using the supplied loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * <p>An implementation of this method must either return a proxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * class that implements the named interfaces or throw an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @param   codebase the list of URLs (space-separated) to load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * classes from, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param   interfaces the names of the interfaces for the proxy class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * to implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @return  a dynamic proxy class that implements the named interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param   defaultLoader additional contextual class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * to use, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @throws  MalformedURLException if <code>codebase</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * non-<code>null</code> and contains an invalid URL, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * if <code>codebase</code> is <code>null</code> and a provider-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * URL used to load classes is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @throws  ClassNotFoundException if a definition for one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * the named interfaces could not be found at the specified location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * or if creation of the dynamic proxy class failed (such as if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * {@link java.lang.reflect.Proxy#getProxyClass(ClassLoader,Class[])}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * would throw an <code>IllegalArgumentException</code> for the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * interface list)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public abstract Class<?> loadProxyClass(String codebase,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                            String[] interfaces,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                            ClassLoader defaultLoader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        throws MalformedURLException, ClassNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Provides the implementation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * {@link RMIClassLoader#getClassLoader(String)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Returns a class loader that loads classes from the given codebase
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * URL path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * <p>If there is a security manger, its <code>checkPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * method will be invoked with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * <code>RuntimePermission("getClassLoader")</code> permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * this could result in a <code>SecurityException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * The implementation of this method may also perform further security
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * checks to verify that the calling context has permission to connect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * to all of the URLs in the codebase URL path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param   codebase the list of URLs (space-separated) from which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * the returned class loader will load classes from, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @return a class loader that loads classes from the given codebase URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @throws  MalformedURLException if <code>codebase</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * non-<code>null</code> and contains an invalid URL, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * if <code>codebase</code> is <code>null</code> and a provider-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * URL used to identify the class loader is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @throws  SecurityException if there is a security manager and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * invocation of its <code>checkPermission</code> method fails, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * if the caller does not have permission to connect to all of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * URLs in the codebase URL path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public abstract ClassLoader getClassLoader(String codebase)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        throws MalformedURLException; // SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Provides the implementation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * {@link RMIClassLoader#getClassAnnotation(Class)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Returns the annotation string (representing a location for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * the class definition) that RMI will use to annotate the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * descriptor when marshalling objects of the given class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @param   cl the class to obtain the annotation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @return  a string to be used to annotate the given class when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * it gets marshalled, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @throws  NullPointerException if <code>cl</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public abstract String getClassAnnotation(Class<?> cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
}