org.ocelotds.spring.extension.SpringConfigurationWrapper Maven / Gradle / Ivy
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.ocelotds.spring.extension;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.HashSet;
import java.util.Set;
import javax.enterprise.inject.Alternative;
import javax.enterprise.inject.spi.AnnotatedConstructor;
import javax.enterprise.inject.spi.AnnotatedField;
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.util.AnnotationLiteral;
import org.ocelotds.spring.OcelotSpringConfiguration;
/**
*
* @author hhfrancois
* @param
*/
public class SpringConfigurationWrapper implements AnnotatedType {
private final static Annotation OSCLITERAL = new AnnotationLiteral() {};
final AnnotatedType type;
SpringConfigurationWrapper(AnnotatedType type) {
this.type = type;
}
@Override
public Class getJavaClass() {
return type.getJavaClass();
}
@Override
public Set> getConstructors() {
return type.getConstructors();
}
@Override
public Set> getMethods() {
return type.getMethods();
}
@Override
public Set> getFields() {
return type.getFields();
}
@Override
public Type getBaseType() {
return type.getBaseType();
}
@Override
public Set getTypeClosure() {
return type.getTypeClosure();
}
@Override
public X getAnnotation(final Class annType) {
return (X) (annType.equals(Alternative.class) ? OSCLITERAL : type.getAnnotation(annType));
}
@Override
public Set getAnnotations() {
Set annotations = new HashSet<>(type.getAnnotations());
annotations.add(OSCLITERAL);
return annotations;
}
@Override
public boolean isAnnotationPresent(Class extends Annotation> annotationType) {
return annotationType.equals(OcelotSpringConfiguration.class) ? true : type.isAnnotationPresent(annotationType);
}
}