Package javax.annotation

Examples of javax.annotation.Resource


    public static final String ABSOLUTE_JNDI_NAME = "java:comp/" + RELATIVE_JNDI_NAME;
   
    public static void addWebServiceContextInjections(Holder holder, ClassFinder finder) {       
        List<Field> fields = finder.findAnnotatedFields(Resource.class);
        for (Field field : fields) {
            Resource resource = (Resource) field.getAnnotation(Resource.class);
            Class type = getInjectionType(resource.type(), null, field);
            if (WebServiceContext.class == type) {
                holder.addInjection(field.getDeclaringClass().getName(),
                                    new Injection(field.getDeclaringClass().getName(), getInjectionName(null, field), ABSOLUTE_JNDI_NAME));
            }
        }
        List<Method> methods = finder.findAnnotatedMethods(Resource.class);
        for (Method method : methods) {
            Resource resource = (Resource) method.getAnnotation(Resource.class);
            Class type = getInjectionType(resource.type(), method, null);
            if (WebServiceContext.class == type) {
                holder.addInjection(method.getDeclaringClass().getName(),
                                    new Injection(method.getDeclaringClass().getName(), getInjectionName(method, null), ABSOLUTE_JNDI_NAME));
            }           
        }
View Full Code Here


            }
        }

        for ( Field field : methods.fieldsFor(Resource.class) )
        {
            Resource resource = field.getAnnotation(Resource.class);
            setFieldResource(obj, field, resource);
        }

        for ( Method method : methods.methodsFor(Resources.class) )
        {
            Resources resources = method.getAnnotation(Resources.class);
            for ( Resource resource : resources.value() )
            {
                setMethodResource(obj, method, resource);
            }
        }

        for ( Method method : methods.methodsFor(Resource.class) )
        {
            Resource resource = method.getAnnotation(Resource.class);
            setMethodResource(obj, method, resource);
        }

        for ( Resources resources : methods.classAnnotationsFor(Resources.class) )
        {
View Full Code Here

        field.set(obj, resourceObj);
    }

    private Resource adjustResource(final Resource resource, final Class siteType, final String siteName)
    {
        return new Resource()
        {
            @Override
            public String name()
            {
                return (resource.name().length() == 0) ? siteName : resource.name();
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

        while (clazz != null) {
            // Initialize fields annotations
            Field[] fields = instance.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(context, instance, fields[i], annotation.name());
                }
                if (fields[i].isAnnotationPresent(EJB.class)) {
                    EJB annotation = (EJB) fields[i].getAnnotation(EJB.class);
                    lookupFieldResource(context, instance, fields[i], annotation.name());
                }
                if (fields[i].isAnnotationPresent(WebServiceRef.class)) {
                    WebServiceRef annotation =
                        (WebServiceRef) fields[i].getAnnotation(WebServiceRef.class);
                    lookupFieldResource(context, instance, fields[i], annotation.name());
                }
                if (fields[i].isAnnotationPresent(PersistenceContext.class)) {
                    PersistenceContext annotation =
                        (PersistenceContext) fields[i].getAnnotation(PersistenceContext.class);
                    lookupFieldResource(context, instance, fields[i], annotation.name());
                }
                if (fields[i].isAnnotationPresent(PersistenceUnit.class)) {
                    PersistenceUnit annotation =
                        (PersistenceUnit) fields[i].getAnnotation(PersistenceUnit.class);
                    lookupFieldResource(context, instance, fields[i], annotation.name());
                }
            }
           
            // Initialize methods annotations
            Method[] methods = instance.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(context, instance, methods[i], annotation.name());
                }
                if (methods[i].isAnnotationPresent(EJB.class)) {
                    EJB annotation = (EJB) methods[i].getAnnotation(EJB.class);
                    lookupMethodResource(context, instance, methods[i], annotation.name());
                }
                if (methods[i].isAnnotationPresent(WebServiceRef.class)) {
                    WebServiceRef annotation =
                        (WebServiceRef) methods[i].getAnnotation(WebServiceRef.class);
                    lookupMethodResource(context, instance, methods[i], annotation.name());
                }
                if (methods[i].isAnnotationPresent(PersistenceContext.class)) {
                    PersistenceContext annotation =
                        (PersistenceContext) methods[i].getAnnotation(PersistenceContext.class);
                    lookupMethodResource(context, instance, methods[i], annotation.name());
                }
                if (methods[i].isAnnotationPresent(PersistenceUnit.class)) {
                    PersistenceUnit annotation =
                        (PersistenceUnit) methods[i].getAnnotation(PersistenceUnit.class);
                    lookupMethodResource(context, instance, methods[i], annotation.name());
                }
            }
           
            clazz = clazz.getSuperclass();
        }
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

      super(finder);
   }
  
   public void process(RemoteEnvironmentRefsGroupMetaData refs, E element)
   {
      Resource annotation = finder.getAnnotation(element, Resource.class);
      if(annotation == null)
         return;
      process(refs, element, annotation);
   }
View Full Code Here

        return context;
    }

    @Override
    protected String getResourceName(InjectionPoint injectionPoint) {
        Resource resource = injectionPoint.getAnnotated().getAnnotation(Resource.class);
        String mappedName = resource.mappedName();
        String lookup = resource.lookup();
        if (!lookup.isEmpty()) {
            return lookup;
        }
        if (!mappedName.isEmpty()) {
            return mappedName;
View Full Code Here

      super(finder);
   }
  
   public void process(EnvironmentRefsGroupMetaData refs, E element)
   {
      Resource annotation = finder.getAnnotation(element, Resource.class);
      if(annotation == null)
         return;
      process(refs, element, annotation);
   }
View Full Code Here

    public final void visitField(final Field field, final Annotation annotation) {

        assert annotation instanceof Resource : annotation;
       
        Resource res = (Resource)annotation;

        String name = getFieldNameForResource(res, field);
        Class<?> type = getResourceType(res, field);
       
        Object resource = resolveResource(name, type);
        if (resource == null
            && "".equals(res.name())) {
            resource = resolveResource(null, type);
        }
        if (resource != null) {
            injectField(field, resource);
        } else {
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.