Commit 7ddd8380 by Gary Benson Committed by Gary Benson

Security.java: Merge with classpath.

2006-11-21  Gary Benson  <gbenson@redhat.com>

	* java/security/Security.java: Merge with classpath.
	* java/lang/Package.java: Likewise.
	* java/lang/Class.java (getDeclaredAnnotations): New method.

From-SVN: r119057
parent 0b2229b0
2006-11-21 Gary Benson <gbenson@redhat.com>
* java/security/Security.java: Merge with classpath.
* java/lang/Package.java: Likewise.
* java/lang/Class.java (getDeclaredAnnotations): New method.
2006-11-20 David Daney <ddaney@avtrex.com>
* include/mips-signal.h (sys/syscall.h): Do not include.
......
......@@ -40,6 +40,7 @@ package java.lang;
import java.io.InputStream;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.GenericDeclaration;
......@@ -949,6 +950,23 @@ public final class Class implements Type, GenericDeclaration, Serializable
}
/**
* Returns all annotations directly defined by this class. If there are
* no annotations associated with this class, then a zero-length array
* will be returned. The returned array may be modified by the client
* code, but this will have no effect on the annotation content of this
* class, and hence no effect on the return value of this method for
* future callers.
*
* @return the annotations directly defined by this class.
* @since 1.5
*/
public Annotation[] getDeclaredAnnotations()
{
// FIXME write real implementation
return new Annotation[0];
}
/**
* Returns the class which immediately encloses this class. If this class
* is a top-level class, this method returns <code>null</code>.
*
......
/* Package.java -- information about a package
Copyright (C) 2000, 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
......@@ -37,6 +38,8 @@ exception statement from your version. */
package java.lang;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.net.URL;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
......@@ -68,9 +71,10 @@ import java.util.StringTokenizer;
* @see ClassLoader#definePackage(String, String, String, String, String,
* String, String, URL)
* @since 1.2
* @status updated to 1.4
* @status updated to 1.5
*/
public class Package
implements AnnotatedElement
{
/** The name of the Package */
private final String name;
......@@ -96,6 +100,20 @@ public class Package
/** If sealed the origin of the package classes, otherwise null */
private final URL sealed;
/** The class loader that defined this package */
private ClassLoader loader;
/** @deprecated Please use the other constructor that takes the class loader
* that defines the Package.
*/
Package(String name,
String specTitle, String specVendor, String specVersion,
String implTitle, String implVendor, String implVersion, URL sealed)
{
this(name, specTitle, specVendor, specVersion, implTitle, implVendor,
implVersion, sealed, null);
}
/**
* A package local constructor for the Package class. All parameters except
* the <code>name</code> of the package may be <code>null</code>.
......@@ -113,7 +131,8 @@ public class Package
*/
Package(String name,
String specTitle, String specVendor, String specVersion,
String implTitle, String implVendor, String implVersion, URL sealed)
String implTitle, String implVendor, String implVersion, URL sealed,
ClassLoader loader)
{
if (name == null)
throw new IllegalArgumentException("null Package name");
......@@ -126,6 +145,7 @@ public class Package
this.specVendor = specVendor;
this.specVersion = specVersion;
this.sealed = sealed;
this.loader = loader;
}
/**
......@@ -231,7 +251,7 @@ public class Package
*
* @return true if the version is compatible, false otherwise
*
* @Throws NumberFormatException if either version string is invalid
* @throws NumberFormatException if either version string is invalid
* @throws NullPointerException if either version string is null
*/
public boolean isCompatibleWith(String version)
......@@ -314,4 +334,82 @@ public class Package
return ("package " + name + (specTitle == null ? "" : ", " + specTitle)
+ (specVersion == null ? "" : ", version " + specVersion));
}
/**
* Returns this package's annotation for the specified annotation type,
* or <code>null</code> if no such annotation exists.
*
* @param annotationClass the type of annotation to look for.
* @return this package's annotation for the specified type, or
* <code>null</code> if no such annotation exists.
* @since 1.5
*/
/* FIXME[GENERICS]: <T extends Annotation> T getAnnotation(Class <T>) */
public Annotation getAnnotation(Class annotationClass)
{
Annotation foundAnnotation = null;
Annotation[] annotations = getAnnotations();
for (int i = 0; i < annotations.length; i++)
if (annotations[i].annotationType() == annotationClass)
foundAnnotation = annotations[i];
return foundAnnotation;
}
/**
* Returns all annotations associated with this package. If there are
* no annotations associated with this package, then a zero-length array
* will be returned. The returned array may be modified by the client
* code, but this will have no effect on the annotation content of this
* package, and hence no effect on the return value of this method for
* future callers.
*
* @return this package' annotations.
* @since 1.5
*/
public Annotation[] getAnnotations()
{
/** All a package's annotations are declared within it. */
return getDeclaredAnnotations();
}
/**
* Returns all annotations directly defined by this package. If there are
* no annotations associated with this package, then a zero-length array
* will be returned. The returned array may be modified by the client
* code, but this will have no effect on the annotation content of this
* package, and hence no effect on the return value of this method for
* future callers.
*
* @return the annotations directly defined by this package.
* @since 1.5
*/
public Annotation[] getDeclaredAnnotations()
{
try
{
Class pkgInfo = Class.forName(name + ".package-info", false, loader);
return pkgInfo.getDeclaredAnnotations();
}
catch (ClassNotFoundException _)
{
return new Annotation[0];
}
}
/**
* Returns true if an annotation for the specified type is associated
* with this package. This is primarily a short-hand for using marker
* annotations.
*
* @param annotationClass the type of annotation to look for.
* @return true if an annotation exists for the specified type.
* @since 1.5
*/
/* FIXME[GENERICS]: Signature is Class<? extends Annotation> */
public boolean isAnnotationPresent(Class
annotationClass)
{
return getAnnotation(annotationClass) != null;
}
} // class Package
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment