jdk/src/java.base/share/classes/java/lang/Package.java
author shade
Tue, 17 May 2016 22:28:00 +0300
changeset 38372 017d7578731c
parent 37521 b6e0f285c998
child 40804 aa5e0497d497
permissions -rw-r--r--
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles Reviewed-by: psandoz, redestad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
     2
 * Copyright (c) 1997, 2015, 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: 3959
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: 3959
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: 3959
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
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.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    28
import java.lang.annotation.Annotation;
16051
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
    29
import java.lang.reflect.AnnotatedElement;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    30
import java.lang.reflect.Module;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    31
import java.net.MalformedURLException;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    32
import java.net.URI;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.PrivilegedAction;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    36
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    38
import jdk.internal.loader.BootLoader;
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 36511
diff changeset
    39
import jdk.internal.reflect.CallerSensitive;
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 36511
diff changeset
    40
import jdk.internal.reflect.Reflection;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    44
 * Represents metadata about a run-time package associated with a class loader.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    45
 * Metadata includes annotations, versioning, and sealing.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    46
 * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    47
 * Annotations for the run-time package are read from {@code package-info.class}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    48
 * at the same code source as classes in the run-time package.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    49
 * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    50
 * The set of classes that make up the run-time package may implement a
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    51
 * particular specification. The specification title, version, and vendor
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    52
 * (indicating the owner/maintainer of the specification) can be provided
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    53
 * when the {@code Package} is defined. An application can ask if the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    54
 * {@code Package} is compatible with a particular specification version
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    55
 * by using the {@link #isCompatibleWith Package.isCompatibleWith(String)}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    56
 * method. In addition, information about the actual classes that make up the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    57
 * run-time package can be provided when the Package is defined.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    58
 * This information consists of an implementation title, version, and vendor
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    59
 * (indicating the supplier of the classes).
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    60
 * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    61
 * A {@code Package} may be explicitly defined with
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    62
 * the {@link ClassLoader#definePackage(String, String, String, String,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    63
 * String, String, String, URL)} method.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    64
 * The caller supplies the specification and implementation titles, versions, and
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    65
 * vendors. The caller also indicates whether the package is
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    66
 * {@linkplain java.util.jar.Attributes.Name#SEALED sealed}.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    67
 * If a {@code Package} is not explicitly defined for a run-time package when
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    68
 * a class in that run-time package is defined, then a {@code Package} is
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    69
 * automatically defined by the class's defining class loader, as follows.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    70
 * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    71
 * A {@code Package} automatically defined for classes in a named module has
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    72
 * the following properties:
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    73
 * <ul>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    74
 * <li>The name of the package is derived from the {@linkplain Class#getName() binary names}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    75
 *     of the classes. Since classes in a named module must be in a named package,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    76
 *     the derived name is never empty.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    77
 * <li>The package is sealed with the {@linkplain java.lang.module.ModuleReference#location()
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    78
 *     module location} as the code source, if known.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    79
 * <li>The specification and implementation titles, versions, and vendors
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    80
 *     are unspecified.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    81
 * <li>Any annotations on the package are read from {@code package-info.class}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    82
 *     as specified above.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    83
 * </ul>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    84
 * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    85
 * A {@code Package} automatically defined for classes in an unnamed module
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    86
 * has the following properties:
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    87
 * <ul>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    88
 * <li>The name of the package is either {@code ""} (for classes in an unnamed package)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    89
 *     or derived from the {@linkplain Class#getName() binary names} of the classes
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    90
 *     (for classes in a named package).</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    91
 * <li>The package is not sealed.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    92
 * <li>The specification and implementation titles, versions, and vendors
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    93
 *     are unspecified.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    94
 * <li>Any annotations on the package are read from {@code package-info.class}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    95
 *     as specified above.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    96
 * </ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    98
 * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    99
 * A {@code Package} can be obtained with the {@link Package#getPackage
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   100
 * Package.getPackage(String)} and {@link ClassLoader#getDefinedPackage
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   101
 * ClassLoader.getDefinedPackage(String)} methods.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   102
 * Every {@code Package} defined by a class loader can be obtained
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   103
 * with the {@link Package#getPackages Package.getPackages()} and
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   104
 * {@link ClassLoader#getDefinedPackages} methods.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   106
 * @jvms 5.3 Run-time package
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   107
 * @see <a href="../../../technotes/guides/jar/jar.html#versioning">
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   108
 * The JAR File Specification: Package Versioning</a>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   109
 * @see <a href="../../../technotes/guides/jar/jar.html#sealing">
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   110
 * The JAR File Specification: Package Sealing</a>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   111
 * @see ClassLoader#definePackage(String, String, String, String, String, String, String, URL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *
25176
3c2ba9344cbf 8047721: @since should have JDK version
henryjen
parents: 22581
diff changeset
   113
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   115
public class Package extends NamedPackage implements java.lang.reflect.AnnotatedElement {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Return the name of this package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8543
diff changeset
   119
     * @return  The fully-qualified name of this package as defined in section 6.5.3 of
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8543
diff changeset
   120
     *          <cite>The Java&trade; Language Specification</cite>,
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8543
diff changeset
   121
     *          for example, {@code java.lang}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public String getName() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   124
        return packageName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Return the title of the specification that this package implements.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   129
     * @return the specification title, {@code null} is returned if it is not known.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public String getSpecificationTitle() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   132
        return versionInfo.specTitle;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Returns the version number of the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * that this package implements.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   138
     * This version string must be a sequence of non-negative decimal
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * integers separated by "."'s and may have leading zeros.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * When version strings are compared the most significant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * numbers are compared.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   142
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   143
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   144
     * <p>Specification version numbers use a syntax that consists of non-negative
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   145
     * decimal integers separated by periods ".", for example "2.0" or
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   146
     * "1.2.3.4.5.6.7".  This allows an extensible number to be used to represent
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   147
     * major, minor, micro, etc. versions.  The version specification is described
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   148
     * by the following formal grammar:
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   149
     * <blockquote>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   150
     * <dl>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   151
     * <dt><i>SpecificationVersion:</i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   152
     * <dd><i>Digits RefinedVersion<sub>opt</sub></i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   153
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   154
     * <dt><i>RefinedVersion:</i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   155
     * <dd>{@code .} <i>Digits</i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   156
     * <dd>{@code .} <i>Digits RefinedVersion</i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   157
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   158
     * <dt><i>Digits:</i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   159
     * <dd><i>Digit</i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   160
     * <dd><i>Digits</i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   161
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   162
     * <dt><i>Digit:</i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   163
     * <dd>any character for which {@link Character#isDigit} returns {@code true},
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   164
     * e.g. 0, 1, 2, ...
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   165
     * </dl>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   166
     * </blockquote>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   167
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   168
     * @return the specification version, {@code null} is returned if it is not known.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public String getSpecificationVersion() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   171
        return versionInfo.specVersion;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Return the name of the organization, vendor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * or company that owns and maintains the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * of the classes that implement this package.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   178
     * @return the specification vendor, {@code null} is returned if it is not known.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public String getSpecificationVendor() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   181
        return versionInfo.specVendor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Return the title of this package.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   186
     * @return the title of the implementation, {@code null} is returned if it is not known.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public String getImplementationTitle() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   189
        return versionInfo.implTitle;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Return the version of this implementation. It consists of any string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * assigned by the vendor of this implementation and does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * not have any particular syntax specified or expected by the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * runtime. It may be compared for equality with other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * package version strings used for this implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * by this vendor for this package.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   199
     * @return the version of the implementation, {@code null} is returned if it is not known.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public String getImplementationVersion() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   202
        return versionInfo.implVersion;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   206
     * Returns the vendor that implemented this package, {@code null}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   207
     * is returned if it is not known.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   208
     * @return the vendor that implemented this package, {@code null}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   209
     * is returned if it is not known.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public String getImplementationVendor() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   212
        return versionInfo.implVendor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Returns true if this package is sealed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @return true if the package is sealed, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public boolean isSealed() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   221
        return module().isNamed() || versionInfo.sealBase != null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Returns true if this package is sealed with respect to the specified
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   226
     * code source {@code url}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   228
     * @param url the code source URL
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   229
     * @return true if this package is sealed with respect to the given {@code url}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public boolean isSealed(URL url) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   232
        Objects.requireNonNull(url);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   233
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   234
        URL sealBase = null;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   235
        if (versionInfo != VersionInfo.NULL_VERSION_INFO) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   236
            sealBase = versionInfo.sealBase;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   237
        } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   238
            try {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   239
                URI uri = location();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   240
                sealBase = uri != null ? uri.toURL() : null;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   241
            } catch (MalformedURLException e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   242
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   243
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return url.equals(sealBase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Compare this package's specification version with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * desired version. It returns true if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * this packages specification version number is greater than or equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * to the desired version number. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Version numbers are compared by sequentially comparing corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * components of the desired and specification strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Each component is converted as a decimal integer and the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * compared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * If the specification value is greater than the desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * value true is returned. If the value is less false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * If the values are equal the period is skipped and the next pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * components is compared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @param desired the version string of the desired version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @return true if this package's version number is greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *          than or equal to the desired version number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   266
     * @exception NumberFormatException if the current version is not known or
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   267
     *          the desired or current version is not of the correct dotted form.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public boolean isCompatibleWith(String desired)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        throws NumberFormatException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   272
        if (versionInfo.specVersion == null || versionInfo.specVersion.length() < 1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            throw new NumberFormatException("Empty version string");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   276
        String [] sa = versionInfo.specVersion.split("\\.", -1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        int [] si = new int[sa.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        for (int i = 0; i < sa.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            si[i] = Integer.parseInt(sa[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            if (si[i] < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                throw NumberFormatException.forInputString("" + si[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        String [] da = desired.split("\\.", -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        int [] di = new int[da.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        for (int i = 0; i < da.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            di[i] = Integer.parseInt(da[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            if (di[i] < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                throw NumberFormatException.forInputString("" + di[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        int len = Math.max(di.length, si.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            int d = (i < di.length ? di[i] : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            int s = (i < si.length ? si[i] : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            if (s < d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            if (s > d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   305
     * Finds a package by name in the caller's class loader and its
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   306
     * ancestors.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   307
     * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   308
     * If the caller's class loader defines a {@code Package} of the given name,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   309
     * the {@code Package} is returned. Otherwise, the ancestors of the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   310
     * caller's class loader are searched recursively (parent by parent)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   311
     * for a {@code Package} of the given name.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   312
     * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   313
     * Calling this method is equivalent to calling {@link ClassLoader#getPackage}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   314
     * on a {@code ClassLoader} instance which is the caller's class loader.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   315
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   316
     * @param name A package name, such as "{@code java.lang}".
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   317
     * @return The {@code Package} of the given name defined by the caller's
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   318
     *         class loader or its ancestors, or {@code null} if not found.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   320
     * @deprecated
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   321
     * If multiple class loaders delegate to each other and define classes
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   322
     * with the same package name, and one such loader relies on the lookup
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   323
     * behavior of {@code getPackage} to return a {@code Package} from
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   324
     * a parent loader, then the properties exposed by the {@code Package}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   325
     * may not be as expected in the rest of the program.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   326
     * For example, the {@code Package} will only expose annotations from the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   327
     * {@code package-info.class} file defined by the parent loader, even if
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   328
     * annotations exist in a {@code package-info.class} file defined by
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   329
     * a child loader.  A more robust approach is to use the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   330
     * {@link ClassLoader#getDefinedPackage} method which returns
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   331
     * a {@code Package} for the specified class loader.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   333
     * @see ClassLoader#getDefinedPackage
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16051
diff changeset
   335
    @CallerSensitive
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 37363
diff changeset
   336
    @Deprecated(since="9")
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   337
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    public static Package getPackage(String name) {
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16051
diff changeset
   339
        ClassLoader l = ClassLoader.getClassLoader(Reflection.getCallerClass());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   340
        return l != null ? l.getPackage(name) : BootLoader.getDefinedPackage(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   344
     * Returns all of the {@code Package}s defined by the caller's class loader
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   345
     * and its ancestors.  The returned array may contain more than one
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   346
     * {@code Package} object of the same package name, each defined by
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   347
     * a different class loader in the class loader hierarchy.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   348
     * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   349
     * Calling this method is equivalent to calling {@link ClassLoader#getPackages}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   350
     * on a {@code ClassLoader} instance which is the caller's class loader.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   352
     * @return  The array of {@code Package} objects defined by this
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   353
     *          class loader and its ancestors
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   354
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   355
     * @see ClassLoader#getDefinedPackages
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16051
diff changeset
   357
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public static Package[] getPackages() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   359
        ClassLoader cl = ClassLoader.getClassLoader(Reflection.getCallerClass());
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   360
        return cl != null ? cl.getPackages() : BootLoader.packages().toArray(Package[]::new);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * Return the hash code computed from the package name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @return the hash code computed from the package name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   367
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public int hashCode(){
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   369
        return packageName().hashCode();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * Returns the string representation of this Package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * Its value is the string "package " and the package name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * If the package title is defined it is appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * If the package version is defined it is appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @return the string representation of the package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   379
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    public String toString() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   381
        String spec = versionInfo.specTitle;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   382
        String ver =  versionInfo.specVersion;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if (spec != null && spec.length() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            spec = ", " + spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            spec = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (ver != null && ver.length() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            ver = ", version " + ver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            ver = "";
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   391
        return "package " + packageName() + spec + ver;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    private Class<?> getPackageInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        if (packageInfo == null) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   396
            // find package-info.class defined by loader
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   397
            String cn = packageName() + ".package-info";
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   398
            PrivilegedAction<ClassLoader> pa = module()::getClassLoader;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   399
            ClassLoader loader = AccessController.doPrivileged(pa);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   400
            Class<?> c = loader != null ? loader.loadLocalClass(cn)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   401
                                        : BootLoader.loadClassOrNull(cn);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   402
            if (c != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   403
                packageInfo = c;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   404
            } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                // store a proxy for the package info that has no annotations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                class PackageInfoProxy {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                packageInfo = PackageInfoProxy.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        return packageInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        return getPackageInfo().getAnnotation(annotationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    /**
16051
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   422
     * {@inheritDoc}
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   423
     * @throws NullPointerException {@inheritDoc}
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   424
     * @since 1.5
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   425
     */
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   426
    @Override
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   427
    public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   428
        return AnnotatedElement.super.isAnnotationPresent(annotationClass);
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   429
    }
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   430
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   431
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @throws NullPointerException {@inheritDoc}
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   433
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   434
     */
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   435
    @Override
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   436
    public  <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationClass) {
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   437
        return getPackageInfo().getAnnotationsByType(annotationClass);
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   438
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   439
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   440
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    public Annotation[] getAnnotations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        return getPackageInfo().getAnnotations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    /**
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   448
     * @throws NullPointerException {@inheritDoc}
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   449
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   450
     */
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   451
    @Override
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   452
    public <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationClass) {
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   453
        return getPackageInfo().getDeclaredAnnotation(annotationClass);
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   454
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   455
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   456
    /**
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   457
     * @throws NullPointerException {@inheritDoc}
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   458
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   459
     */
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   460
    @Override
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   461
    public <A extends Annotation> A[] getDeclaredAnnotationsByType(Class<A> annotationClass) {
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   462
        return getPackageInfo().getDeclaredAnnotationsByType(annotationClass);
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   463
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   464
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   465
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    public Annotation[] getDeclaredAnnotations()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        return getPackageInfo().getDeclaredAnnotations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   473
     * Construct a package instance for an unnamed module
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   474
     * with the specified version information.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   475
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   476
     * @apiNote
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   477
     * This method should not be called to define a Package for named module.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   478
     *
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 11117
diff changeset
   479
     * @param name the name of the package
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @param spectitle the title of the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @param specversion the version of the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * @param specvendor the organization that maintains the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @param impltitle the title of the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @param implversion the version of the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @param implvendor the organization that maintains the implementation
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   486
     * @param sealbase code source where this Package comes from
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   487
     * @param loader defining class loader
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    Package(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            String spectitle, String specversion, String specvendor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            String impltitle, String implversion, String implvendor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            URL sealbase, ClassLoader loader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   494
        super(Objects.requireNonNull(name),
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   495
              loader != null ? loader.getUnnamedModule()
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   496
                             : BootLoader.getUnnamedModule());
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   497
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   498
        this.versionInfo = VersionInfo.getInstance(spectitle, specversion,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   499
                                                   specvendor, impltitle,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   500
                                                   implversion, implvendor,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   501
                                                   sealbase);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   504
    Package(String name, Module module) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   505
        super(name, module);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   506
        this.versionInfo = VersionInfo.NULL_VERSION_INFO;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /*
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   510
     * Versioning information.  Only for packages in unnamed modules.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   512
    static class VersionInfo {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   513
        static final VersionInfo NULL_VERSION_INFO
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   514
            = new VersionInfo(null, null, null, null, null, null, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   516
        private final String specTitle;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   517
        private final String specVersion;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   518
        private final String specVendor;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   519
        private final String implTitle;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   520
        private final String implVersion;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   521
        private final String implVendor;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   522
        private final URL sealBase;
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   523
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   524
        static VersionInfo getInstance(String spectitle, String specversion,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   525
                                       String specvendor, String impltitle,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   526
                                       String implversion, String implvendor,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   527
                                       URL sealbase) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   528
            if (spectitle == null && specversion == null &&
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   529
                    specvendor == null && impltitle == null &&
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   530
                    implvendor == null && sealbase == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   531
                return NULL_VERSION_INFO;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   532
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   533
            return new VersionInfo(spectitle, specversion, specvendor,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   534
                    impltitle, implversion, implvendor,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   535
                    sealbase);
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   536
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   538
        private VersionInfo(String spectitle, String specversion,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   539
                            String specvendor, String impltitle,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   540
                            String implversion, String implvendor,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   541
                            URL sealbase)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   542
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   543
            this.implTitle = impltitle;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   544
            this.implVersion = implversion;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   545
            this.implVendor = implvendor;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   546
            this.specTitle = spectitle;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   547
            this.specVersion = specversion;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   548
            this.specVendor = specvendor;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   549
            this.sealBase = sealbase;
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   550
        }
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   551
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   553
    private final VersionInfo versionInfo;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   554
    private Class<?> packageInfo;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
}