Search in sources :

Example 11 with AnnotationTarget

use of org.jboss.jandex.AnnotationTarget in project wildfly by wildfly.

the class SessionBeanComponentDescriptionFactory method processSessionBeans.

private void processSessionBeans(final DeploymentUnit deploymentUnit, final List<AnnotationInstance> sessionBeanAnnotations, final SessionBeanComponentDescription.SessionBeanType annotatedSessionBeanType) {
    final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
    final ServiceName deploymentUnitServiceName = deploymentUnit.getServiceName();
    PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
    // process these session bean annotations and create component descriptions out of it
    for (final AnnotationInstance sessionBeanAnnotation : sessionBeanAnnotations) {
        final AnnotationTarget target = sessionBeanAnnotation.target();
        if (!(target instanceof ClassInfo)) {
            // Let's just WARN and move on. No need to throw an error
            EjbLogger.DEPLOYMENT_LOGGER.warn(EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(sessionBeanAnnotation.name().toString(), target).getMessage());
            continue;
        }
        final ClassInfo sessionBeanClassInfo = (ClassInfo) target;
        // skip if it's not a valid class for session bean
        if (!assertSessionBeanClassValidity(sessionBeanClassInfo)) {
            continue;
        }
        final String ejbName = sessionBeanClassInfo.name().local();
        final AnnotationValue nameValue = sessionBeanAnnotation.value("name");
        final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? ejbName : propertyReplacer.replaceProperties(nameValue.asString());
        final SessionBeanMetaData beanMetaData = getEnterpriseBeanMetaData(deploymentUnit, beanName, SessionBeanMetaData.class);
        final SessionBeanComponentDescription.SessionBeanType sessionBeanType;
        final String beanClassName;
        if (beanMetaData != null) {
            beanClassName = override(sessionBeanClassInfo.name().toString(), beanMetaData.getEjbClass());
            sessionBeanType = override(annotatedSessionBeanType, descriptionOf(((SessionBeanMetaData) beanMetaData).getSessionType()));
        } else {
            beanClassName = sessionBeanClassInfo.name().toString();
            sessionBeanType = annotatedSessionBeanType;
        }
        final SessionBeanComponentDescription sessionBeanDescription;
        switch(sessionBeanType) {
            case STATELESS:
                sessionBeanDescription = new StatelessComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, beanMetaData);
                break;
            case STATEFUL:
                sessionBeanDescription = new StatefulComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, beanMetaData);
                // If passivation is disabled for the SFSB, either via annotation or via DD, then setup the component
                // description appropriately
                final boolean passivationCapableAnnotationValue = sessionBeanAnnotation.value("passivationCapable") == null ? true : sessionBeanAnnotation.value("passivationCapable").asBoolean();
                final Boolean passivationCapableDeploymentDescriptorValue;
                if ((beanMetaData instanceof SessionBean32MetaData)) {
                    passivationCapableDeploymentDescriptorValue = ((SessionBean32MetaData) beanMetaData).isPassivationCapable();
                } else {
                    passivationCapableDeploymentDescriptorValue = null;
                }
                final boolean passivationApplicable = override(passivationCapableDeploymentDescriptorValue, passivationCapableAnnotationValue);
                ((StatefulComponentDescription) sessionBeanDescription).setPassivationApplicable(passivationApplicable);
                break;
            case SINGLETON:
                sessionBeanDescription = new SingletonComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, beanMetaData);
                break;
            default:
                throw EjbLogger.ROOT_LOGGER.unknownSessionBeanType(sessionBeanType.name());
        }
        addComponent(deploymentUnit, sessionBeanDescription);
    }
    EjbDeploymentMarker.mark(deploymentUnit);
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) SessionBeanMetaData(org.jboss.metadata.ejb.spec.SessionBeanMetaData) ServiceName(org.jboss.msc.service.ServiceName) StatelessComponentDescription(org.jboss.as.ejb3.component.stateless.StatelessComponentDescription) StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) EjbJarDescription(org.jboss.as.ejb3.deployment.EjbJarDescription) AbstractDeploymentUnitProcessor.getEjbJarDescription(org.jboss.as.ejb3.deployment.processors.AbstractDeploymentUnitProcessor.getEjbJarDescription) SessionBean32MetaData(org.jboss.metadata.ejb.spec.SessionBean32MetaData) AnnotationValue(org.jboss.jandex.AnnotationValue) PropertyReplacer(org.jboss.metadata.property.PropertyReplacer) SingletonComponentDescription(org.jboss.as.ejb3.component.singleton.SingletonComponentDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 12 with AnnotationTarget

use of org.jboss.jandex.AnnotationTarget in project wildfly by wildfly.

the class JSFManagedBeanProcessor method handleAnnotations.

private void handleAnnotations(final CompositeIndex index, final Set<String> managedBeanClasses) throws DeploymentUnitProcessingException {
    final List<AnnotationInstance> annotations = index.getAnnotations(MANAGED_BEAN_ANNOTATION);
    if (annotations != null) {
        for (final AnnotationInstance annotation : annotations) {
            final AnnotationTarget target = annotation.target();
            if (target instanceof ClassInfo) {
                final String className = ((ClassInfo) target).name().toString();
                managedBeanClasses.add(className);
            } else {
                throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.invalidManagedBeanAnnotation(target));
            }
        }
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 13 with AnnotationTarget

use of org.jboss.jandex.AnnotationTarget in project wildfly by wildfly.

the class WarAnnotationDeploymentProcessor method processAnnotations.

/**
     * Process a single index.
     *
     * @param index the annotation index
     *
     * @throws DeploymentUnitProcessingException
     */
protected WebMetaData processAnnotations(Index index) throws DeploymentUnitProcessingException {
    Web30MetaData metaData = new Web30MetaData();
    // @WebServlet
    final List<AnnotationInstance> webServletAnnotations = index.getAnnotations(webServlet);
    if (webServletAnnotations != null && webServletAnnotations.size() > 0) {
        ServletsMetaData servlets = new ServletsMetaData();
        List<ServletMappingMetaData> servletMappings = new ArrayList<ServletMappingMetaData>();
        for (final AnnotationInstance annotation : webServletAnnotations) {
            ServletMetaData servlet = new ServletMetaData();
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebServletAnnotation(target));
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            servlet.setServletClass(classInfo.toString());
            AnnotationValue nameValue = annotation.value("name");
            if (nameValue == null || nameValue.asString().isEmpty()) {
                servlet.setName(classInfo.toString());
            } else {
                servlet.setName(nameValue.asString());
            }
            AnnotationValue loadOnStartup = annotation.value("loadOnStartup");
            if (loadOnStartup != null && loadOnStartup.asInt() >= 0) {
                servlet.setLoadOnStartupInt(loadOnStartup.asInt());
            }
            AnnotationValue asyncSupported = annotation.value("asyncSupported");
            if (asyncSupported != null) {
                servlet.setAsyncSupported(asyncSupported.asBoolean());
            }
            AnnotationValue initParamsValue = annotation.value("initParams");
            if (initParamsValue != null) {
                AnnotationInstance[] initParamsAnnotations = initParamsValue.asNestedArray();
                if (initParamsAnnotations != null && initParamsAnnotations.length > 0) {
                    List<ParamValueMetaData> initParams = new ArrayList<ParamValueMetaData>();
                    for (AnnotationInstance initParamsAnnotation : initParamsAnnotations) {
                        ParamValueMetaData initParam = new ParamValueMetaData();
                        AnnotationValue initParamName = initParamsAnnotation.value("name");
                        AnnotationValue initParamValue = initParamsAnnotation.value();
                        if (initParamName == null || initParamValue == null) {
                            throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebInitParamAnnotation(target));
                        }
                        AnnotationValue initParamDescription = initParamsAnnotation.value("description");
                        initParam.setParamName(initParamName.asString());
                        initParam.setParamValue(initParamValue.asString());
                        if (initParamDescription != null) {
                            Descriptions descriptions = getDescription(initParamDescription.asString());
                            if (descriptions != null) {
                                initParam.setDescriptions(descriptions);
                            }
                        }
                        initParams.add(initParam);
                    }
                    servlet.setInitParam(initParams);
                }
            }
            AnnotationValue descriptionValue = annotation.value("description");
            AnnotationValue displayNameValue = annotation.value("displayName");
            AnnotationValue smallIconValue = annotation.value("smallIcon");
            AnnotationValue largeIconValue = annotation.value("largeIcon");
            DescriptionGroupMetaData descriptionGroup = getDescriptionGroup((descriptionValue == null) ? "" : descriptionValue.asString(), (displayNameValue == null) ? "" : displayNameValue.asString(), (smallIconValue == null) ? "" : smallIconValue.asString(), (largeIconValue == null) ? "" : largeIconValue.asString());
            if (descriptionGroup != null) {
                servlet.setDescriptionGroup(descriptionGroup);
            }
            ServletMappingMetaData servletMapping = new ServletMappingMetaData();
            servletMapping.setServletName(servlet.getName());
            List<String> urlPatterns = new ArrayList<String>();
            AnnotationValue urlPatternsValue = annotation.value("urlPatterns");
            if (urlPatternsValue != null) {
                for (String urlPattern : urlPatternsValue.asStringArray()) {
                    urlPatterns.add(urlPattern);
                }
            }
            urlPatternsValue = annotation.value();
            if (urlPatternsValue != null) {
                for (String urlPattern : urlPatternsValue.asStringArray()) {
                    urlPatterns.add(urlPattern);
                }
            }
            if (urlPatterns.size() > 0) {
                servletMapping.setUrlPatterns(urlPatterns);
                servletMappings.add(servletMapping);
            }
            servlets.add(servlet);
        }
        metaData.setServlets(servlets);
        metaData.setServletMappings(servletMappings);
    }
    // @WebFilter
    final List<AnnotationInstance> webFilterAnnotations = index.getAnnotations(webFilter);
    if (webFilterAnnotations != null && webFilterAnnotations.size() > 0) {
        FiltersMetaData filters = new FiltersMetaData();
        List<FilterMappingMetaData> filterMappings = new ArrayList<FilterMappingMetaData>();
        for (final AnnotationInstance annotation : webFilterAnnotations) {
            FilterMetaData filter = new FilterMetaData();
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebFilterAnnotation(target));
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            filter.setFilterClass(classInfo.toString());
            AnnotationValue nameValue = annotation.value("filterName");
            if (nameValue == null || nameValue.asString().isEmpty()) {
                filter.setName(classInfo.toString());
            } else {
                filter.setName(nameValue.asString());
            }
            AnnotationValue asyncSupported = annotation.value("asyncSupported");
            if (asyncSupported != null) {
                filter.setAsyncSupported(asyncSupported.asBoolean());
            }
            AnnotationValue initParamsValue = annotation.value("initParams");
            if (initParamsValue != null) {
                AnnotationInstance[] initParamsAnnotations = initParamsValue.asNestedArray();
                if (initParamsAnnotations != null && initParamsAnnotations.length > 0) {
                    List<ParamValueMetaData> initParams = new ArrayList<ParamValueMetaData>();
                    for (AnnotationInstance initParamsAnnotation : initParamsAnnotations) {
                        ParamValueMetaData initParam = new ParamValueMetaData();
                        AnnotationValue initParamName = initParamsAnnotation.value("name");
                        AnnotationValue initParamValue = initParamsAnnotation.value();
                        if (initParamName == null || initParamValue == null) {
                            throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebInitParamAnnotation(target));
                        }
                        AnnotationValue initParamDescription = initParamsAnnotation.value("description");
                        initParam.setParamName(initParamName.asString());
                        initParam.setParamValue(initParamValue.asString());
                        if (initParamDescription != null) {
                            Descriptions descriptions = getDescription(initParamDescription.asString());
                            if (descriptions != null) {
                                initParam.setDescriptions(descriptions);
                            }
                        }
                        initParams.add(initParam);
                    }
                    filter.setInitParam(initParams);
                }
            }
            AnnotationValue descriptionValue = annotation.value("description");
            AnnotationValue displayNameValue = annotation.value("displayName");
            AnnotationValue smallIconValue = annotation.value("smallIcon");
            AnnotationValue largeIconValue = annotation.value("largeIcon");
            DescriptionGroupMetaData descriptionGroup = getDescriptionGroup((descriptionValue == null) ? "" : descriptionValue.asString(), (displayNameValue == null) ? "" : displayNameValue.asString(), (smallIconValue == null) ? "" : smallIconValue.asString(), (largeIconValue == null) ? "" : largeIconValue.asString());
            if (descriptionGroup != null) {
                filter.setDescriptionGroup(descriptionGroup);
            }
            filters.add(filter);
            FilterMappingMetaData filterMapping = new FilterMappingMetaData();
            filterMapping.setFilterName(filter.getName());
            List<String> urlPatterns = new ArrayList<String>();
            List<String> servletNames = new ArrayList<String>();
            List<DispatcherType> dispatchers = new ArrayList<DispatcherType>();
            AnnotationValue urlPatternsValue = annotation.value("urlPatterns");
            if (urlPatternsValue != null) {
                for (String urlPattern : urlPatternsValue.asStringArray()) {
                    urlPatterns.add(urlPattern);
                }
            }
            urlPatternsValue = annotation.value();
            if (urlPatternsValue != null) {
                for (String urlPattern : urlPatternsValue.asStringArray()) {
                    urlPatterns.add(urlPattern);
                }
            }
            if (urlPatterns.size() > 0) {
                filterMapping.setUrlPatterns(urlPatterns);
            }
            AnnotationValue servletNamesValue = annotation.value("servletNames");
            if (servletNamesValue != null) {
                for (String servletName : servletNamesValue.asStringArray()) {
                    servletNames.add(servletName);
                }
            }
            if (servletNames.size() > 0) {
                filterMapping.setServletNames(servletNames);
            }
            AnnotationValue dispatcherTypesValue = annotation.value("dispatcherTypes");
            if (dispatcherTypesValue != null) {
                for (String dispatcherValue : dispatcherTypesValue.asEnumArray()) {
                    dispatchers.add(DispatcherType.valueOf(dispatcherValue));
                }
            }
            if (dispatchers.size() > 0) {
                filterMapping.setDispatchers(dispatchers);
            }
            if (urlPatterns.size() > 0 || servletNames.size() > 0) {
                filterMappings.add(filterMapping);
            }
        }
        metaData.setFilters(filters);
        metaData.setFilterMappings(filterMappings);
    }
    // @WebListener
    final List<AnnotationInstance> webListenerAnnotations = index.getAnnotations(webListener);
    if (webListenerAnnotations != null && webListenerAnnotations.size() > 0) {
        List<ListenerMetaData> listeners = new ArrayList<ListenerMetaData>();
        for (final AnnotationInstance annotation : webListenerAnnotations) {
            ListenerMetaData listener = new ListenerMetaData();
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebListenerAnnotation(target));
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            listener.setListenerClass(classInfo.toString());
            AnnotationValue descriptionValue = annotation.value();
            if (descriptionValue != null) {
                DescriptionGroupMetaData descriptionGroup = getDescriptionGroup(descriptionValue.asString());
                if (descriptionGroup != null) {
                    listener.setDescriptionGroup(descriptionGroup);
                }
            }
            listeners.add(listener);
        }
        metaData.setListeners(listeners);
    }
    // @RunAs
    final List<AnnotationInstance> runAsAnnotations = index.getAnnotations(runAs);
    if (runAsAnnotations != null && runAsAnnotations.size() > 0) {
        AnnotationsMetaData annotations = metaData.getAnnotations();
        if (annotations == null) {
            annotations = new AnnotationsMetaData();
            metaData.setAnnotations(annotations);
        }
        for (final AnnotationInstance annotation : runAsAnnotations) {
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                continue;
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            AnnotationMetaData annotationMD = annotations.get(classInfo.toString());
            if (annotationMD == null) {
                annotationMD = new AnnotationMetaData();
                annotationMD.setClassName(classInfo.toString());
                annotations.add(annotationMD);
            }
            if (annotation.value() == null) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidRunAsAnnotation(target));
            }
            RunAsMetaData runAs = new RunAsMetaData();
            runAs.setRoleName(annotation.value().asString());
            annotationMD.setRunAs(runAs);
        }
    }
    // @DeclareRoles
    final List<AnnotationInstance> declareRolesAnnotations = index.getAnnotations(declareRoles);
    if (declareRolesAnnotations != null && declareRolesAnnotations.size() > 0) {
        SecurityRolesMetaData securityRoles = metaData.getSecurityRoles();
        if (securityRoles == null) {
            securityRoles = new SecurityRolesMetaData();
            metaData.setSecurityRoles(securityRoles);
        }
        for (final AnnotationInstance annotation : declareRolesAnnotations) {
            if (annotation.value() == null) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidDeclareRolesAnnotation(annotation.target()));
            }
            for (String role : annotation.value().asStringArray()) {
                SecurityRoleMetaData sr = new SecurityRoleMetaData();
                sr.setRoleName(role);
                securityRoles.add(sr);
            }
        }
    }
    // @MultipartConfig
    final List<AnnotationInstance> multipartConfigAnnotations = index.getAnnotations(multipartConfig);
    if (multipartConfigAnnotations != null && multipartConfigAnnotations.size() > 0) {
        AnnotationsMetaData annotations = metaData.getAnnotations();
        if (annotations == null) {
            annotations = new AnnotationsMetaData();
            metaData.setAnnotations(annotations);
        }
        for (final AnnotationInstance annotation : multipartConfigAnnotations) {
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidMultipartConfigAnnotation(target));
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            AnnotationMetaData annotationMD = annotations.get(classInfo.toString());
            if (annotationMD == null) {
                annotationMD = new AnnotationMetaData();
                annotationMD.setClassName(classInfo.toString());
                annotations.add(annotationMD);
            }
            MultipartConfigMetaData multipartConfig = new MultipartConfigMetaData();
            AnnotationValue locationValue = annotation.value("location");
            if (locationValue != null && locationValue.asString().length() > 0) {
                multipartConfig.setLocation(locationValue.asString());
            }
            AnnotationValue maxFileSizeValue = annotation.value("maxFileSize");
            if (maxFileSizeValue != null && maxFileSizeValue.asLong() != -1L) {
                multipartConfig.setMaxFileSize(maxFileSizeValue.asLong());
            }
            AnnotationValue maxRequestSizeValue = annotation.value("maxRequestSize");
            if (maxRequestSizeValue != null && maxRequestSizeValue.asLong() != -1L) {
                multipartConfig.setMaxRequestSize(maxRequestSizeValue.asLong());
            }
            AnnotationValue fileSizeThresholdValue = annotation.value("fileSizeThreshold");
            if (fileSizeThresholdValue != null && fileSizeThresholdValue.asInt() != 0) {
                multipartConfig.setFileSizeThreshold(fileSizeThresholdValue.asInt());
            }
            annotationMD.setMultipartConfig(multipartConfig);
        }
    }
    // @ServletSecurity
    final List<AnnotationInstance> servletSecurityAnnotations = index.getAnnotations(servletSecurity);
    if (servletSecurityAnnotations != null && servletSecurityAnnotations.size() > 0) {
        AnnotationsMetaData annotations = metaData.getAnnotations();
        if (annotations == null) {
            annotations = new AnnotationsMetaData();
            metaData.setAnnotations(annotations);
        }
        for (final AnnotationInstance annotation : servletSecurityAnnotations) {
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidServletSecurityAnnotation(target));
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            AnnotationMetaData annotationMD = annotations.get(classInfo.toString());
            if (annotationMD == null) {
                annotationMD = new AnnotationMetaData();
                annotationMD.setClassName(classInfo.toString());
                annotations.add(annotationMD);
            }
            ServletSecurityMetaData servletSecurity = new ServletSecurityMetaData();
            AnnotationValue httpConstraintValue = annotation.value();
            List<String> rolesAllowed = new ArrayList<String>();
            if (httpConstraintValue != null) {
                AnnotationInstance httpConstraint = httpConstraintValue.asNested();
                AnnotationValue httpConstraintERSValue = httpConstraint.value();
                if (httpConstraintERSValue != null) {
                    servletSecurity.setEmptyRoleSemantic(EmptyRoleSemanticType.valueOf(httpConstraintERSValue.asEnum()));
                }
                AnnotationValue httpConstraintTGValue = httpConstraint.value("transportGuarantee");
                if (httpConstraintTGValue != null) {
                    servletSecurity.setTransportGuarantee(TransportGuaranteeType.valueOf(httpConstraintTGValue.asEnum()));
                }
                AnnotationValue rolesAllowedValue = httpConstraint.value("rolesAllowed");
                if (rolesAllowedValue != null) {
                    for (String role : rolesAllowedValue.asStringArray()) {
                        rolesAllowed.add(role);
                    }
                }
            }
            servletSecurity.setRolesAllowed(rolesAllowed);
            AnnotationValue httpMethodConstraintsValue = annotation.value("httpMethodConstraints");
            if (httpMethodConstraintsValue != null) {
                AnnotationInstance[] httpMethodConstraints = httpMethodConstraintsValue.asNestedArray();
                if (httpMethodConstraints.length > 0) {
                    List<HttpMethodConstraintMetaData> methodConstraints = new ArrayList<HttpMethodConstraintMetaData>();
                    for (AnnotationInstance httpMethodConstraint : httpMethodConstraints) {
                        HttpMethodConstraintMetaData methodConstraint = new HttpMethodConstraintMetaData();
                        AnnotationValue httpMethodConstraintValue = httpMethodConstraint.value();
                        if (httpMethodConstraintValue != null) {
                            methodConstraint.setMethod(httpMethodConstraintValue.asString());
                        }
                        AnnotationValue httpMethodConstraintERSValue = httpMethodConstraint.value("emptyRoleSemantic");
                        if (httpMethodConstraintERSValue != null) {
                            methodConstraint.setEmptyRoleSemantic(EmptyRoleSemanticType.valueOf(httpMethodConstraintERSValue.asEnum()));
                        }
                        AnnotationValue httpMethodConstraintTGValue = httpMethodConstraint.value("transportGuarantee");
                        if (httpMethodConstraintTGValue != null) {
                            methodConstraint.setTransportGuarantee(TransportGuaranteeType.valueOf(httpMethodConstraintTGValue.asEnum()));
                        }
                        AnnotationValue rolesAllowedValue = httpMethodConstraint.value("rolesAllowed");
                        rolesAllowed = new ArrayList<String>();
                        if (rolesAllowedValue != null) {
                            for (String role : rolesAllowedValue.asStringArray()) {
                                rolesAllowed.add(role);
                            }
                        }
                        methodConstraint.setRolesAllowed(rolesAllowed);
                        methodConstraints.add(methodConstraint);
                    }
                    servletSecurity.setHttpMethodConstraints(methodConstraints);
                }
            }
            annotationMD.setServletSecurity(servletSecurity);
        }
    }
    return metaData;
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) SecurityRoleMetaData(org.jboss.metadata.javaee.spec.SecurityRoleMetaData) ArrayList(java.util.ArrayList) SecurityRolesMetaData(org.jboss.metadata.javaee.spec.SecurityRolesMetaData) ServletSecurityMetaData(org.jboss.metadata.web.spec.ServletSecurityMetaData) Descriptions(org.jboss.annotation.javaee.Descriptions) ListenerMetaData(org.jboss.metadata.web.spec.ListenerMetaData) MultipartConfigMetaData(org.jboss.metadata.web.spec.MultipartConfigMetaData) Web30MetaData(org.jboss.metadata.web.spec.Web30MetaData) ServletMetaData(org.jboss.metadata.web.spec.ServletMetaData) DispatcherType(org.jboss.metadata.web.spec.DispatcherType) FilterMappingMetaData(org.jboss.metadata.web.spec.FilterMappingMetaData) AnnotationTarget(org.jboss.jandex.AnnotationTarget) ParamValueMetaData(org.jboss.metadata.javaee.spec.ParamValueMetaData) FilterMetaData(org.jboss.metadata.web.spec.FilterMetaData) RunAsMetaData(org.jboss.metadata.javaee.spec.RunAsMetaData) HttpMethodConstraintMetaData(org.jboss.metadata.web.spec.HttpMethodConstraintMetaData) FiltersMetaData(org.jboss.metadata.web.spec.FiltersMetaData) ServletMappingMetaData(org.jboss.metadata.web.spec.ServletMappingMetaData) ServletsMetaData(org.jboss.metadata.web.spec.ServletsMetaData) AnnotationValue(org.jboss.jandex.AnnotationValue) DescriptionGroupMetaData(org.jboss.metadata.javaee.spec.DescriptionGroupMetaData) AnnotationsMetaData(org.jboss.metadata.web.spec.AnnotationsMetaData) AnnotationMetaData(org.jboss.metadata.web.spec.AnnotationMetaData) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 14 with AnnotationTarget

use of org.jboss.jandex.AnnotationTarget in project wildfly by wildfly.

the class ServletContainerInitializerDeploymentProcessor method processHandlesType.

private Set<ClassInfo> processHandlesType(DotName typeName, Class<?> type, CompositeIndex index) throws DeploymentUnitProcessingException {
    Set<ClassInfo> classes = new HashSet<ClassInfo>();
    if (type.isAnnotation()) {
        List<AnnotationInstance> instances = index.getAnnotations(typeName);
        for (AnnotationInstance instance : instances) {
            AnnotationTarget annotationTarget = instance.target();
            if (annotationTarget instanceof ClassInfo) {
                classes.add((ClassInfo) annotationTarget);
            } else if (annotationTarget instanceof FieldInfo) {
                classes.add(((FieldInfo) annotationTarget).declaringClass());
            } else if (annotationTarget instanceof MethodInfo) {
                classes.add(((MethodInfo) annotationTarget).declaringClass());
            } else if (annotationTarget instanceof MethodParameterInfo) {
                classes.add(((MethodParameterInfo) annotationTarget).method().declaringClass());
            }
        }
    } else {
        classes.addAll(index.getAllKnownSubclasses(typeName));
        classes.addAll(index.getAllKnownImplementors(typeName));
    }
    return classes;
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) MethodInfo(org.jboss.jandex.MethodInfo) MethodParameterInfo(org.jboss.jandex.MethodParameterInfo) AnnotationInstance(org.jboss.jandex.AnnotationInstance) FieldInfo(org.jboss.jandex.FieldInfo) HashSet(java.util.HashSet) ClassInfo(org.jboss.jandex.ClassInfo)

Example 15 with AnnotationTarget

use of org.jboss.jandex.AnnotationTarget in project wildfly by wildfly.

the class ApplicationExceptionAnnotationProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (MetadataCompleteMarker.isMetadataComplete(deploymentUnit)) {
        return;
    }
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (compositeIndex == null) {
        return;
    }
    List<AnnotationInstance> applicationExceptionAnnotations = compositeIndex.getAnnotations(DotName.createSimple(ApplicationException.class.getName()));
    if (applicationExceptionAnnotations == null || applicationExceptionAnnotations.isEmpty()) {
        return;
    }
    ApplicationExceptionDescriptions descriptions = new ApplicationExceptionDescriptions();
    deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.APPLICATION_EXCEPTION_DESCRIPTIONS, descriptions);
    for (AnnotationInstance annotationInstance : applicationExceptionAnnotations) {
        AnnotationTarget target = annotationInstance.target();
        if (!(target instanceof ClassInfo)) {
            throw EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(ApplicationException.class.getName(), target);
        }
        String exceptionClassName = ((ClassInfo) target).name().toString();
        boolean rollback = false;
        AnnotationValue rollBackAnnValue = annotationInstance.value("rollback");
        if (rollBackAnnValue != null) {
            rollback = rollBackAnnValue.asBoolean();
        }
        // default "inherited" is true
        boolean inherited = true;
        AnnotationValue inheritedAnnValue = annotationInstance.value("inherited");
        if (inheritedAnnValue != null) {
            inherited = inheritedAnnValue.asBoolean();
        }
        descriptions.addApplicationException(exceptionClassName, rollback, inherited);
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) ApplicationException(javax.ejb.ApplicationException) ApplicationExceptionDescriptions(org.jboss.as.ejb3.deployment.ApplicationExceptionDescriptions) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) AnnotationValue(org.jboss.jandex.AnnotationValue) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Aggregations

AnnotationTarget (org.jboss.jandex.AnnotationTarget)18 ClassInfo (org.jboss.jandex.ClassInfo)18 AnnotationInstance (org.jboss.jandex.AnnotationInstance)16 AnnotationValue (org.jboss.jandex.AnnotationValue)7 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)6 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)6 FieldInfo (org.jboss.jandex.FieldInfo)6 MethodInfo (org.jboss.jandex.MethodInfo)6 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)4 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)4 PropertyReplacer (org.jboss.metadata.property.PropertyReplacer)4 HashSet (java.util.HashSet)3 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)2 EjbJarDescription (org.jboss.as.ejb3.deployment.EjbJarDescription)2 AbstractDeploymentUnitProcessor.getEjbJarDescription (org.jboss.as.ejb3.deployment.processors.AbstractDeploymentUnitProcessor.getEjbJarDescription)2 DotName (org.jboss.jandex.DotName)2 Module (org.jboss.modules.Module)2