src/share/classes/java/lang/Package.java

Print this page




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 

  28 import java.io.InputStream;
  29 import java.util.Enumeration;
  30 
  31 import java.util.StringTokenizer;
  32 import java.io.File;
  33 import java.io.FileInputStream;
  34 import java.io.FileNotFoundException;
  35 import java.io.IOException;
  36 import java.net.URL;
  37 import java.net.MalformedURLException;
  38 import java.security.AccessController;
  39 import java.security.PrivilegedAction;
  40 
  41 import java.util.jar.JarInputStream;
  42 import java.util.jar.Manifest;
  43 import java.util.jar.Attributes;
  44 import java.util.jar.Attributes.Name;
  45 import java.util.jar.JarException;
  46 import java.util.Map;
  47 import java.util.HashMap;


 366 
 367     private Class<?> getPackageInfo() {
 368         if (packageInfo == null) {
 369             try {
 370                 packageInfo = Class.forName(pkgName + ".package-info", false, loader);
 371             } catch (ClassNotFoundException ex) {
 372                 // store a proxy for the package info that has no annotations
 373                 class PackageInfoProxy {}
 374                 packageInfo = PackageInfoProxy.class;
 375             }
 376         }
 377         return packageInfo;
 378     }
 379 
 380     /**
 381      * @throws NullPointerException {@inheritDoc}
 382      * @since 1.5
 383      */
 384     public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
 385         return getPackageInfo().getAnnotation(annotationClass);










 386     }
 387 
 388     /**
 389      * @throws NullPointerException {@inheritDoc}
 390      * @since 1.8
 391      */
 392     @Override
 393     public  <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationClass) {
 394         return getPackageInfo().getAnnotationsByType(annotationClass);
 395     }
 396 
 397     /**
 398      * @since 1.5
 399      */
 400     public Annotation[] getAnnotations() {
 401         return getPackageInfo().getAnnotations();
 402     }
 403 
 404     /**
 405      * @throws NullPointerException {@inheritDoc}




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.lang.reflect.AnnotatedElement;
  29 import java.io.InputStream;
  30 import java.util.Enumeration;
  31 
  32 import java.util.StringTokenizer;
  33 import java.io.File;
  34 import java.io.FileInputStream;
  35 import java.io.FileNotFoundException;
  36 import java.io.IOException;
  37 import java.net.URL;
  38 import java.net.MalformedURLException;
  39 import java.security.AccessController;
  40 import java.security.PrivilegedAction;
  41 
  42 import java.util.jar.JarInputStream;
  43 import java.util.jar.Manifest;
  44 import java.util.jar.Attributes;
  45 import java.util.jar.Attributes.Name;
  46 import java.util.jar.JarException;
  47 import java.util.Map;
  48 import java.util.HashMap;


 367 
 368     private Class<?> getPackageInfo() {
 369         if (packageInfo == null) {
 370             try {
 371                 packageInfo = Class.forName(pkgName + ".package-info", false, loader);
 372             } catch (ClassNotFoundException ex) {
 373                 // store a proxy for the package info that has no annotations
 374                 class PackageInfoProxy {}
 375                 packageInfo = PackageInfoProxy.class;
 376             }
 377         }
 378         return packageInfo;
 379     }
 380 
 381     /**
 382      * @throws NullPointerException {@inheritDoc}
 383      * @since 1.5
 384      */
 385     public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
 386         return getPackageInfo().getAnnotation(annotationClass);
 387     }
 388 
 389     /**
 390      * {@inheritDoc}
 391      * @throws NullPointerException {@inheritDoc}
 392      * @since 1.5
 393      */
 394     @Override
 395     public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
 396         return AnnotatedElement.super.isAnnotationPresent(annotationClass);
 397     }
 398 
 399     /**
 400      * @throws NullPointerException {@inheritDoc}
 401      * @since 1.8
 402      */
 403     @Override
 404     public  <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationClass) {
 405         return getPackageInfo().getAnnotationsByType(annotationClass);
 406     }
 407 
 408     /**
 409      * @since 1.5
 410      */
 411     public Annotation[] getAnnotations() {
 412         return getPackageInfo().getAnnotations();
 413     }
 414 
 415     /**
 416      * @throws NullPointerException {@inheritDoc}