use of java.lang.reflect.AnnotatedElement in project Payara by payara.
the class MapInjectionResolverTest method getParamValueTest.
@Test
public void getParamValueTest() {
try {
DummyCommand dc = new DummyCommand();
Class<?> cl = dc.getClass();
ParameterMap params = new ParameterMap();
params.add("hello", "world");
CommandModel dccm = new CommandModelImpl(dc.getClass());
MapInjectionResolver mir = new MapInjectionResolver(dccm, params);
AnnotatedElement ae = (AnnotatedElement) cl.getDeclaredField("hello");
String hello = mir.getValue(dc, ae, null, String.class);
assertEquals("hello should be world", "world", hello);
} catch (Exception ex) {
ex.printStackTrace();
fail("unexpected exception");
}
}
use of java.lang.reflect.AnnotatedElement in project Payara by payara.
the class AbstractAuthAnnotationHandler method validateAccessControlAnnotations.
/**
* This method checks whether annotations are compatible.
* One cannot have two or more of the @DenyAll, @PermitAll, @RoleAllowed.
*
* @param ainfo
* @return validity
*/
private boolean validateAccessControlAnnotations(AnnotationInfo ainfo) throws AnnotationProcessorException {
boolean validity = true;
AnnotatedElement ae = (AnnotatedElement) ainfo.getAnnotatedElement();
int count = 0;
boolean hasDenyAll = false;
count += (ae.isAnnotationPresent(RolesAllowed.class) ? 1 : 0);
if (ae.isAnnotationPresent(DenyAll.class)) {
count += 1;
hasDenyAll = true;
}
// continue the checking if not already more than one
if (count < 2 && ae.isAnnotationPresent(PermitAll.class)) {
count++;
}
if (count > 1) {
log(Level.SEVERE, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.morethanoneauthannotation", "One cannot have more than one of @RolesAllowed, @PermitAll, @DenyAll in the same AnnotatedElement."));
validity = false;
}
return validity;
}
use of java.lang.reflect.AnnotatedElement in project Payara by payara.
the class StatelessHandler 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.STATELESS);
return newDescriptor;
}
use of java.lang.reflect.AnnotatedElement in project Payara by payara.
the class ApplicationExceptionHandler method processAnnotation.
public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo) throws AnnotationProcessorException {
AnnotatedElement ae = ainfo.getAnnotatedElement();
Annotation annotation = ainfo.getAnnotation();
AnnotatedElementHandler aeHandler = ainfo.getProcessingContext().getHandler();
if (aeHandler instanceof EjbBundleContext) {
EjbBundleContext ejbBundleContext = (EjbBundleContext) aeHandler;
EjbBundleDescriptorImpl ejbBundle = (EjbBundleDescriptorImpl) ejbBundleContext.getDescriptor();
ApplicationException appExcAnn = (ApplicationException) annotation;
EjbApplicationExceptionInfo appExcInfo = new EjbApplicationExceptionInfo();
Class annotatedClass = (Class) ae;
appExcInfo.setExceptionClassName(annotatedClass.getName());
appExcInfo.setRollback(appExcAnn.rollback());
appExcInfo.setInherited(appExcAnn.inherited());
// in ejb-jar.xml
if (!ejbBundle.getApplicationExceptions().containsKey(annotatedClass.getName())) {
ejbBundle.addApplicationException(appExcInfo);
}
}
return getDefaultProcessedResult();
}
use of java.lang.reflect.AnnotatedElement in project snow-owl by b2ihealthcare.
the class SnowOwlApiConfig method createRequestMappingHandlerMapping.
@Override
protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
return new RequestMappingHandlerMapping() {
private StringValueResolver embeddedValueResolver;
@Override
public void setEmbeddedValueResolver(StringValueResolver resolver) {
super.setEmbeddedValueResolver(resolver);
this.embeddedValueResolver = resolver;
}
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
RequestMappingInfo info = createRequestMappingInfo(method);
if (info != null) {
RequestMappingInfo typeInfo = createRequestMappingInfo(handlerType);
if (typeInfo != null) {
info = typeInfo.combine(info);
}
String prefix = getPrefix(handlerType);
if (prefix != null && !prefix.equals("/")) {
BuilderConfiguration config = new BuilderConfiguration();
config.setPathMatcher(getPathMatcher());
config.setSuffixPatternMatch(false);
info = RequestMappingInfo.paths(prefix).options(config).build().combine(info);
}
}
return info;
}
@Nullable
private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) {
RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class);
RequestCondition<?> condition = (element instanceof Class ? getCustomTypeCondition((Class<?>) element) : getCustomMethodCondition((Method) element));
return (requestMapping != null ? createRequestMappingInfo(requestMapping, condition) : null);
}
private String getPrefix(Class<?> handlerType) {
for (Map.Entry<String, Predicate<Class<?>>> entry : getPathPrefixes().entrySet()) {
if (entry.getValue().test(handlerType)) {
String prefix = entry.getKey();
if (this.embeddedValueResolver != null) {
prefix = this.embeddedValueResolver.resolveStringValue(prefix);
}
return prefix;
}
}
return null;
}
};
}
Aggregations