Search in sources :

Example 46 with AnnotatedElement

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");
    }
}
Also used : AnnotatedElement(java.lang.reflect.AnnotatedElement) ParameterMap(org.glassfish.api.admin.ParameterMap) CommandModel(org.glassfish.api.admin.CommandModel) Test(org.junit.Test)

Example 47 with AnnotatedElement

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;
}
Also used : RolesAllowed(javax.annotation.security.RolesAllowed) AnnotatedElement(java.lang.reflect.AnnotatedElement) PermitAll(javax.annotation.security.PermitAll)

Example 48 with AnnotatedElement

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;
}
Also used : AnnotatedElement(java.lang.reflect.AnnotatedElement) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 49 with AnnotatedElement

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();
}
Also used : ApplicationException(javax.ejb.ApplicationException) EjbBundleContext(com.sun.enterprise.deployment.annotation.context.EjbBundleContext) EjbApplicationExceptionInfo(org.glassfish.ejb.deployment.descriptor.EjbApplicationExceptionInfo) AnnotatedElement(java.lang.reflect.AnnotatedElement) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler) Annotation(java.lang.annotation.Annotation) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 50 with AnnotatedElement

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;
        }
    };
}
Also used : BuilderConfiguration(org.springframework.web.servlet.mvc.method.RequestMappingInfo.BuilderConfiguration) RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo) AnnotatedElement(java.lang.reflect.AnnotatedElement) Method(java.lang.reflect.Method) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Predicate(java.util.function.Predicate) HandlerTypePredicate(org.springframework.web.method.HandlerTypePredicate) StringValueResolver(org.springframework.util.StringValueResolver) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

AnnotatedElement (java.lang.reflect.AnnotatedElement)106 Method (java.lang.reflect.Method)23 Annotation (java.lang.annotation.Annotation)17 Field (java.lang.reflect.Field)17 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)11 HashMap (java.util.HashMap)9 Test (org.junit.jupiter.api.Test)8 Member (java.lang.reflect.Member)7 LinkedHashSet (java.util.LinkedHashSet)7 List (java.util.List)7 Constructor (java.lang.reflect.Constructor)6 Type (java.lang.reflect.Type)6 Map (java.util.Map)6 HashSet (java.util.HashSet)5 By (org.openqa.selenium.By)5 Statement (org.junit.runners.model.Statement)4 FindBy (org.openqa.selenium.support.FindBy)4 EntityType (com.querydsl.codegen.EntityType)3 Collection (java.util.Collection)3