use of java.lang.reflect.AnnotatedElement in project jersey by jersey.
the class AutowiredInjectResolver method resolve.
@Override
public Object resolve(Injectee injectee) {
AnnotatedElement parent = injectee.getParent();
String beanName = null;
if (parent != null) {
Qualifier an = parent.getAnnotation(Qualifier.class);
if (an != null) {
beanName = an.value();
}
}
boolean required = parent != null ? parent.getAnnotation(Autowired.class).required() : false;
return getBeanFromSpringContext(beanName, injectee, required);
}
use of java.lang.reflect.AnnotatedElement in project jersey by jersey.
the class ParamInjectionResolver method resolve.
@Override
@SuppressWarnings("unchecked")
public Object resolve(Injectee injectee) {
AnnotatedElement annotated = injectee.getParent();
Annotation[] annotations;
if (annotated.getClass().equals(Constructor.class)) {
annotations = ((Constructor) annotated).getParameterAnnotations()[injectee.getPosition()];
} else {
annotations = annotated.getDeclaredAnnotations();
}
Class componentClass = injectee.getInjecteeClass();
Type genericType = injectee.getRequiredType();
final Type targetGenericType;
if (injectee.isFactory()) {
targetGenericType = ReflectionHelper.getTypeArgument(genericType, 0);
} else {
targetGenericType = genericType;
}
final Class<?> targetType = ReflectionHelper.erasure(targetGenericType);
final Parameter parameter = Parameter.create(componentClass, componentClass, hasEncodedAnnotation(injectee), targetType, targetGenericType, annotations);
final Supplier<?> paramValueSupplier = valueSupplierProvider.getValueSupplier(parameter);
if (paramValueSupplier != null) {
if (injectee.isFactory()) {
return paramValueSupplier;
} else {
return paramValueSupplier.get();
}
}
return null;
}
use of java.lang.reflect.AnnotatedElement in project camel by apache.
the class FallbackTypeConverter method createContext.
protected synchronized <T> JAXBContext createContext(Class<T> type) throws JAXBException {
AnnotatedElement ae = hasXmlRootElement(type) ? type : type.getPackage();
JAXBContext context = contexts.get(ae);
if (context == null) {
if (hasXmlRootElement(type)) {
context = JAXBContext.newInstance(type);
contexts.put(type, context);
} else {
context = JAXBContext.newInstance(type.getPackage().getName());
contexts.put(type.getPackage(), context);
}
}
return context;
}
use of java.lang.reflect.AnnotatedElement in project querydsl by querydsl.
the class HibernateDomainExporter method collectTypes.
@Override
protected void collectTypes() throws IOException, XMLStreamException, ClassNotFoundException, NoSuchMethodException {
// super classes
Iterator<?> superClassMappings = configuration.getMappedSuperclassMappings();
while (superClassMappings.hasNext()) {
MappedSuperclass msc = (MappedSuperclass) superClassMappings.next();
EntityType entityType = createSuperType(msc.getMappedClass());
if (msc.getDeclaredIdentifierProperty() != null) {
handleProperty(entityType, msc.getMappedClass(), msc.getDeclaredIdentifierProperty());
}
Iterator<?> properties = msc.getDeclaredPropertyIterator();
while (properties.hasNext()) {
handleProperty(entityType, msc.getMappedClass(), (org.hibernate.mapping.Property) properties.next());
}
}
// entity classes
Iterator<?> classMappings = configuration.getClassMappings();
while (classMappings.hasNext()) {
PersistentClass pc = (PersistentClass) classMappings.next();
EntityType entityType = createEntityType(pc.getMappedClass());
if (pc.getDeclaredIdentifierProperty() != null) {
handleProperty(entityType, pc.getMappedClass(), pc.getDeclaredIdentifierProperty());
} else if (!pc.isInherited() && pc.hasIdentifierProperty()) {
logger.info(entityType.toString() + pc.getIdentifierProperty());
handleProperty(entityType, pc.getMappedClass(), pc.getIdentifierProperty());
} else if (pc.getIdentifier() != null) {
KeyValue identifier = pc.getIdentifier();
if (identifier instanceof Component) {
Component component = (Component) identifier;
Iterator<?> properties = component.getPropertyIterator();
if (component.isEmbedded()) {
while (properties.hasNext()) {
handleProperty(entityType, pc.getMappedClass(), (org.hibernate.mapping.Property) properties.next());
}
} else {
String name = component.getNodeName();
Class<?> clazz = component.getType().getReturnedClass();
Type propertyType = getType(pc.getMappedClass(), clazz, name);
AnnotatedElement annotated = getAnnotatedElement(pc.getMappedClass(), name);
Property property = createProperty(entityType, name, propertyType, annotated);
entityType.addProperty(property);
// handle component properties
EntityType embeddedType = createEmbeddableType(propertyType);
while (properties.hasNext()) {
handleProperty(embeddedType, clazz, (org.hibernate.mapping.Property) properties.next());
}
}
}
// TODO handle other KeyValue subclasses such as Any, DependentValue and ToOne
}
Iterator<?> properties = pc.getDeclaredPropertyIterator();
while (properties.hasNext()) {
handleProperty(entityType, pc.getMappedClass(), (org.hibernate.mapping.Property) properties.next());
}
}
}
use of java.lang.reflect.AnnotatedElement in project acceptance-test-harness by jenkinsci.
the class TSRJenkinsAcceptanceTestRule method apply.
@Override
public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
final Description description = Description.createTestDescription(method.getMethod().getDeclaringClass(), method.getName(), method.getAnnotations());
return new Statement() {
@Inject
JenkinsController controller;
@Inject
Injector injector;
@Override
public void evaluate() throws Throwable {
World world = World.get();
Injector injector = world.getInjector();
world.startTestScope(description.getDisplayName());
injector.injectMembers(target);
injector.injectMembers(this);
System.out.println("=== Starting " + description.getDisplayName());
try {
decorateWithRules(base).evaluate();
} catch (AssumptionViolatedException e) {
throw e;
} catch (Exception | AssertionError e) {
// Errors and failures
controller.diagnose(e);
throw e;
} finally {
world.endTestScope();
}
}
/**
* Look for annotations on a test and honor {@link RuleAnnotation}s in them.
*/
private Statement decorateWithRules(Statement body) {
Set<Class<? extends Annotation>> annotations = new HashSet<>();
collectAnnotationTypes(method.getMethod(), annotations);
collectAnnotationTypes(target.getClass(), annotations);
Description testDescription = Description.createTestDescription(target.getClass(), method.getName(), method.getAnnotations());
for (Class<? extends Annotation> a : annotations) {
RuleAnnotation r = a.getAnnotation(RuleAnnotation.class);
if (r != null) {
TestRule tr = injector.getInstance(r.value());
body = tr.apply(body, testDescription);
}
}
return body;
}
private void collectAnnotationTypes(AnnotatedElement e, Collection<Class<? extends Annotation>> types) {
for (Annotation a : e.getAnnotations()) {
types.add(a.annotationType());
}
}
};
}
Aggregations