Search in sources :

Example 1 with Resources

use of jakarta.annotation.Resources in project tomcat by apache.

the class WebAnnotationSet method loadClassAnnotation.

/**
 * Process the annotations on a context for a given className.
 *
 * @param context The context which will have its annotations processed
 * @param clazz The class to examine for Servlet annotations
 */
protected static void loadClassAnnotation(Context context, Class<?> clazz) {
    /* Process Resource annotation.
         * Ref JSR 250
         */
    Resource resourceAnnotation = clazz.getAnnotation(Resource.class);
    if (resourceAnnotation != null) {
        addResource(context, resourceAnnotation);
    }
    /* Process Resources annotation.
         * Ref JSR 250
         */
    Resources resourcesAnnotation = clazz.getAnnotation(Resources.class);
    if (resourcesAnnotation != null && resourcesAnnotation.value() != null) {
        for (Resource resource : resourcesAnnotation.value()) {
            addResource(context, resource);
        }
    }
    /* Process EJB annotation.
         * Ref JSR 224, equivalent to the ejb-ref or ejb-local-ref
         * element in the deployment descriptor.
        {
            EJB annotation = clazz.getAnnotation(EJB.class);
            if (annotation != null) {

                if ((annotation.mappedName().length() == 0)
                        || annotation.mappedName().equals("Local")) {

                    ContextLocalEjb ejb = new ContextLocalEjb();

                    ejb.setName(annotation.name());
                    ejb.setType(annotation.beanInterface().getCanonicalName());
                    ejb.setDescription(annotation.description());

                    ejb.setHome(annotation.beanName());

                    context.getNamingResources().addLocalEjb(ejb);

                } else if (annotation.mappedName().equals("Remote")) {

                    ContextEjb ejb = new ContextEjb();

                    ejb.setName(annotation.name());
                    ejb.setType(annotation.beanInterface().getCanonicalName());
                    ejb.setDescription(annotation.description());

                    ejb.setHome(annotation.beanName());

                    context.getNamingResources().addEjb(ejb);

                }
            }
        }
        */
    /* Process WebServiceRef annotation.
         * Ref JSR 224, equivalent to the service-ref element in
         * the deployment descriptor.
         * The service-ref registration is not implemented
        {
            WebServiceRef annotation = clazz
                    .getAnnotation(WebServiceRef.class);
            if (annotation != null) {
                ContextService service = new ContextService();

                service.setName(annotation.name());
                service.setWsdlfile(annotation.wsdlLocation());

                service.setType(annotation.type().getCanonicalName());

                if (annotation.value() == null)
                    service.setServiceinterface(annotation.type()
                            .getCanonicalName());

                if (annotation.type().getCanonicalName().equals("Service"))
                    service.setServiceinterface(annotation.type()
                            .getCanonicalName());

                if (annotation.value().getCanonicalName().equals("Endpoint"))
                    service.setServiceendpoint(annotation.type()
                            .getCanonicalName());

                service.setPortlink(annotation.type().getCanonicalName());

                context.getNamingResources().addService(service);
            }
        }
        */
    /* Process DeclareRoles annotation.
         * Ref JSR 250, equivalent to the security-role element in
         * the deployment descriptor
         */
    DeclareRoles declareRolesAnnotation = clazz.getAnnotation(DeclareRoles.class);
    if (declareRolesAnnotation != null && declareRolesAnnotation.value() != null) {
        for (String role : declareRolesAnnotation.value()) {
            context.addSecurityRole(role);
        }
    }
}
Also used : ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource) Resource(jakarta.annotation.Resource) DeclareRoles(jakarta.annotation.security.DeclareRoles) Resources(jakarta.annotation.Resources)

Aggregations

Resource (jakarta.annotation.Resource)1 Resources (jakarta.annotation.Resources)1 DeclareRoles (jakarta.annotation.security.DeclareRoles)1 ContextResource (org.apache.tomcat.util.descriptor.web.ContextResource)1