Package javax.annotation

Examples of javax.annotation.Resource


    public final void visitMethod(final Method method, final Annotation annotation) {
       
        assert annotation instanceof Resource : annotation;

        Resource res = (Resource)annotation;
       
        String resourceName = getResourceName(res, method);
        Class<?> clz = getResourceType(res, method);

        Object resource = resolveResource(resourceName, clz);
        if (resource == null
            && "".equals(res.name())) {
            resource = resolveResource(null, clz);
        }
        if (resource != null) {
            invokeSetter(method, resource);
        } else {
View Full Code Here


               
                // Initialize fields annotations
                Field[] fields = managedBean.getClass().getDeclaredFields();
                for (int i = 0; i < fields.length; i++) {
                    if (fields[i].isAnnotationPresent(Resource.class)) {
                        Resource annotation = (Resource) fields[i].getAnnotation(Resource.class);
                        lookupFieldResource(namingContext, managedBean, fields[i], annotation.name());
                    }
                    if (fields[i].isAnnotationPresent(EJB.class)) {
                        EJB annotation = (EJB) fields[i].getAnnotation(EJB.class);
                        lookupFieldResource(namingContext, managedBean, fields[i], annotation.name());
                    }
                    if (fields[i].isAnnotationPresent(WebServiceRef.class)) {
                        WebServiceRef annotation =
                            (WebServiceRef) fields[i].getAnnotation(WebServiceRef.class);
                        lookupFieldResource(namingContext, managedBean, fields[i], annotation.name());
                    }
                    if (fields[i].isAnnotationPresent(PersistenceContext.class)) {
                        PersistenceContext annotation =
                            (PersistenceContext) fields[i].getAnnotation(PersistenceContext.class);
                        lookupFieldResource(namingContext, managedBean, fields[i], annotation.name());
                    }
                    if (fields[i].isAnnotationPresent(PersistenceUnit.class)) {
                        PersistenceUnit annotation =
                            (PersistenceUnit) fields[i].getAnnotation(PersistenceUnit.class);
                        lookupFieldResource(namingContext, managedBean, fields[i], annotation.name());
                    }
                }
               
                // Initialize methods annotations
                Method[] methods = managedBean.getClass().getDeclaredMethods();
                for (int i = 0; i < methods.length; i++) {
                    if (methods[i].isAnnotationPresent(Resource.class)) {
                        Resource annotation = (Resource) methods[i].getAnnotation(Resource.class);
                        lookupMethodResource(namingContext, managedBean, methods[i], annotation.name());
                    }
                    if (methods[i].isAnnotationPresent(EJB.class)) {
                        EJB annotation = (EJB) methods[i].getAnnotation(EJB.class);
                        lookupMethodResource(namingContext, managedBean, methods[i], annotation.name());
                    }
                    if (methods[i].isAnnotationPresent(WebServiceRef.class)) {
                        WebServiceRef annotation =
                            (WebServiceRef) methods[i].getAnnotation(WebServiceRef.class);
                        lookupMethodResource(namingContext, managedBean, methods[i], annotation.name());
                    }
                    if (methods[i].isAnnotationPresent(PersistenceContext.class)) {
                        PersistenceContext annotation =
                            (PersistenceContext) methods[i].getAnnotation(PersistenceContext.class);
                        lookupMethodResource(namingContext, managedBean, methods[i], annotation.name());
                    }
                    if (methods[i].isAnnotationPresent(PersistenceUnit.class)) {
                        PersistenceUnit annotation =
                            (PersistenceUnit) methods[i].getAnnotation(PersistenceUnit.class);
                        lookupMethodResource(namingContext, managedBean, methods[i], annotation.name());
                    }
                }
               
            } catch (Exception e) {
                LOG.error("Injection failed on managed bean.", e);
View Full Code Here

         for (Resource ref : resources.value())
         {
            handleClassAnnotation(ref, container, clazz);
         }
      }
      Resource res = container.getAnnotation(Resource.class, clazz);
      if (res != null)
         handleClassAnnotation(res, container, clazz);
   }
View Full Code Here

   }

   public void handleMethodAnnotations(Method method, InjectionContainer container,
         Map<AccessibleObject, Injector> injectors)
   {
      Resource ref = container.getAnnotation(Resource.class, method);
      if (ref == null)
         return;

      log.trace("method " + method + " has @Resource");
View Full Code Here

   }

   public void handleFieldAnnotations(Field field, InjectionContainer container,
         Map<AccessibleObject, Injector> injectors)
   {
      Resource ref = container.getAnnotation(Resource.class, field);
      if (ref == null)
         return;

      log.trace("field " + field + " has @Resource");
View Full Code Here

      return context.lookup(jndiName);
   }
  
   protected String getResourceName(Field field)
   {
      Resource resource = field.getAnnotation(Resource.class);
      String resourceName = getResourceName(resource);
      if(resourceName != null)
      {
       return resourceName;
      }
View Full Code Here

            Class<?> classClass) {
        /* Process Resource annotation.
         * Ref JSR 250
         */
        {
            Resource annotation = classClass.getAnnotation(Resource.class);
            if (annotation != null) {
                addResource(context, annotation);
            }
        }
        /* Process Resources annotation.
         * Ref JSR 250
         */
        {
            Resources annotation = classClass.getAnnotation(Resources.class);
            if (annotation != null && annotation.value() != null) {
                for (Resource resource : annotation.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 annotation = classClass
                    .getAnnotation(DeclareRoles.class);
            if (annotation != null && annotation.value() != null) {
                for (String role : annotation.value()) {
                    context.addSecurityRole(role);
                }
            }
        }
    }
View Full Code Here

            Class<?> classClass) {
        // Initialize the annotations
        Field[] fields = Introspection.getDeclaredFields(classClass);
        if (fields != null && fields.length > 0) {
            for (Field field : fields) {
                Resource annotation = field.getAnnotation(Resource.class);
                if (annotation != null) {
                    String defaultName = classClass.getName() + SEPARATOR + field.getName();
                    Class<?> defaultType = field.getType();
                    addResource(context, annotation, defaultName, defaultType);
                }
View Full Code Here

            Class<?> classClass) {
        // Initialize the annotations
        Method[] methods = Introspection.getDeclaredMethods(classClass);
        if (methods != null && methods.length > 0) {
            for (Method method : methods) {
                Resource annotation = method.getAnnotation(Resource.class);
                if (annotation != null) {
                    if (!Introspection.isValidSetter(method)) {
                        throw new IllegalArgumentException(sm.getString(
                                "webAnnotationSet.invalidInjection"));
                    }
View Full Code Here

        List<Method> methodswithResource = classFinder.findAnnotatedMethods(Resource.class);
        List<Field> fieldswithResource = classFinder.findAnnotatedFields(Resource.class);

        // Class-level annotation
        for (Class cls : classeswithResource) {
            Resource resource = (Resource) cls.getAnnotation(Resource.class);
            if (resource != null) {
                resourceProcessor.processResource(annotatedApp, resource, cls, null, null);
            }
        }

        // Method-level annotation
        for (Method method : methodswithResource) {
            Resource resource = (Resource) method.getAnnotation(Resource.class);
            if (resource != null) {
                resourceProcessor.processResource(annotatedApp, resource, null, method, null);
            }
        }

        // Field-level annotation
        for (Field field : fieldswithResource) {
            Resource resource = (Resource) field.getAnnotation(Resource.class);
            if (resource != null) {
                resourceProcessor.processResource(annotatedApp, resource, null, null, field);
            }
        }
View Full Code Here

TOP

Related Classes of javax.annotation.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.