All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jvnet.jaxb.annox.model.XAnnotatedElement Maven / Gradle / Ivy

The newest version!
package org.jvnet.jaxb.annox.model;

import org.jvnet.jaxb.annox.util.Validate;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;

/**
 * Defines an annotated element.
 *
 * @param 
 *            type of the annotated element.
 * @author Aleksei Valikov
 */
public class XAnnotatedElement extends XAnnotated
		implements AnnotatedElement {

	/**
	 * Target annotated element.
	 */
	private final T annotatedElement;

	/**
	 * Constructs an annotated element.
	 *
	 * @param annotatedElement
	 *            target annotated element.
	 * @param xannotations
	 *            element annotations.
	 */
	public XAnnotatedElement(T annotatedElement, XAnnotation[] xannotations) {
		super(xannotations);
		Validate.notNull(annotatedElement,
				"Annotated element must not be null.");
		this.annotatedElement = annotatedElement;
	}

	/**
	 * Returns the target annotated element.
	 *
	 * @return Target annotated element.
	 */
	public T getAnnotatedElement() {
		return annotatedElement;
	}

	public boolean isAnnotationPresent(
			Class annotationClass) {
		for (final XAnnotation xannotation : getXAnnotations()) {
			if (annotationClass.equals(xannotation.getAnnotationClass())) {
				return true;
			}
		}
		return false;
	}

	public  X getAnnotation(Class annotationClass) {
		for (final XAnnotation xannotation : getXAnnotations()) {
			if (annotationClass.equals(xannotation.getAnnotationClass())) {
				@SuppressWarnings("unchecked")
				final X result = (X) xannotation.getResult();
				return result;
			}
		}
		return null;
	}

	public Annotation[] getDeclaredAnnotations() {
		throw new UnsupportedOperationException();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy