jdk/src/java.base/share/classes/java/lang/Package.java
author alanb
Thu, 01 Dec 2016 08:57:53 +0000
changeset 42338 a60f280f803c
parent 40804 aa5e0497d497
child 43712 5dfd0950317c
permissions -rw-r--r--
8169069: Module system implementation refresh (11/2016) Reviewed-by: plevart, chegar, psandoz, mchung, alanb, dfuchs, naoto, coffeys, weijun Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, claes.redestad@oracle.com, mark.reinhold@oracle.com
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
     *
40804
aa5e0497d497 8165346: j.l.ClassLoader.getDefinedPackage(String) throws NPE
mchung
parents: 37521
diff changeset
   320
     * @throws NullPointerException
aa5e0497d497 8165346: j.l.ClassLoader.getDefinedPackage(String) throws NPE
mchung
parents: 37521
diff changeset
   321
     *         if {@code name} is {@code null}.
aa5e0497d497 8165346: j.l.ClassLoader.getDefinedPackage(String) throws NPE
mchung
parents: 37521
diff changeset
   322
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   323
     * @deprecated
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   324
     * If multiple class loaders delegate to each other and define classes
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   325
     * with the same package name, and one such loader relies on the lookup
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   326
     * behavior of {@code getPackage} to return a {@code Package} from
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   327
     * a parent loader, then the properties exposed by the {@code Package}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   328
     * may not be as expected in the rest of the program.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   329
     * For example, the {@code Package} will only expose annotations from the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   330
     * {@code package-info.class} file defined by the parent loader, even if
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   331
     * annotations exist in a {@code package-info.class} file defined by
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   332
     * a child loader.  A more robust approach is to use the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   333
     * {@link ClassLoader#getDefinedPackage} method which returns
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   334
     * a {@code Package} for the specified class loader.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   336
     * @see ClassLoader#getDefinedPackage
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16051
diff changeset
   338
    @CallerSensitive
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 37363
diff changeset
   339
    @Deprecated(since="9")
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   340
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public static Package getPackage(String name) {
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16051
diff changeset
   342
        ClassLoader l = ClassLoader.getClassLoader(Reflection.getCallerClass());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   343
        return l != null ? l.getPackage(name) : BootLoader.getDefinedPackage(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   347
     * Returns all of the {@code Package}s defined by the caller's class loader
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   348
     * and its ancestors.  The returned array may contain more than one
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   349
     * {@code Package} object of the same package name, each defined by
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   350
     * a different class loader in the class loader hierarchy.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   351
     * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   352
     * Calling this method is equivalent to calling {@link ClassLoader#getPackages}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   353
     * on a {@code ClassLoader} instance which is the caller's class loader.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   355
     * @return  The array of {@code Package} objects defined by this
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   356
     *          class loader and its ancestors
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   357
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   358
     * @see ClassLoader#getDefinedPackages
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16051
diff changeset
   360
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    public static Package[] getPackages() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   362
        ClassLoader cl = ClassLoader.getClassLoader(Reflection.getCallerClass());
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   363
        return cl != null ? cl.getPackages() : BootLoader.packages().toArray(Package[]::new);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * Return the hash code computed from the package name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @return the hash code computed from the package name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   370
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    public int hashCode(){
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   372
        return packageName().hashCode();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * Returns the string representation of this Package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * Its value is the string "package " and the package name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * If the package title is defined it is appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * If the package version is defined it is appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @return the string representation of the package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   382
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    public String toString() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   384
        String spec = versionInfo.specTitle;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   385
        String ver =  versionInfo.specVersion;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if (spec != null && spec.length() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            spec = ", " + spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            spec = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (ver != null && ver.length() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            ver = ", version " + ver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            ver = "";
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   394
        return "package " + packageName() + spec + ver;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    private Class<?> getPackageInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (packageInfo == null) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   399
            // find package-info.class defined by loader
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   400
            String cn = packageName() + ".package-info";
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   401
            Module module = module();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   402
            PrivilegedAction<ClassLoader> pa = module::getClassLoader;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   403
            ClassLoader loader = AccessController.doPrivileged(pa);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   404
            Class<?> c;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   405
            if (loader != null) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   406
                c = loader.loadClass(module, cn);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   407
            } else {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   408
                c = BootLoader.loadClass(module, cn);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   409
            }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   410
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   411
            if (c != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   412
                packageInfo = c;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   413
            } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                // store a proxy for the package info that has no annotations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                class PackageInfoProxy {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                packageInfo = PackageInfoProxy.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        return packageInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        return getPackageInfo().getAnnotation(annotationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    /**
16051
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   431
     * {@inheritDoc}
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   432
     * @throws NullPointerException {@inheritDoc}
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   433
     * @since 1.5
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   434
     */
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   435
    @Override
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   436
    public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   437
        return AnnotatedElement.super.isAnnotationPresent(annotationClass);
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   438
    }
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   439
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   440
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @throws NullPointerException {@inheritDoc}
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   442
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   443
     */
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   444
    @Override
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   445
    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
   446
        return getPackageInfo().getAnnotationsByType(annotationClass);
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   447
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   448
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   449
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public Annotation[] getAnnotations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        return getPackageInfo().getAnnotations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /**
14676
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
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   461
    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
   462
        return getPackageInfo().getDeclaredAnnotation(annotationClass);
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
    /**
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   466
     * @throws NullPointerException {@inheritDoc}
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   467
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   468
     */
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   469
    @Override
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   470
    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
   471
        return getPackageInfo().getDeclaredAnnotationsByType(annotationClass);
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   472
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   473
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   474
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    public Annotation[] getDeclaredAnnotations()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        return getPackageInfo().getDeclaredAnnotations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   482
     * Construct a package instance for an unnamed module
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   483
     * with the specified version information.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   484
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   485
     * @apiNote
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   486
     * This method should not be called to define a Package for named module.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   487
     *
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 11117
diff changeset
   488
     * @param name the name of the package
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @param spectitle the title of the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @param specversion the version of the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @param specvendor the organization that maintains the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @param impltitle the title of the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @param implversion the version of the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @param implvendor the organization that maintains the implementation
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   495
     * @param sealbase code source where this Package comes from
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   496
     * @param loader defining class loader
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    Package(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            String spectitle, String specversion, String specvendor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            String impltitle, String implversion, String implvendor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            URL sealbase, ClassLoader loader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   503
        super(Objects.requireNonNull(name),
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   504
              loader != null ? loader.getUnnamedModule()
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   505
                             : BootLoader.getUnnamedModule());
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   506
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   507
        this.versionInfo = VersionInfo.getInstance(spectitle, specversion,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   508
                                                   specvendor, impltitle,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   509
                                                   implversion, implvendor,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   510
                                                   sealbase);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   513
    Package(String name, Module module) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   514
        super(name, module);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   515
        this.versionInfo = VersionInfo.NULL_VERSION_INFO;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    /*
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   519
     * Versioning information.  Only for packages in unnamed modules.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   521
    static class VersionInfo {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   522
        static final VersionInfo NULL_VERSION_INFO
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   523
            = new VersionInfo(null, null, null, null, null, null, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   525
        private final String specTitle;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   526
        private final String specVersion;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   527
        private final String specVendor;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   528
        private final String implTitle;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   529
        private final String implVersion;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   530
        private final String implVendor;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   531
        private final URL sealBase;
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   532
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   533
        static VersionInfo getInstance(String spectitle, String specversion,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   534
                                       String specvendor, String impltitle,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   535
                                       String implversion, String implvendor,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   536
                                       URL sealbase) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   537
            if (spectitle == null && specversion == null &&
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   538
                    specvendor == null && impltitle == null &&
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   539
                    implvendor == null && sealbase == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   540
                return NULL_VERSION_INFO;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   541
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   542
            return new VersionInfo(spectitle, specversion, specvendor,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   543
                    impltitle, implversion, implvendor,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   544
                    sealbase);
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   545
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   547
        private VersionInfo(String spectitle, String specversion,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   548
                            String specvendor, String impltitle,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   549
                            String implversion, String implvendor,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   550
                            URL sealbase)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   551
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   552
            this.implTitle = impltitle;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   553
            this.implVersion = implversion;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   554
            this.implVendor = implvendor;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   555
            this.specTitle = spectitle;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   556
            this.specVersion = specversion;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   557
            this.specVendor = specvendor;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   558
            this.sealBase = sealbase;
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   559
        }
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   560
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   562
    private final VersionInfo versionInfo;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   563
    private Class<?> packageInfo;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
}