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

Print this page




 299             return l.getPackages();
 300         } else {
 301             return getSystemPackages();
 302         }
 303     }
 304 
 305     /**
 306      * Get the package for the specified class.
 307      * The class's class loader is used to find the package instance
 308      * corresponding to the specified class. If the class loader
 309      * is the bootstrap class loader, which may be represented by
 310      * {@code null} in some implementations, then the set of packages
 311      * loaded by the bootstrap class loader is searched to find the package.
 312      * <p>
 313      * Packages have attributes for versions and specifications only
 314      * if the class loader created the package
 315      * instance with the appropriate attributes. Typically those
 316      * attributes are defined in the manifests that accompany
 317      * the classes.
 318      *
 319      * @param class the class to get the package of.
 320      * @return the package of the class. It may be null if no package
 321      *          information is available from the archive or codebase.  */
 322     static Package getPackage(Class<?> c) {
 323         String name = c.getName();
 324         int i = name.lastIndexOf('.');
 325         if (i != -1) {
 326             name = name.substring(0, i);
 327             ClassLoader cl = c.getClassLoader();
 328             if (cl != null) {
 329                 return cl.getPackage(name);
 330             } else {
 331                 return getSystemPackage(name);
 332             }
 333         } else {
 334             return null;
 335         }
 336     }
 337 
 338     /**
 339      * Return the hash code computed from the package name.


 394         return getPackageInfo().isAnnotationPresent(annotationClass);
 395     }
 396 
 397     /**
 398      * @since 1.5
 399      */
 400     public Annotation[] getAnnotations() {
 401         return getPackageInfo().getAnnotations();
 402     }
 403 
 404     /**
 405      * @since 1.5
 406      */
 407     public Annotation[] getDeclaredAnnotations()  {
 408         return getPackageInfo().getDeclaredAnnotations();
 409     }
 410 
 411     /**
 412      * Construct a package instance with the specified version
 413      * information.
 414      * @param pkgName the name of the package
 415      * @param spectitle the title of the specification
 416      * @param specversion the version of the specification
 417      * @param specvendor the organization that maintains the specification
 418      * @param impltitle the title of the implementation
 419      * @param implversion the version of the implementation
 420      * @param implvendor the organization that maintains the implementation
 421      * @return a new package for containing the specified information.
 422      */
 423     Package(String name,
 424             String spectitle, String specversion, String specvendor,
 425             String impltitle, String implversion, String implvendor,
 426             URL sealbase, ClassLoader loader)
 427     {
 428         pkgName = name;
 429         implTitle = impltitle;
 430         implVersion = implversion;
 431         implVendor = implvendor;
 432         specTitle = spectitle;
 433         specVersion = specversion;
 434         specVendor = specvendor;
 435         sealBase = sealbase;
 436         this.loader = loader;
 437     }
 438 
 439     /*
 440      * Construct a package using the attributes from the specified manifest.
 441      *




 299             return l.getPackages();
 300         } else {
 301             return getSystemPackages();
 302         }
 303     }
 304 
 305     /**
 306      * Get the package for the specified class.
 307      * The class's class loader is used to find the package instance
 308      * corresponding to the specified class. If the class loader
 309      * is the bootstrap class loader, which may be represented by
 310      * {@code null} in some implementations, then the set of packages
 311      * loaded by the bootstrap class loader is searched to find the package.
 312      * <p>
 313      * Packages have attributes for versions and specifications only
 314      * if the class loader created the package
 315      * instance with the appropriate attributes. Typically those
 316      * attributes are defined in the manifests that accompany
 317      * the classes.
 318      *
 319      * @param c the class to get the package of.
 320      * @return the package of the class. It may be null if no package
 321      *          information is available from the archive or codebase.  */
 322     static Package getPackage(Class<?> c) {
 323         String name = c.getName();
 324         int i = name.lastIndexOf('.');
 325         if (i != -1) {
 326             name = name.substring(0, i);
 327             ClassLoader cl = c.getClassLoader();
 328             if (cl != null) {
 329                 return cl.getPackage(name);
 330             } else {
 331                 return getSystemPackage(name);
 332             }
 333         } else {
 334             return null;
 335         }
 336     }
 337 
 338     /**
 339      * Return the hash code computed from the package name.


 394         return getPackageInfo().isAnnotationPresent(annotationClass);
 395     }
 396 
 397     /**
 398      * @since 1.5
 399      */
 400     public Annotation[] getAnnotations() {
 401         return getPackageInfo().getAnnotations();
 402     }
 403 
 404     /**
 405      * @since 1.5
 406      */
 407     public Annotation[] getDeclaredAnnotations()  {
 408         return getPackageInfo().getDeclaredAnnotations();
 409     }
 410 
 411     /**
 412      * Construct a package instance with the specified version
 413      * information.
 414      * @param name the name of the package
 415      * @param spectitle the title of the specification
 416      * @param specversion the version of the specification
 417      * @param specvendor the organization that maintains the specification
 418      * @param impltitle the title of the implementation
 419      * @param implversion the version of the implementation
 420      * @param implvendor the organization that maintains the implementation

 421      */
 422     Package(String name,
 423             String spectitle, String specversion, String specvendor,
 424             String impltitle, String implversion, String implvendor,
 425             URL sealbase, ClassLoader loader)
 426     {
 427         pkgName = name;
 428         implTitle = impltitle;
 429         implVersion = implversion;
 430         implVendor = implvendor;
 431         specTitle = spectitle;
 432         specVersion = specversion;
 433         specVendor = specvendor;
 434         sealBase = sealbase;
 435         this.loader = loader;
 436     }
 437 
 438     /*
 439      * Construct a package using the attributes from the specified manifest.
 440      *