2003-03-02 22:20:26 +01:00
|
|
|
/* Package.java -- information about a package
|
2003-03-29 02:34:23 +01:00
|
|
|
Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
|
2001-04-25 17:45:15 +02:00
|
|
|
|
|
|
|
This file is part of GNU Classpath.
|
|
|
|
|
|
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
02111-1307 USA.
|
|
|
|
|
2002-01-22 23:40:42 +01:00
|
|
|
Linking this library statically or dynamically with other modules is
|
|
|
|
making a combined work based on this library. Thus, the terms and
|
|
|
|
conditions of the GNU General Public License cover the whole
|
|
|
|
combination.
|
|
|
|
|
|
|
|
As a special exception, the copyright holders of this library give you
|
|
|
|
permission to link this library with independent modules to produce an
|
|
|
|
executable, regardless of the license terms of these independent
|
|
|
|
modules, and to copy and distribute the resulting executable under
|
|
|
|
terms of your choice, provided that you also meet, for each linked
|
|
|
|
independent module, the terms and conditions of the license of that
|
|
|
|
module. An independent module is a module which is not derived from
|
|
|
|
or based on this library. If you modify this library, you may extend
|
|
|
|
this exception to your version of the library, but you are not
|
|
|
|
obligated to do so. If you do not wish to do so, delete this
|
|
|
|
exception statement from your version. */
|
2001-04-25 17:45:15 +02:00
|
|
|
|
|
|
|
package java.lang;
|
|
|
|
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.NoSuchElementException;
|
|
|
|
import java.util.StringTokenizer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Everything you ever wanted to know about a package. This class makes it
|
|
|
|
* possible to attach specification and implementation information to a
|
|
|
|
* package as explained in the
|
|
|
|
* <a href="http://java.sun.com/products/jdk/1.3/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersionSpecification">Package Versioning Specification</a>
|
|
|
|
* section of the
|
|
|
|
* <a href="http://java.sun.com/products/jdk/1.3/docs/guide/versioning/spec/VersioningSpecification.html">Product Versioning Specification</a>.
|
|
|
|
* It also allows packages to be sealed with respect to the originating URL.
|
2003-03-02 22:20:26 +01:00
|
|
|
*
|
|
|
|
* <p>The most useful method is the <code>isCompatibleWith()</code> method that
|
2001-04-25 17:45:15 +02:00
|
|
|
* compares a desired version of a specification with the version of the
|
|
|
|
* specification as implemented by a package. A package is considered
|
|
|
|
* compatible with another version if the version of the specification is
|
|
|
|
* equal or higher then the requested version. Version numbers are represented
|
acinclude.m4: Fix spelling error of "separate" as "seperate".
config:
* acinclude.m4: Fix spelling error of "separate" as "seperate".
gcc:
* ChangeLog.2, c-decl.c, config/i386/i386.md, doc/gcc.texi, gcc.c,
genmultilib, toplev.c: Fix spelling errors of "separate" as
"seperate", and corresponding spelling errors of related words.
gcc/ada:
* 5oosinte.adb: Fix spelling error of "separate" as "seperate".
gcc/testsuite:
* gcc.c-torture/unsorted/unsorted.exp, lib/file-format.exp: Fix
spelling errors of "separate" as "seperate".
libffi:
* src/x86/ffi.c: Fix spelling error of "separate" as "seperate".
libjava:
* defineclass.cc, java/awt/image/ColorModel.java,
java/awt/image/SampleModel.java, java/lang/Package.java,
java/security/cert/X509Extension.java: Fix spelling errors of
"separate" as "seperate", and corresponding spelling errors of
related words.
libstdc++-v3:
* docs/html/22_locale/locale.html, docs/html/faq/index.html: Fix
spelling errors of "separate" as "seperate", and corresponding
spelling errors of related words.
* docs/html/faq/index.txt: Regenerate.
From-SVN: r46063
2001-10-07 20:02:46 +02:00
|
|
|
* as strings of positive numbers separated by dots (e.g. "1.2.0").
|
2001-04-25 17:45:15 +02:00
|
|
|
* The first number is called the major number, the second the minor,
|
|
|
|
* the third the micro, etc. A version is considered higher then another
|
|
|
|
* version if it has a bigger major number then the another version or when
|
|
|
|
* the major numbers of the versions are equal if it has a bigger minor number
|
|
|
|
* then the other version, etc. (If a version has no minor, micro, etc numbers
|
|
|
|
* then they are considered the be 0.)
|
|
|
|
*
|
2003-03-02 22:20:26 +01:00
|
|
|
* @author Mark Wielaard <mark@klomp.org>
|
|
|
|
* @see ClassLoader#definePackage(String, String, String, String, String,
|
|
|
|
* String, String, URL)
|
2001-04-25 17:45:15 +02:00
|
|
|
* @since 1.2
|
2003-03-02 22:20:26 +01:00
|
|
|
* @status updated to 1.4
|
2001-04-25 17:45:15 +02:00
|
|
|
*/
|
|
|
|
public class Package
|
|
|
|
{
|
|
|
|
/** The name of the Package */
|
|
|
|
final private String name;
|
|
|
|
|
|
|
|
/** The name if the implementation */
|
|
|
|
final private String implTitle;
|
2003-03-02 22:20:26 +01:00
|
|
|
|
2001-04-25 17:45:15 +02:00
|
|
|
/** The vendor that wrote this implementation */
|
|
|
|
final private String implVendor;
|
2003-03-02 22:20:26 +01:00
|
|
|
|
2001-04-25 17:45:15 +02:00
|
|
|
/** The version of this implementation */
|
|
|
|
final private String implVersion;
|
|
|
|
|
|
|
|
/** The name of the specification */
|
|
|
|
final private String specTitle;
|
2003-03-02 22:20:26 +01:00
|
|
|
|
2001-04-25 17:45:15 +02:00
|
|
|
/** The name of the specification designer */
|
|
|
|
final private String specVendor;
|
2003-03-02 22:20:26 +01:00
|
|
|
|
2001-04-25 17:45:15 +02:00
|
|
|
/** The version of this specification */
|
|
|
|
final private String specVersion;
|
|
|
|
|
|
|
|
/** If sealed the origin of the package classes, otherwise null */
|
|
|
|
final private URL sealed;
|
|
|
|
|
2003-03-02 22:20:26 +01:00
|
|
|
/**
|
|
|
|
* A package local constructor for the Package class. All parameters except
|
|
|
|
* the <code>name</code> of the package may be <code>null</code>.
|
|
|
|
* There are no public constructors defined for Package; this is a package
|
2001-04-25 17:45:15 +02:00
|
|
|
* local constructor that is used by java.lang.Classloader.definePackage().
|
|
|
|
*
|
|
|
|
* @param name The name of the Package
|
|
|
|
* @param specTitle The name of the specification
|
|
|
|
* @param specVendor The name of the specification designer
|
|
|
|
* @param specVersion The version of this specification
|
|
|
|
* @param implTitle The name of the implementation
|
|
|
|
* @param implVendor The vendor that wrote this implementation
|
|
|
|
* @param implVersion The version of this implementation
|
|
|
|
* @param sealed If sealed the origin of the package classes
|
|
|
|
*/
|
|
|
|
Package(String name,
|
|
|
|
String specTitle, String specVendor, String specVersion,
|
|
|
|
String implTitle, String implVendor, String implVersion, URL sealed)
|
|
|
|
{
|
|
|
|
if (name == null)
|
|
|
|
throw new IllegalArgumentException("null Package name");
|
|
|
|
|
|
|
|
this.name = name;
|
|
|
|
this.implTitle = implTitle;
|
|
|
|
this.implVendor = implVendor;
|
|
|
|
this.implVersion = implVersion;
|
|
|
|
this.specTitle = specTitle;
|
|
|
|
this.specVendor = specVendor;
|
|
|
|
this.specVersion = specVersion;
|
|
|
|
this.sealed = sealed;
|
|
|
|
}
|
|
|
|
|
2003-03-02 22:20:26 +01:00
|
|
|
/**
|
|
|
|
* Returns the Package name in dot-notation.
|
|
|
|
*
|
|
|
|
* @return the non-null package name
|
2001-04-25 17:45:15 +02:00
|
|
|
*/
|
|
|
|
public String getName()
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2003-03-02 22:20:26 +01:00
|
|
|
/**
|
|
|
|
* Returns the name of the specification, or null if unknown.
|
|
|
|
*
|
|
|
|
* @return the specification title
|
2001-04-25 17:45:15 +02:00
|
|
|
*/
|
2003-03-02 22:20:26 +01:00
|
|
|
public String getSpecificationTitle()
|
2001-04-25 17:45:15 +02:00
|
|
|
{
|
2003-03-02 22:20:26 +01:00
|
|
|
return specTitle;
|
2001-04-25 17:45:15 +02:00
|
|
|
}
|
|
|
|
|
2003-03-02 22:20:26 +01:00
|
|
|
/**
|
|
|
|
* Returns the version of the specification, or null if unknown.
|
|
|
|
*
|
|
|
|
* @return the specification version
|
2001-04-25 17:45:15 +02:00
|
|
|
*/
|
2003-03-02 22:20:26 +01:00
|
|
|
public String getSpecificationVersion()
|
2001-04-25 17:45:15 +02:00
|
|
|
{
|
2003-03-02 22:20:26 +01:00
|
|
|
return specVersion;
|
2001-04-25 17:45:15 +02:00
|
|
|
}
|
|
|
|
|
2003-03-02 22:20:26 +01:00
|
|
|
/**
|
|
|
|
* Returns the name of the specification designer, or null if unknown.
|
|
|
|
*
|
|
|
|
* @return the specification vendor
|
2001-04-25 17:45:15 +02:00
|
|
|
*/
|
2003-03-02 22:20:26 +01:00
|
|
|
public String getSpecificationVendor()
|
2001-04-25 17:45:15 +02:00
|
|
|
{
|
2003-03-02 22:20:26 +01:00
|
|
|
return specVendor;
|
2001-04-25 17:45:15 +02:00
|
|
|
}
|
|
|
|
|
2003-03-02 22:20:26 +01:00
|
|
|
/**
|
|
|
|
* Returns the name of the implementation, or null if unknown.
|
|
|
|
*
|
|
|
|
* @return the implementation title
|
2001-04-25 17:45:15 +02:00
|
|
|
*/
|
2003-03-02 22:20:26 +01:00
|
|
|
public String getImplementationTitle()
|
2001-04-25 17:45:15 +02:00
|
|
|
{
|
2003-03-02 22:20:26 +01:00
|
|
|
return implTitle;
|
2001-04-25 17:45:15 +02:00
|
|
|
}
|
|
|
|
|
2003-03-02 22:20:26 +01:00
|
|
|
/**
|
|
|
|
* Returns the version of this implementation, or null if unknown.
|
|
|
|
*
|
|
|
|
* @return the implementation version
|
2001-04-25 17:45:15 +02:00
|
|
|
*/
|
2003-03-02 22:20:26 +01:00
|
|
|
public String getImplementationVersion()
|
2001-04-25 17:45:15 +02:00
|
|
|
{
|
2003-03-02 22:20:26 +01:00
|
|
|
return implVersion;
|
2001-04-25 17:45:15 +02:00
|
|
|
}
|
|
|
|
|
2003-03-02 22:20:26 +01:00
|
|
|
/**
|
|
|
|
* Returns the vendor that wrote this implementation, or null if unknown.
|
|
|
|
*
|
|
|
|
* @return the implementation vendor
|
2001-04-25 17:45:15 +02:00
|
|
|
*/
|
2003-03-02 22:20:26 +01:00
|
|
|
public String getImplementationVendor()
|
2001-04-25 17:45:15 +02:00
|
|
|
{
|
2003-03-02 22:20:26 +01:00
|
|
|
return implVendor;
|
2001-04-25 17:45:15 +02:00
|
|
|
}
|
|
|
|
|
2003-03-02 22:20:26 +01:00
|
|
|
/**
|
2001-04-25 17:45:15 +02:00
|
|
|
* Returns true if this Package is sealed.
|
2003-03-02 22:20:26 +01:00
|
|
|
*
|
|
|
|
* @return true if the package is sealed
|
2001-04-25 17:45:15 +02:00
|
|
|
*/
|
|
|
|
public boolean isSealed()
|
|
|
|
{
|
2003-03-02 22:20:26 +01:00
|
|
|
return sealed != null;
|
2001-04-25 17:45:15 +02:00
|
|
|
}
|
|
|
|
|
2003-03-02 22:20:26 +01:00
|
|
|
/**
|
2001-04-25 17:45:15 +02:00
|
|
|
* Returns true if this Package is sealed and the origin of the classes is
|
|
|
|
* the given URL.
|
2003-03-02 22:20:26 +01:00
|
|
|
*
|
|
|
|
* @param url the URL to test
|
|
|
|
* @return true if the package is sealed by this URL
|
|
|
|
* @throws NullPointerException if url is null
|
2001-04-25 17:45:15 +02:00
|
|
|
*/
|
|
|
|
public boolean isSealed(URL url)
|
|
|
|
{
|
|
|
|
return url.equals(sealed);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the version of the specification is higher or at least as high
|
2003-03-02 22:20:26 +01:00
|
|
|
* as the desired version. Comparison is done by sequentially comparing
|
|
|
|
* dotted decimal numbers from the parameter and from
|
|
|
|
* <code>getSpecificationVersion</code>.
|
|
|
|
*
|
2001-04-25 17:45:15 +02:00
|
|
|
* @param version the (minimal) desired version of the specification
|
2003-03-02 22:20:26 +01:00
|
|
|
* @throws NumberFormatException if either version string is invalid
|
|
|
|
* @throws NullPointerException if either version string is null
|
2001-04-25 17:45:15 +02:00
|
|
|
*/
|
2003-03-02 22:20:26 +01:00
|
|
|
public boolean isCompatibleWith(String version)
|
2001-04-25 17:45:15 +02:00
|
|
|
{
|
|
|
|
StringTokenizer versionTokens = new StringTokenizer(version, ".");
|
|
|
|
StringTokenizer specTokens = new StringTokenizer(specVersion, ".");
|
|
|
|
try
|
|
|
|
{
|
2003-03-02 22:20:26 +01:00
|
|
|
while (versionTokens.hasMoreElements())
|
|
|
|
{
|
|
|
|
int vers = Integer.parseInt(versionTokens.nextToken());
|
|
|
|
int spec = Integer.parseInt(specTokens.nextToken());
|
|
|
|
if (spec < vers)
|
|
|
|
return false;
|
|
|
|
else if (spec > vers)
|
|
|
|
return true;
|
|
|
|
// They must be equal, next Token please!
|
|
|
|
}
|
2001-04-25 17:45:15 +02:00
|
|
|
}
|
|
|
|
catch (NoSuchElementException e)
|
|
|
|
{
|
2003-03-02 22:20:26 +01:00
|
|
|
// This must have been thrown by spec.nextToken() so return false.
|
|
|
|
return false;
|
2001-04-25 17:45:15 +02:00
|
|
|
}
|
|
|
|
// They must have been exactly the same version.
|
|
|
|
// Or the specVersion has more subversions. That is also good.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the named package if it is known by the callers class loader.
|
|
|
|
* It may return null if the package is unknown, when there is no
|
|
|
|
* information on that particular package available or when the callers
|
|
|
|
* classloader is null.
|
2003-03-02 22:20:26 +01:00
|
|
|
*
|
2001-04-25 17:45:15 +02:00
|
|
|
* @param name the name of the desired package
|
2003-03-02 22:20:26 +01:00
|
|
|
* @return the package by that name in the current ClassLoader
|
2001-04-25 17:45:15 +02:00
|
|
|
*/
|
|
|
|
public static Package getPackage(String name)
|
|
|
|
{
|
|
|
|
// Get the caller's classloader
|
2003-03-29 02:34:23 +01:00
|
|
|
Class c = VMSecurityManager.getClassContext()[1];
|
2001-04-25 17:45:15 +02:00
|
|
|
ClassLoader cl = c.getClassLoader();
|
2003-03-02 22:20:26 +01:00
|
|
|
return cl != null ? cl.getPackage(name) : null;
|
2001-04-25 17:45:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all the packages that are known to the callers class loader.
|
|
|
|
* It may return an empty array if the classloader of the caller is null.
|
2003-03-02 22:20:26 +01:00
|
|
|
*
|
|
|
|
* @return an array of all known packages
|
2001-04-25 17:45:15 +02:00
|
|
|
*/
|
|
|
|
public static Package[] getPackages()
|
|
|
|
{
|
|
|
|
// Get the caller's classloader
|
2003-03-29 02:34:23 +01:00
|
|
|
Class c = VMSecurityManager.getClassContext()[1];
|
2001-04-25 17:45:15 +02:00
|
|
|
ClassLoader cl = c.getClassLoader();
|
2003-03-02 22:20:26 +01:00
|
|
|
// Sun's implementation returns the packages loaded by the bootstrap
|
|
|
|
// classloader if cl is null, but right now our bootstrap classloader
|
|
|
|
// does not create any Packages.
|
|
|
|
return cl != null ? cl.getPackages() : new Package[0];
|
2001-04-25 17:45:15 +02:00
|
|
|
}
|
|
|
|
|
2003-03-02 22:20:26 +01:00
|
|
|
/**
|
2001-04-25 17:45:15 +02:00
|
|
|
* Returns the hashCode of the name of this package.
|
2003-03-02 22:20:26 +01:00
|
|
|
*
|
|
|
|
* @return the hash code
|
2001-04-25 17:45:15 +02:00
|
|
|
*/
|
|
|
|
public int hashCode()
|
|
|
|
{
|
|
|
|
return name.hashCode();
|
|
|
|
}
|
|
|
|
|
2003-03-02 22:20:26 +01:00
|
|
|
/**
|
|
|
|
* Returns a string representation of this package. It is specified to
|
|
|
|
* be <code>"package " + getName() + (getSpecificationTitle() == null
|
|
|
|
* ? "" : ", " + getSpecificationTitle()) + (getSpecificationVersion()
|
|
|
|
* == null ? "" : ", version " + getSpecificationVersion())</code>.
|
|
|
|
*
|
|
|
|
* @return the string representation of the package
|
2001-04-25 17:45:15 +02:00
|
|
|
*/
|
|
|
|
public String toString()
|
|
|
|
{
|
2003-03-29 02:34:23 +01:00
|
|
|
return ("package " + name + (specTitle == null ? "" : ", " + specTitle)
|
|
|
|
+ (specVersion == null ? "" : ", version " + specVersion));
|
2001-04-25 17:45:15 +02:00
|
|
|
}
|
2003-03-02 22:20:26 +01:00
|
|
|
} // class Package
|