39 |
|
|
40 |
import gnu.classpath.VMStackWalker; |
import gnu.classpath.VMStackWalker; |
41 |
|
|
42 |
|
import java.lang.annotation.Annotation; |
43 |
|
import java.lang.reflect.AnnotatedElement; |
44 |
import java.net.URL; |
import java.net.URL; |
45 |
import java.util.NoSuchElementException; |
import java.util.NoSuchElementException; |
46 |
import java.util.StringTokenizer; |
import java.util.StringTokenizer; |
72 |
* @see ClassLoader#definePackage(String, String, String, String, String, |
* @see ClassLoader#definePackage(String, String, String, String, String, |
73 |
* String, String, URL) |
* String, String, URL) |
74 |
* @since 1.2 |
* @since 1.2 |
75 |
* @status updated to 1.4 |
* @status updated to 1.5 |
76 |
*/ |
*/ |
77 |
public class Package |
public class Package |
78 |
|
implements AnnotatedElement |
79 |
{ |
{ |
80 |
/** The name of the Package */ |
/** The name of the Package */ |
81 |
private final String name; |
private final String name; |
236 |
* |
* |
237 |
* @return true if the version is compatible, false otherwise |
* @return true if the version is compatible, false otherwise |
238 |
* |
* |
239 |
* @Throws NumberFormatException if either version string is invalid |
* @throws NumberFormatException if either version string is invalid |
240 |
* @throws NullPointerException if either version string is null |
* @throws NullPointerException if either version string is null |
241 |
*/ |
*/ |
242 |
public boolean isCompatibleWith(String version) |
public boolean isCompatibleWith(String version) |
318 |
return ("package " + name + (specTitle == null ? "" : ", " + specTitle) |
return ("package " + name + (specTitle == null ? "" : ", " + specTitle) |
319 |
+ (specVersion == null ? "" : ", version " + specVersion)); |
+ (specVersion == null ? "" : ", version " + specVersion)); |
320 |
} |
} |
321 |
|
|
322 |
|
/** |
323 |
|
* Returns this package's annotation for the specified annotation type, |
324 |
|
* or <code>null</code> if no such annotation exists. |
325 |
|
* |
326 |
|
* @param annotationClass the type of annotation to look for. |
327 |
|
* @return this package's annotation for the specified type, or |
328 |
|
* <code>null</code> if no such annotation exists. |
329 |
|
* @since 1.5 |
330 |
|
*/ |
331 |
|
public <A extends Annotation> A getAnnotation(Class<A> annotationClass) |
332 |
|
{ |
333 |
|
A foundAnnotation = null; |
334 |
|
Annotation[] annotations = getAnnotations(); |
335 |
|
for (Annotation annotation : annotations) |
336 |
|
if (annotation.annotationType() == annotationClass) |
337 |
|
foundAnnotation = (A) annotation; |
338 |
|
return foundAnnotation; |
339 |
|
} |
340 |
|
|
341 |
|
/** |
342 |
|
* Returns all annotations associated with this package. If there are |
343 |
|
* no annotations associated with this package, then a zero-length array |
344 |
|
* will be returned. The returned array may be modified by the client |
345 |
|
* code, but this will have no effect on the annotation content of this |
346 |
|
* package, and hence no effect on the return value of this method for |
347 |
|
* future callers. |
348 |
|
* |
349 |
|
* @return this package' annotations. |
350 |
|
* @since 1.5 |
351 |
|
*/ |
352 |
|
public Annotation[] getAnnotations() |
353 |
|
{ |
354 |
|
/** All a package's annotations are declared within it. */ |
355 |
|
return getDeclaredAnnotations(); |
356 |
|
} |
357 |
|
|
358 |
|
/** |
359 |
|
* Returns all annotations directly defined by this package. If there are |
360 |
|
* no annotations associated with this package, then a zero-length array |
361 |
|
* will be returned. The returned array may be modified by the client |
362 |
|
* code, but this will have no effect on the annotation content of this |
363 |
|
* package, and hence no effect on the return value of this method for |
364 |
|
* future callers. |
365 |
|
* |
366 |
|
* @return the annotations directly defined by this package. |
367 |
|
* @since 1.5 |
368 |
|
*/ |
369 |
|
public Annotation[] getDeclaredAnnotations() |
370 |
|
{ |
371 |
|
return VMPackage.getDeclaredAnnotations(this); |
372 |
|
} |
373 |
|
|
374 |
|
/** |
375 |
|
* Returns true if an annotation for the specified type is associated |
376 |
|
* with this package. This is primarily a short-hand for using marker |
377 |
|
* annotations. |
378 |
|
* |
379 |
|
* @param annotationClass the type of annotation to look for. |
380 |
|
* @return true if an annotation exists for the specified type. |
381 |
|
* @since 1.5 |
382 |
|
*/ |
383 |
|
public boolean isAnnotationPresent(Class<? extends Annotation> |
384 |
|
annotationClass) |
385 |
|
{ |
386 |
|
return getAnnotation(annotationClass) != null; |
387 |
|
} |
388 |
|
|
389 |
} // class Package |
} // class Package |