Package javax.annotation

Examples of javax.annotation.Resource


        Field[] fields = instance.getClass().getDeclaredFields();
        for (Field field : fields) {
            if (injections != null && injections.containsKey(field.getName())) {
                lookupFieldResource(context, instance, field, injections.get(field.getName()));
            } else if (field.isAnnotationPresent(Resource.class)) {
                Resource annotation = field.getAnnotation(Resource.class);
                lookupFieldResource(context, instance, field, annotation.name());
            } else if (field.isAnnotationPresent(EJB.class)) {
                EJB annotation = field.getAnnotation(EJB.class);
                lookupFieldResource(context, instance, field, annotation.name());
            } else if (field.isAnnotationPresent(WebServiceRef.class)) {
                WebServiceRef annotation =
                        field.getAnnotation(WebServiceRef.class);
                lookupFieldResource(context, instance, field, annotation.name());
            } else if (field.isAnnotationPresent(PersistenceContext.class)) {
                PersistenceContext annotation =
                        field.getAnnotation(PersistenceContext.class);
                lookupFieldResource(context, instance, field, annotation.name());
            } else if (field.isAnnotationPresent(PersistenceUnit.class)) {
                PersistenceUnit annotation =
                        field.getAnnotation(PersistenceUnit.class);
                lookupFieldResource(context, instance, field, annotation.name());
            }
        }

        // Initialize methods annotations
        Method[] methods = instance.getClass().getDeclaredMethods();
        for (Method method : methods) {
            String methodName = method.getName();
            if (injections != null && methodName.startsWith("set") && methodName.length() > 3) {
                String fieldName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4);
                if (injections.containsKey(fieldName)) {
                    lookupMethodResource(context, instance, method, injections.get(fieldName));
                    break;
                }
            }
            if (method.isAnnotationPresent(Resource.class)) {
                Resource annotation = method.getAnnotation(Resource.class);
                lookupMethodResource(context, instance, method, annotation.name());
            } else if (method.isAnnotationPresent(EJB.class)) {
                EJB annotation = method.getAnnotation(EJB.class);
                lookupMethodResource(context, instance, method, annotation.name());
            } else if (method.isAnnotationPresent(WebServiceRef.class)) {
                WebServiceRef annotation =
                        method.getAnnotation(WebServiceRef.class);
                lookupMethodResource(context, instance, method, annotation.name());
            } else if (method.isAnnotationPresent(PersistenceContext.class)) {
                PersistenceContext annotation =
                        method.getAnnotation(PersistenceContext.class);
                lookupMethodResource(context, instance, method, annotation.name());
            } else if (method.isAnnotationPresent(PersistenceUnit.class)) {
                PersistenceUnit annotation =
                        method.getAnnotation(PersistenceUnit.class);
                lookupMethodResource(context, instance, method, annotation.name());
            }
        }

    }
View Full Code Here


            for (final Annotated<Class<?>> clazz : annotationFinder.findMetaAnnotatedClasses(Resources.class)) {
                final Resources resources = clazz.getAnnotation(Resources.class);
                resourceList.addAll(Arrays.asList(resources.value()));
            }
            for (final Annotated<Class<?>> clazz : annotationFinder.findMetaAnnotatedClasses(Resource.class)) {
                final Resource resource = clazz.getAnnotation(Resource.class);
                resourceList.add(resource);
            }

            for (final Resource resource : resourceList) {
                buildResource(consumer, resource, null);
            }

            for (final Annotated<Field> field : annotationFinder.findMetaAnnotatedFields(Resource.class)) {
                final Resource resource = field.getAnnotation(Resource.class);

                final Member member = new FieldMember(field.get());

                buildResource(consumer, resource, member);
            }

            for (final Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(Resource.class)) {
                final Resource resource = method.getAnnotation(Resource.class);

                final Member member = new MethodMember(method.get());

                buildResource(consumer, resource, member);
            }
View Full Code Here

        while (clazz != null) {
            // Initialize fields annotations
            Field[] fields = clazz.getDeclaredFields();
            for (int i = 0; i < fields.length; i++) {
                if (fields[i].isAnnotationPresent(Resource.class)) {
                    Resource annotation =
                            fields[i].getAnnotation(Resource.class);
                    lookupFieldResource(context, instance, fields[i],
                            annotation.name(), clazz);
                }
                if (fields[i].isAnnotationPresent(EJB.class)) {
                    EJB annotation = fields[i].getAnnotation(EJB.class);
                    lookupFieldResource(context, instance, fields[i],
                            annotation.name(), clazz);
                }
                if (fields[i].isAnnotationPresent(WebServiceRef.class)) {
                    WebServiceRef annotation =
                            fields[i].getAnnotation(WebServiceRef.class);
                    lookupFieldResource(context, instance, fields[i],
                            annotation.name(), clazz);
                }
                if (fields[i].isAnnotationPresent(PersistenceContext.class)) {
                    PersistenceContext annotation =
                            fields[i].getAnnotation(PersistenceContext.class);
                    lookupFieldResource(context, instance, fields[i],
                            annotation.name(), clazz);
                }
                if (fields[i].isAnnotationPresent(PersistenceUnit.class)) {
                    PersistenceUnit annotation =
                            fields[i].getAnnotation(PersistenceUnit.class);
                    lookupFieldResource(context, instance, fields[i],
                            annotation.name(), clazz);
                }
            }

            // Initialize methods annotations
            Method[] methods = clazz.getDeclaredMethods();

            for (int i = 0; i < methods.length; i++) {
                if (methods[i].isAnnotationPresent(Resource.class)) {
                    Resource annotation = methods[i].getAnnotation(Resource.class);
                    lookupMethodResource(context, instance, methods[i],
                            annotation.name(), clazz);
                }
                if (methods[i].isAnnotationPresent(EJB.class)) {
                    EJB annotation = methods[i].getAnnotation(EJB.class);
                    lookupMethodResource(context, instance, methods[i],
                            annotation.name(), clazz);
                }
                if (methods[i].isAnnotationPresent(WebServiceRef.class)) {
                    WebServiceRef annotation =
                            methods[i].getAnnotation(WebServiceRef.class);
                    lookupMethodResource(context, instance, methods[i],
                            annotation.name(), clazz);
                }
                if (methods[i].isAnnotationPresent(PersistenceContext.class)) {
                    PersistenceContext annotation =
                            methods[i].getAnnotation(PersistenceContext.class);
                    lookupMethodResource(context, instance, methods[i],
                            annotation.name(), clazz);
                }
                if (methods[i].isAnnotationPresent(PersistenceUnit.class)) {
                    PersistenceUnit annotation =
                            methods[i].getAnnotation(PersistenceUnit.class);
                    lookupMethodResource(context, instance, methods[i],
                            annotation.name(), clazz);
                }
            }

            clazz = clazz.getSuperclass();
        }
View Full Code Here

            }
            RouteType routeType = (routing == null) ? RouteType.BOTH : routing.value();
            Route route = new RouteImpl(routeType).id(routeId);
            boolean isResourced = m.isAnnotationPresent(Resource.class);
            if (isResourced) {
                Resource r = m.getAnnotation(Resource.class);
                log.debug("Loading resource " + r.mappedName());
                route.addDestinationJndiName(r.mappedName());
            }

            /* in this case, each method has one non destination and multiple
             * destinations.  this can take the form of resources or qualified
             * resources.
 
View Full Code Here

                            annotations.add(new AnnotationCacheEntry(
                                    field.getName(), null,
                                    injections.get(field.getName()),
                                    AnnotationCacheEntryType.FIELD));
                        } else if (field.isAnnotationPresent(Resource.class)) {
                            Resource annotation = field.getAnnotation(Resource.class);
                            annotations.add(new AnnotationCacheEntry(
                                    field.getName(), null, annotation.name(),
                                    AnnotationCacheEntryType.FIELD));
                        } else if (field.isAnnotationPresent(EJB.class)) {
                            EJB annotation = field.getAnnotation(EJB.class);
                            annotations.add(new AnnotationCacheEntry(
                                    field.getName(), null, annotation.name(),
                                    AnnotationCacheEntryType.FIELD));
                        } else if (field.isAnnotationPresent(WebServiceRef.class)) {
                            WebServiceRef annotation =
                                    field.getAnnotation(WebServiceRef.class);
                            annotations.add(new AnnotationCacheEntry(
                                    field.getName(), null, annotation.name(),
                                    AnnotationCacheEntryType.FIELD));
                        } else if (field.isAnnotationPresent(PersistenceContext.class)) {
                            PersistenceContext annotation =
                                    field.getAnnotation(PersistenceContext.class);
                            annotations.add(new AnnotationCacheEntry(
                                    field.getName(), null, annotation.name(),
                                    AnnotationCacheEntryType.FIELD));
                        } else if (field.isAnnotationPresent(PersistenceUnit.class)) {
                            PersistenceUnit annotation =
                                    field.getAnnotation(PersistenceUnit.class);
                            annotations.add(new AnnotationCacheEntry(
                                    field.getName(), null, annotation.name(),
                                    AnnotationCacheEntryType.FIELD));
                        }
                    }
                }

                // Initialize methods annotations
                Method[] methods = Introspection.getDeclaredMethods(clazz);
                Method postConstruct = null;
                String postConstructFromXml = postConstructMethods.get(clazz.getName());
                Method preDestroy = null;
                String preDestroyFromXml = preDestroyMethods.get(clazz.getName());
                for (Method method : methods) {
                    if (context != null) {
                        // Resource injection only if JNDI is enabled
                        if (injections != null &&
                                Introspection.isValidSetter(method)) {
                            String fieldName = Introspection.getPropertyName(method);
                            if (injections.containsKey(fieldName)) {
                                annotations.add(new AnnotationCacheEntry(
                                        method.getName(),
                                        method.getParameterTypes(),
                                        injections.get(fieldName),
                                        AnnotationCacheEntryType.SETTER));
                                continue;
                            }
                        }
                        if (method.isAnnotationPresent(Resource.class)) {
                            Resource annotation = method.getAnnotation(Resource.class);
                            annotations.add(new AnnotationCacheEntry(
                                    method.getName(),
                                    method.getParameterTypes(),
                                    annotation.name(),
                                    AnnotationCacheEntryType.SETTER));
                        } else if (method.isAnnotationPresent(EJB.class)) {
                            EJB annotation = method.getAnnotation(EJB.class);
                            annotations.add(new AnnotationCacheEntry(
                                    method.getName(),
                                    method.getParameterTypes(),
                                    annotation.name(),
                                    AnnotationCacheEntryType.SETTER));
                        } else if (method.isAnnotationPresent(WebServiceRef.class)) {
                            WebServiceRef annotation =
                                    method.getAnnotation(WebServiceRef.class);
                            annotations.add(new AnnotationCacheEntry(
                                    method.getName(),
                                    method.getParameterTypes(),
                                    annotation.name(),
                                    AnnotationCacheEntryType.SETTER));
                        } else if (method.isAnnotationPresent(PersistenceContext.class)) {
                            PersistenceContext annotation =
                                    method.getAnnotation(PersistenceContext.class);
                            annotations.add(new AnnotationCacheEntry(
                                    method.getName(),
                                    method.getParameterTypes(),
                                    annotation.name(),
                                    AnnotationCacheEntryType.SETTER));
                        } else if (method.isAnnotationPresent(PersistenceUnit.class)) {
                            PersistenceUnit annotation =
                                    method.getAnnotation(PersistenceUnit.class);
                            annotations.add(new AnnotationCacheEntry(
                                    method.getName(),
                                    method.getParameterTypes(),
                                    annotation.name(),
                                    AnnotationCacheEntryType.SETTER));
                        }
                    }

                    postConstruct = findPostConstruct(postConstruct, postConstructFromXml, method);
View Full Code Here

            for (Annotated<Class<?>> clazz : annotationFinder.findMetaAnnotatedClasses(Resources.class)) {
                Resources resources = clazz.getAnnotation(Resources.class);
                resourceList.addAll(asList(resources.value()));
            }
            for (Annotated<Class<?>> clazz : annotationFinder.findMetaAnnotatedClasses(Resource.class)) {
                Resource resource = clazz.getAnnotation(Resource.class);
                resourceList.add(resource);
            }

            for (Resource resource : resourceList) {
                buildResource(consumer, resource, null);
            }

            for (Annotated<Field> field : annotationFinder.findMetaAnnotatedFields(Resource.class)) {
                Resource resource = field.getAnnotation(Resource.class);

                Member member = new FieldMember(field.get());

                buildResource(consumer, resource, member);
            }

            for (Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(Resource.class)) {
                Resource resource = method.getAnnotation(Resource.class);

                Member member = new MethodMember(method.get());

                buildResource(consumer, resource, member);
            }
View Full Code Here

            for (Class<?> clazz : classFinder.findAnnotatedClasses(Resources.class)) {
                Resources resources = clazz.getAnnotation(Resources.class);
                resourceList.addAll(asList(resources.value()));
            }
            for (Class<?> clazz : classFinder.findAnnotatedClasses(Resource.class)) {
                Resource resource = clazz.getAnnotation(Resource.class);
                resourceList.add(resource);
            }

            for (Resource resource : resourceList) {
                buildResource(consumer, resource, null);
            }

            for (Field field : classFinder.findAnnotatedFields(Resource.class)) {
                Resource resource = field.getAnnotation(Resource.class);

                Member member = new FieldMember(field);

                buildResource(consumer, resource, member);
            }

            for (Method method : classFinder.findAnnotatedMethods(Resource.class)) {
                Resource resource = method.getAnnotation(Resource.class);

                Member member = new MethodMember(method);

                buildResource(consumer, resource, member);
            }
View Full Code Here

    @Override
    public <X, T extends Annotation> X getResourceReference(ResourceReference<X, T> resourceReference)
    {       
        if(resourceReference.supports(Resource.class))
        {        
            Resource resource = resourceReference.getAnnotation(Resource.class);
            return processor.getResource(resource, resourceReference.getResourceType());
        }

        if(resourceReference.supports(WebServiceRef.class))
        {        
View Full Code Here

            return null;
        }
       
        if(resourceReference.supports(Resource.class))
        {
            Resource annotation = resourceReference.getAnnotation(Resource.class);
            String name = annotation.name();
            if(name == null || name.equals(""))
            {
                name = resourceReference.getOwnerClass() + "/" + resourceReference.getName();
            }
           
            resource= lookupFieldResource(context, "openejb/Resource/"+name, resourceReference.getResourceType());
        }
        else if(resourceReference.supports(EJB.class))
        {
            EJB annotation = resourceReference.getAnnotation(EJB.class);
                       
            String intf = null;
            if(annotation.beanInterface() != null
                    && annotation.beanInterface() != Object.class
                    && !annotation.beanInterface().equals(""))
            {
                intf = annotation.beanInterface().getName();
            }
           
            if(intf == null)
            {
                intf = resourceReference.getResourceType().getName();
            }
           
            if(intf == null &&  annotation.beanName() == null)
            {
                if(logger.wblWillLogWarn())
                {
                    logger.warn("To inject @EJBs into the managed beans you have to give @EJB(beanName), " +
                            "trying to get inject with @EJB(name) where name is the internal JNDI name of the OpenEJB Bean");
                }
               
                String name = annotation.name();
                if(name == null || name.equals(""))
                {
                    name = resourceReference.getOwnerClass() + "/" + resourceReference.getName();
                }               
            
                resource = lookupFieldResource(context, "openejb/Deployment/"+ name, resourceReference.getResourceType());               
            }           
            else
            {
                EjbPlugin plugin =(EjbPlugin) PluginLoader.getInstance().getEjbPlugin();
                return plugin.getEjbInstance(intf, resourceReference.getResourceType());               
            }
        }
        else if(resourceReference.supports(WebServiceRef.class))
        {
            WebServiceRef annotation = resourceReference.getAnnotation(WebServiceRef.class);
            String name = annotation.name();
            if(name == null || name.equals(""))
            {
                name = resourceReference.getOwnerClass() + "/" + resourceReference.getName();
            }           
            resource = lookupFieldResource(context, name, resourceReference.getResourceType());
        }
        else if(resourceReference.supports(PersistenceUnit.class))
        {
            PersistenceUnit annotation = resourceReference.getAnnotation(PersistenceUnit.class);
            resource = getPersistenceUnit(context, annotation.unitName(), resourceReference.getResourceType());
        }
        else if(resourceReference.supports(PersistenceContext.class))
        {
            PersistenceContext annotation = resourceReference.getAnnotation(PersistenceContext.class);
            resource = getPersistenceContext(context, annotation.unitName(), resourceReference.getResourceType());
        }
       
        return resource;
    }
View Full Code Here

                            annotations.add(new AnnotationCacheEntry(
                                    field.getName(), null,
                                    injections.get(field.getName()),
                                    AnnotationCacheEntryType.FIELD));
                        } else if (field.isAnnotationPresent(Resource.class)) {
                            Resource annotation = field.getAnnotation(Resource.class);
                            annotations.add(new AnnotationCacheEntry(
                                    field.getName(), null, annotation.name(),
                                    AnnotationCacheEntryType.FIELD));
                        } else if (field.isAnnotationPresent(EJB.class)) {
                            EJB annotation = field.getAnnotation(EJB.class);
                            annotations.add(new AnnotationCacheEntry(
                                    field.getName(), null, annotation.name(),
                                    AnnotationCacheEntryType.FIELD));
                        } else if (field.isAnnotationPresent(WebServiceRef.class)) {
                            WebServiceRef annotation =
                                    field.getAnnotation(WebServiceRef.class);
                            annotations.add(new AnnotationCacheEntry(
                                    field.getName(), null, annotation.name(),
                                    AnnotationCacheEntryType.FIELD));
                        } else if (field.isAnnotationPresent(PersistenceContext.class)) {
                            PersistenceContext annotation =
                                    field.getAnnotation(PersistenceContext.class);
                            annotations.add(new AnnotationCacheEntry(
                                    field.getName(), null, annotation.name(),
                                    AnnotationCacheEntryType.FIELD));
                        } else if (field.isAnnotationPresent(PersistenceUnit.class)) {
                            PersistenceUnit annotation =
                                    field.getAnnotation(PersistenceUnit.class);
                            annotations.add(new AnnotationCacheEntry(
                                    field.getName(), null, annotation.name(),
                                    AnnotationCacheEntryType.FIELD));
                        }
                    }
                }

                // Initialize methods annotations
                Method[] methods = Introspection.getDeclaredMethods(clazz);
                Method postConstruct = null;
                String postConstructFromXml = postConstructMethods.get(clazz.getName());
                Method preDestroy = null;
                String preDestroyFromXml = preDestroyMethods.get(clazz.getName());
                for (Method method : methods) {
                    if (context != null) {
                        // Resource injection only if JNDI is enabled
                        if (injections != null &&
                                Introspection.isValidSetter(method)) {
                            String fieldName = Introspection.getPropertyName(method);
                            if (injections.containsKey(fieldName)) {
                                annotations.add(new AnnotationCacheEntry(
                                        method.getName(),
                                        method.getParameterTypes(),
                                        injections.get(fieldName),
                                        AnnotationCacheEntryType.SETTER));
                                continue;
                            }
                        }
                        if (method.isAnnotationPresent(Resource.class)) {
                            Resource annotation = method.getAnnotation(Resource.class);
                            annotations.add(new AnnotationCacheEntry(
                                    method.getName(),
                                    method.getParameterTypes(),
                                    annotation.name(),
                                    AnnotationCacheEntryType.SETTER));
                        } else if (method.isAnnotationPresent(EJB.class)) {
                            EJB annotation = method.getAnnotation(EJB.class);
                            annotations.add(new AnnotationCacheEntry(
                                    method.getName(),
                                    method.getParameterTypes(),
                                    annotation.name(),
                                    AnnotationCacheEntryType.SETTER));
                        } else if (method.isAnnotationPresent(WebServiceRef.class)) {
                            WebServiceRef annotation =
                                    method.getAnnotation(WebServiceRef.class);
                            annotations.add(new AnnotationCacheEntry(
                                    method.getName(),
                                    method.getParameterTypes(),
                                    annotation.name(),
                                    AnnotationCacheEntryType.SETTER));
                        } else if (method.isAnnotationPresent(PersistenceContext.class)) {
                            PersistenceContext annotation =
                                    method.getAnnotation(PersistenceContext.class);
                            annotations.add(new AnnotationCacheEntry(
                                    method.getName(),
                                    method.getParameterTypes(),
                                    annotation.name(),
                                    AnnotationCacheEntryType.SETTER));
                        } else if (method.isAnnotationPresent(PersistenceUnit.class)) {
                            PersistenceUnit annotation =
                                    method.getAnnotation(PersistenceUnit.class);
                            annotations.add(new AnnotationCacheEntry(
                                    method.getName(),
                                    method.getParameterTypes(),
                                    annotation.name(),
                                    AnnotationCacheEntryType.SETTER));
                        }
                    }

                    postConstruct = findPostConstruct(postConstruct, postConstructFromXml, method);
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.