FileDocCategorySizeDatePackage
Package.javaAPI DocAndroid 1.5 API10670Wed May 06 22:41:04 BST 2009java.lang

Package

public class Package extends Object implements AnnotatedElement
Contains information about a Java package. This includes implementation and specification versions. Typically this information is retrieved from the manifest.

Packages are managed by class loaders. All classes loaded by the same loader from the same package share a {@code Package} instance.

since
Android 1.0
see
java.lang.ClassLoader

Fields Summary
private final String
name
private final String
specTitle
private final String
specVersion
private final String
specVendor
private final String
implTitle
private final String
implVersion
private final String
implVendor
private final URL
sealBase
Constructors Summary
Package(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase)

        this.name = name;
        this.specTitle = specTitle;
        this.specVersion = specVersion;
        this.specVendor = specVendor;
        this.implTitle = implTitle;
        this.implVersion = implVersion;
        this.implVendor = implVendor;
        this.sealBase = sealBase;
    
Methods Summary
public TgetAnnotation(java.lang.Class annotationType)
Gets the annotation associated with the specified annotation type and this package, if present.

param
annotationType the annotation type to look for.
return
an instance of {@link Annotation} or {@code null}.
see
java.lang.reflect.AnnotatedElement#getAnnotation(java.lang.Class)
since
Android 1.0

        Annotation[] list = getAnnotations();
        for (int i = 0; i < list.length; i++) {
            if (annotationType.isInstance(list[i])) {
                return (T)list[i];
            }
        }
        
        return null;
    
public java.lang.annotation.Annotation[]getAnnotations()
Gets all annotations associated with this package, if any.

return
an array of {@link Annotation} instances, which may be empty.
see
java.lang.reflect.AnnotatedElement#getAnnotations()
since
Android 1.0

        return getDeclaredAnnotations(this, true);
    
public java.lang.annotation.Annotation[]getDeclaredAnnotations()
Gets all annotations directly declared on this package, if any.

return
an array of {@link Annotation} instances, which may be empty.
see
java.lang.reflect.AnnotatedElement#getDeclaredAnnotations()
since
Android 1.0

        return getDeclaredAnnotations(this, false);
    
private static native java.lang.annotation.Annotation[]getDeclaredAnnotations(java.lang.Package pkg, boolean publicOnly)

public java.lang.StringgetImplementationTitle()
Returns the title of the implementation of this package, or {@code null} if this is unknown. The format of this string is unspecified.

return
the implementation title, may be {@code null}.
since
Android 1.0

        return implTitle;
    
public java.lang.StringgetImplementationVendor()
Returns the name of the vendor or organization that provides this implementation of the package, or {@code null} if this is unknown. The format of this string is unspecified.

return
the implementation vendor name, may be {@code null}.
since
Android 1.0

        return implVendor;
    
public java.lang.StringgetImplementationVersion()
Returns the version of the implementation of this package, or {@code null} if this is unknown. The format of this string is unspecified.

return
the implementation version, may be {@code null}.
since
Android 1.0

        return implVersion;
    
public java.lang.StringgetName()
Returns the name of this package in the standard dot notation; for example: "java.lang".

return
the name of this package.
since
Android 1.0

        return name;
    
public static java.lang.PackagegetPackage(java.lang.String packageName)
Attempts to locate the requested package in the caller's class loader. If no package information can be located, {@code null} is returned.

param
packageName the name of the package to find.
return
the requested package, or {@code null}.
see
ClassLoader#getPackage(java.lang.String)
since
Android 1.0

        ClassLoader classloader = VMStack.getCallingClassLoader();
        return classloader.getPackage(packageName);
    
public static java.lang.Package[]getPackages()
Returns all the packages known to the caller's class loader.

return
all the packages known to the caller's class loader.
see
ClassLoader#getPackages
since
Android 1.0

        ClassLoader classloader = VMStack.getCallingClassLoader();
        return classloader.getPackages();
    
public java.lang.StringgetSpecificationTitle()
Returns the title of the specification this package implements, or {@code null} if this is unknown.

return
the specification title, may be {@code null}.
since
Android 1.0

        return specTitle;
    
public java.lang.StringgetSpecificationVendor()
Returns the name of the vendor or organization that owns and maintains the specification this package implements, or {@code null} if this is unknown.

return
the specification vendor name, may be {@code null}.
since
Android 1.0

        return specVendor;
    
public java.lang.StringgetSpecificationVersion()
Returns the version of the specification this package implements, or {@code null} if this is unknown. The version string is a sequence of non-negative integers separated by dots; for example: "1.2.3".

return
the specification version string, may be {@code null}.
since
Android 1.0

        return specVersion;
    
public inthashCode()

        return name.hashCode();
    
public booleanisAnnotationPresent(java.lang.Class annotationType)
Indicates whether the specified annotation is present.

param
annotationType the annotation type to look for.
return
{@code true} if the annotation is present; {@code false} otherwise.
see
java.lang.reflect.AnnotatedElement#isAnnotationPresent(java.lang.Class)
since
Android 1.0

        return getAnnotation(annotationType) != null;
    
public booleanisCompatibleWith(java.lang.String version)
Indicates whether this package's specification version is compatible with the specified version string. Version strings are compared by comparing each dot separated part of the version as an integer.

param
version the version string to compare against.
return
{@code true} if the package versions are compatible; {@code false} otherwise.
throws
NumberFormatException if this package's version string or the one provided are not in the correct format.
since
Android 1.0

        String[] requested = version.split("."); 
        String[] provided = specVersion.split("."); 
        
        for (int i = 0; i < Math.min(requested.length, provided.length); i++) {
            int reqNum = Integer.parseInt(requested[i]);
            int provNum = Integer.parseInt(provided[i]);
            
            if (reqNum > provNum) {
                return false;
            } else if (reqNum < provNum) {
                return true;
            }
        }

        if (requested.length > provided.length) {
            return false;
        }
        
        return true;
    
public booleanisSealed()
Indicates whether this package is sealed.

return
{@code true} if this package is sealed; {@code false} otherwise.
since
Android 1.0

        return sealBase != null;
    
public booleanisSealed(java.net.URL url)
Indicates whether this package is sealed with respect to the specified URL.

param
url the URL to check.
return
{@code true} if this package is sealed with {@code url}; {@code false} otherwise
since
Android 1.0

        return sealBase != null && sealBase.sameFile(url);
    
public java.lang.StringtoString()

        return "package " + name;