net.sf.mmm.util.reflect.base
Class AnnotationUtilImpl

java.lang.Object
  extended by net.sf.mmm.util.reflect.base.AnnotationUtilImpl
All Implemented Interfaces:
AnnotationUtil

@Singleton
@Named
public class AnnotationUtilImpl
extends Object
implements AnnotationUtil

This class is a collection of utility functions for dealing with annotations.

Since:
1.0.1
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
See Also:
getInstance()

Field Summary
private static AnnotationUtilImpl instance
           
private  ReflectionUtil reflectionUtil
           
 
Fields inherited from interface net.sf.mmm.util.reflect.api.AnnotationUtil
NO_TARGET
 
Constructor Summary
protected AnnotationUtilImpl()
          The constructor.
 
Method Summary
<A extends Annotation>
A
getClassAnnotation(Class<?> annotatedClass, Class<A> annotation)
          This method gets the first annotation of the type given by annotation in the class hierarchy of the given annotatedClass.
static AnnotationUtilImpl getInstance()
          This method gets the singleton instance of this AnnotationUtilImpl.
private
<A extends Annotation>
A
getInterfacesAnnotation(Class<?> annotatedType, Class<A> annotation)
          This method gets the first annotation of the type given by annotation in the hierarchy of the given annotatedInterface.
<A extends Annotation>
A
getMethodAnnotation(Method annotatedMethod, Class<A> annotation)
          This method gets the first annotation of the type given by annotation in the hierarchy of the given method.
protected  ReflectionUtil getReflectionUtil()
          This method gets the ReflectionUtilImpl used by this AnnotationUtilImpl instance.
<A extends Annotation>
A
getTypeAnnotation(Class<?> annotatedType, Class<A> annotation)
          This method gets the first annotation of the type given by annotation in the declaration of the given annotatedType.
<A extends Annotation>
boolean
isAnnotationForType(Class<A> annotationType, ElementType targetType)
          This method determines if the given annotationType represents an Annotation that has a Target compatible with the given targetType.
<A extends Annotation>
boolean
isRuntimeAnnotation(Class<A> annotationType)
          This method determines if the given annotationType represents an Annotation that has the Retention runtime and can therefore be resolved at runtime.
 void setReflectionUtil(ReflectionUtil reflectionUtil)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

private static AnnotationUtilImpl instance
See Also:
getInstance()

reflectionUtil

private ReflectionUtil reflectionUtil
See Also:
getReflectionUtil()
Constructor Detail

AnnotationUtilImpl

protected AnnotationUtilImpl()
The constructor.

Method Detail

getInstance

public static AnnotationUtilImpl getInstance()
This method gets the singleton instance of this AnnotationUtilImpl.
This design is the best compromise between easy access (via this indirection you have direct, static access to all offered functionality) and IoC-style design which allows extension and customization.
For IoC usage, simply ignore all static getInstance() methods and construct new instances via the container-framework of your choice (like plexus, pico, springframework, etc.). To wire up the dependent components everything is properly annotated using common-annotations (JSR-250). If your container does NOT support this, you should consider using a better one.

Returns:
the singleton instance.

getReflectionUtil

protected ReflectionUtil getReflectionUtil()
This method gets the ReflectionUtilImpl used by this AnnotationUtilImpl instance.

Returns:
the ReflectionUtilImpl to use.

setReflectionUtil

@Inject
public void setReflectionUtil(ReflectionUtil reflectionUtil)
Parameters:
reflectionUtil - the reflectionUtil to set

isRuntimeAnnotation

public <A extends Annotation> boolean isRuntimeAnnotation(Class<A> annotationType)
This method determines if the given annotationType represents an Annotation that has the Retention runtime and can therefore be resolved at runtime.

Specified by:
isRuntimeAnnotation in interface AnnotationUtil
Type Parameters:
A - is the type of the annotation to check.
Parameters:
annotationType - is the type of the annotation to check.
Returns:
true if the given annotationType can be resolved at runtime.

isAnnotationForType

public <A extends Annotation> boolean isAnnotationForType(Class<A> annotationType,
                                                          ElementType targetType)
This method determines if the given annotationType represents an Annotation that has a Target compatible with the given targetType.

Specified by:
isAnnotationForType in interface AnnotationUtil
Type Parameters:
A - is the type of the annotation to check.
Parameters:
annotationType - is the type of the annotation to check.
targetType - is the expected target-type to check.
Returns:
true if the given annotationType can be used to annotate elements of the given targetType.

getClassAnnotation

public <A extends Annotation> A getClassAnnotation(Class<?> annotatedClass,
                                                   Class<A> annotation)
                                        throws IllegalArgumentException
This method gets the first annotation of the type given by annotation in the class hierarchy of the given annotatedClass.
INFORMATION:
This method is only useful if the given annotation is a runtime annotation that is applicable for classes. If the annotation is inherited you may want to directly use Class.getAnnotation(Class) instead.

Specified by:
getClassAnnotation in interface AnnotationUtil
Type Parameters:
A - is the type of the requested annotation.
Parameters:
annotatedClass - is the class potentially annotated with the given annotation. This should NOT be an interface, primitive, array, enum, or annotation.
annotation - is the type of the requested annotation.
Returns:
the requested annotation or null if neither the annotatedClass nor one of its super-classes are annotated with the given annotation.
Throws:
IllegalArgumentException - if the given annotation is no runtime annotation or is NOT applicable for classes.
See Also:
AnnotationUtil.getTypeAnnotation(Class, Class)

getInterfacesAnnotation

private <A extends Annotation> A getInterfacesAnnotation(Class<?> annotatedType,
                                                         Class<A> annotation)
This method gets the first annotation of the type given by annotation in the hierarchy of the given annotatedInterface.
This method is only useful if the given annotation is a runtime annotation that is applicable for classes.

Type Parameters:
A - is the type of the requested annotation.
Parameters:
annotatedType - is the type potentially implementing an interface annotated with the given annotation. This should NOT be an primitive, array, enum, or annotation.
annotation - is the type of the requested annotation.
Returns:
the requested annotation or null if neither the annotatedInterface nor one of its super-interfaces are annotated with the given annotation.

getTypeAnnotation

public <A extends Annotation> A getTypeAnnotation(Class<?> annotatedType,
                                                  Class<A> annotation)
This method gets the first annotation of the type given by annotation in the declaration of the given annotatedType.
Instead of AnnotationUtil.getClassAnnotation(Class, Class) this method will also scan implemented interfaces for the given annotation.
This method is only useful if the given annotation is a runtime annotation.

Specified by:
getTypeAnnotation in interface AnnotationUtil
Type Parameters:
A - is the type of the requested annotation.
Parameters:
annotatedType - is the class or interface potentially annotated with the given annotation. This should NOT be an primitive, array , enum, or annotation.
annotation - is the type of the requested annotation.
Returns:
the requested annotation or null if neither the annotatedType nor one of its super-classes, or any implemented interfaces (no matter if implemented directly or indirectly) are annotated with the given annotation.

getMethodAnnotation

public <A extends Annotation> A getMethodAnnotation(Method annotatedMethod,
                                                    Class<A> annotation)
This method gets the first annotation of the type given by annotation in the hierarchy of the given method.
This method is only useful if the given annotation is a runtime annotation.

Specified by:
getMethodAnnotation in interface AnnotationUtil
Type Parameters:
A - is the type of the requested annotation.
Parameters:
annotatedMethod - is the method potentially annotated with the given annotation.
annotation - is the type of the requested annotation.
Returns:
the requested annotation or null if neither the annotatedMethod nor one of its parent methods are annotated with the given annotation.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.