Search in sources :

Example 1 with Resources

use of javax.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 classClass The class to examine for Servlet annotations
     */
protected static void loadClassAnnotation(Context context, Class<?> classClass) {
    /* Process Resource annotation.
         * Ref JSR 250
         */
    Resource resourceAnnotation = classClass.getAnnotation(Resource.class);
    if (resourceAnnotation != null) {
        addResource(context, resourceAnnotation);
    }
    /* Process Resources annotation.
         * Ref JSR 250
         */
    Resources resourcesAnnotation = classClass.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 = classClass.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 = classClass
                    .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 = classClass.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(javax.annotation.Resource) DeclareRoles(javax.annotation.security.DeclareRoles) Resources(javax.annotation.Resources)

Example 2 with Resources

use of javax.annotation.Resources in project jetty.project by eclipse.

the class ResourcesAnnotationHandler method doHandle.

public void doHandle(Class<?> clazz) {
    Resources resources = (Resources) clazz.getAnnotation(Resources.class);
    if (resources != null) {
        Resource[] resArray = resources.value();
        if (resArray == null || resArray.length == 0) {
            LOG.warn("Skipping empty or incorrect Resources annotation on " + clazz.getName());
            return;
        }
        for (int j = 0; j < resArray.length; j++) {
            String name = resArray[j].name();
            String mappedName = resArray[j].mappedName();
            if (name == null || name.trim().equals(""))
                throw new IllegalStateException("Class level Resource annotations must contain a name (Common Annotations Spec Section 2.3)");
            try {
                if (!org.eclipse.jetty.plus.jndi.NamingEntryUtil.bindToENC(_wac, name, mappedName))
                    if (!org.eclipse.jetty.plus.jndi.NamingEntryUtil.bindToENC(_wac.getServer(), name, mappedName))
                        LOG.warn("Skipping Resources(Resource) annotation on " + clazz.getName() + " for name " + name + ": No resource bound at " + (mappedName == null ? name : mappedName));
            } catch (NamingException e) {
                LOG.warn(e);
            }
        }
    }
}
Also used : Resource(javax.annotation.Resource) NamingException(javax.naming.NamingException) Resources(javax.annotation.Resources)

Aggregations

Resource (javax.annotation.Resource)2 Resources (javax.annotation.Resources)2 DeclareRoles (javax.annotation.security.DeclareRoles)1 NamingException (javax.naming.NamingException)1 ContextResource (org.apache.tomcat.util.descriptor.web.ContextResource)1