use of java.lang.reflect.AnnotatedElement in project jdbi by jdbi.
the class SqlObjectFactory method forEachConfigurer.
private void forEachConfigurer(AnnotatedElement element, BiConsumer<Configurer, Annotation> consumer) {
Stream.of(element.getAnnotations()).filter(a -> a.annotationType().isAnnotationPresent(ConfiguringAnnotation.class)).forEach(a -> {
ConfiguringAnnotation meta = a.annotationType().getAnnotation(ConfiguringAnnotation.class);
consumer.accept(getConfigurer(meta.value()), a);
});
}
use of java.lang.reflect.AnnotatedElement in project junit5 by junit-team.
the class ScriptExecutionConditionTests method throwingEvaluatorIsCreatedWhenDefaultEvaluatorClassNameIsIllegal.
@Test
void throwingEvaluatorIsCreatedWhenDefaultEvaluatorClassNameIsIllegal() throws ReflectiveOperationException {
String name = "illegal class name";
ScriptExecutionCondition condition = new ScriptExecutionCondition(name);
ExtensionContext context = Mockito.mock(ExtensionContext.class);
AnnotatedElement element = SimpleTestCases.class.getDeclaredMethod("testIsEnabled");
Mockito.when(context.getElement()).thenReturn(Optional.of(element));
Exception e = assertThrows(Exception.class, () -> condition.evaluateExecutionCondition(context));
//
assertThat(e).isInstanceOf(//
ExtensionConfigurationException.class).hasMessageStartingWith("Creating instance of class `" + name + "` failed");
}
use of java.lang.reflect.AnnotatedElement in project Payara by payara.
the class StatefulHandler method createEjbDescriptor.
/**
* Create a new EjbDescriptor for a given elementName and AnnotationInfo.
* @param elementName
* @param ainfo
* @return a new EjbDescriptor
*/
protected EjbDescriptor createEjbDescriptor(String elementName, AnnotationInfo ainfo) throws AnnotationProcessorException {
AnnotatedElement ae = ainfo.getAnnotatedElement();
Class ejbClass = (Class) ae;
EjbSessionDescriptor newDescriptor = new EjbSessionDescriptor();
newDescriptor.setName(elementName);
newDescriptor.setEjbClassName(ejbClass.getName());
newDescriptor.setSessionType(EjbSessionDescriptor.STATEFUL);
return newDescriptor;
}
use of java.lang.reflect.AnnotatedElement in project Payara by payara.
the class AbstractAttributeHandler method processAnnotation.
/**
* Process a particular annotation which type is the same as the
* one returned by @see getAnnotationType(). All information
* pertinent to the annotation and its context is encapsulated
* in the passed AnnotationInfo instance.
* This is a method in interface AnnotationHandler.
*
* @param ainfo the annotation information
*/
public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo) throws AnnotationProcessorException {
AnnotatedElement ae = ainfo.getAnnotatedElement();
Annotation annotation = ainfo.getAnnotation();
if (logger.isLoggable(Level.FINER)) {
logger.finer("@process annotation " + annotation + " in " + ae);
}
AnnotatedElementHandler aeHandler = ainfo.getProcessingContext().getHandler();
if (aeHandler instanceof EjbBundleContext) {
EjbBundleContext ejbBundleContext = (EjbBundleContext) aeHandler;
AnnotatedElementHandler aeh = ejbBundleContext.createContextForEjb();
if (aeh != null) {
aeHandler = aeh;
} else {
if (isDelegatee()) {
aeHandler = ejbBundleContext.createContextForEjbInterceptor();
}
if (aeHandler == null) {
return getInvalidAnnotatedElementHandlerResult(null, ainfo);
}
}
}
if (!supportTypeInheritance() && ElementType.TYPE.equals(ainfo.getElementType()) && aeHandler instanceof ComponentContext) {
ComponentContext context = (ComponentContext) aeHandler;
Class clazz = (Class) ainfo.getAnnotatedElement();
if (!clazz.getName().equals(context.getComponentClassName())) {
if (logger.isLoggable(Level.WARNING)) {
log(Level.WARNING, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.typeinhernotsupp", "The annotation symbol inheritance is not supported."));
}
return getDefaultProcessedResult();
}
}
EjbContext[] ejbContexts = null;
EjbInterceptorContext ejbInterceptorContext = null;
if (aeHandler instanceof EjbContext) {
EjbContext ejbContext = (EjbContext) aeHandler;
ejbContexts = new EjbContext[] { ejbContext };
} else if (aeHandler instanceof EjbsContext) {
ejbContexts = ((EjbsContext) aeHandler).getEjbContexts();
} else if (isDelegatee() && aeHandler instanceof EjbInterceptorContext) {
ejbInterceptorContext = (EjbInterceptorContext) aeHandler;
} else {
return getInvalidAnnotatedElementHandlerResult(aeHandler, ainfo);
}
HandlerProcessingResult procResult = null;
if (ejbInterceptorContext != null) {
procResult = processAnnotation(ainfo, ejbInterceptorContext);
} else {
procResult = processAnnotation(ainfo, ejbContexts);
}
if (logger.isLoggable(Level.FINER)) {
logger.finer("New annotation for " + annotation);
}
return procResult;
}
use of java.lang.reflect.AnnotatedElement in project Payara by payara.
the class SingletonHandler method createEjbDescriptor.
/**
* Create a new EjbDescriptor for a given elementName and AnnotationInfo.
* @param elementName
* @param ainfo
* @return a new EjbDescriptor
*/
protected EjbDescriptor createEjbDescriptor(String elementName, AnnotationInfo ainfo) throws AnnotationProcessorException {
AnnotatedElement ae = ainfo.getAnnotatedElement();
Class ejbClass = (Class) ae;
EjbSessionDescriptor newDescriptor = new EjbSessionDescriptor();
newDescriptor.setName(elementName);
newDescriptor.setEjbClassName(ejbClass.getName());
newDescriptor.setSessionType(EjbSessionDescriptor.SINGLETON);
doSingletonSpecificProcessing(newDescriptor, ejbClass);
return newDescriptor;
}
Aggregations