Package javax.annotation

Examples of javax.annotation.Resource


     */
    protected static void loadClassAnnotation(Context context,
            Class<?> classClass) {
        // Initialize the annotations
        if (classClass.isAnnotationPresent(Resource.class)) {
            Resource annotation = classClass.getAnnotation(Resource.class);
            addResource(context, annotation);
        }
        /* Process Resources annotation.
         * Ref JSR 250
         */
        if (classClass.isAnnotationPresent(Resources.class)) {
            Resources annotation = classClass.getAnnotation(Resources.class);
            for (int i = 0; annotation.value() != null && i < annotation.value().length; i++) {
                addResource(context, annotation.value()[i]);
            }
        }
        /* Process EJB annotation.
         * Ref JSR 224, equivalent to the ejb-ref or ejb-local-ref
         * element in the deployment descriptor.
        if (classClass.isAnnotationPresent(EJB.class)) {
            EJB annotation = (EJB)
            classClass.getAnnotation(EJB.class);

            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
        if (classClass.isAnnotationPresent(WebServiceRef.class)) {
            WebServiceRef annotation = (WebServiceRef)
            classClass.getAnnotation(WebServiceRef.class);

            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
         */
        if (classClass.isAnnotationPresent(DeclareRoles.class)) {
            DeclareRoles annotation =
                classClass.getAnnotation(DeclareRoles.class);
            for (int i = 0; annotation.value() != null && i < annotation.value().length; i++) {
                context.addSecurityRole(annotation.value()[i]);
            }
        }
    }
View Full Code Here


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

        // Initialize the annotations
        Method[] methods = Introspection.getDeclaredMethods(classClass);
        if (methods != null && methods.length > 0) {
            for (Method method : methods) {
                if (method.isAnnotationPresent(Resource.class)) {
                    Resource annotation = method.getAnnotation(Resource.class);

                    if (!Introspection.isValidSetter(method)) {
                        throw new IllegalArgumentException(sm.getString(
                                "webAnnotationSet.invalidInjection"));
                    }
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

    protected void checkFieldAnnotation(Field field, Object instance)
            throws NamingException, IllegalAccessException
    {
        if (field.isAnnotationPresent(Resource.class))
        {
            Resource annotation = field.getAnnotation(Resource.class);
            lookupFieldResource(context, instance, field, annotation.name());
        }
    }
View Full Code Here

            throws NamingException, IllegalAccessException, InvocationTargetException
    {
        super.checkMethodAnnotation(method, instance);
        if (method.isAnnotationPresent(Resource.class))
        {
            Resource annotation =  method.getAnnotation(Resource.class);
            lookupMethodResource(context, instance, method, annotation.name());
        }
        if (method.isAnnotationPresent(EJB.class))
        {
            EJB annotation =  method.getAnnotation(EJB.class);
            lookupMethodResource(context, instance, method, annotation.name());
        }
        // TODO where i find WebServiceRef?
        /*if (method.isAnnotationPresent(WebServiceRef.class)) {
            WebServiceRef annotation =
                (WebServiceRef) method.getAnnotation(WebServiceRef.class);
            lookupMethodResource(context, instance, methods, annotation.name());
        }*/
        if (method.isAnnotationPresent(PersistenceContext.class))
        {
            PersistenceContext annotation = method.getAnnotation(PersistenceContext.class);
            lookupMethodResource(context, instance, method, annotation.name());
        }
        if (method.isAnnotationPresent(PersistenceUnit.class))
        {
            PersistenceUnit annotation = method.getAnnotation(PersistenceUnit.class);
            lookupMethodResource(context, instance, method, annotation.name());
        }
    }
View Full Code Here

      super(member, pd);
      initAnnotation((AnnotatedElement) member);
    }

    protected void initAnnotation(AnnotatedElement ae) {
      Resource resource = ae.getAnnotation(Resource.class);
      String resourceName = resource.name();
      Class resourceType = resource.type();
      this.isDefaultName = !StringUtils.hasLength(resourceName);
      if (this.isDefaultName) {
        resourceName = this.member.getName();
        if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) {
          resourceName = Introspector.decapitalize(resourceName.substring(3));
        }
      }
      if (resourceType != null && !Object.class.equals(resourceType)) {
        checkResourceType(resourceType);
      }
      else {
        // No resource type specified... check field/method.
        resourceType = getResourceType();
      }
      this.name = resourceName;
      this.lookupType = resourceType;
      this.mappedName = resource.mappedName();
      this.shareable = resource.shareable();
    }
View Full Code Here

      super(member, pd);
    }

    @Override
    protected void initAnnotation(AnnotatedElement ae) {
      Resource resource = ae.getAnnotation(Resource.class);
      String resourceName = resource.name();
      Class<?> resourceType = resource.type();
      this.isDefaultName = !StringUtils.hasLength(resourceName);
      if (this.isDefaultName) {
        resourceName = this.member.getName();
        if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) {
          resourceName = Introspector.decapitalize(resourceName.substring(3));
        }
      }
      else if (beanFactory instanceof ConfigurableBeanFactory){
        resourceName = ((ConfigurableBeanFactory) beanFactory).resolveEmbeddedValue(resourceName);
      }
      if (resourceType != null && !Object.class.equals(resourceType)) {
        checkResourceType(resourceType);
      }
      else {
        // No resource type specified... check field/method.
        resourceType = getResourceType();
      }
      this.name = resourceName;
      this.lookupType = resourceType;
      this.mappedName = resource.mappedName();
      this.shareable = resource.shareable();
    }
View Full Code Here

      super(member, pd);
    }

    @Override
    protected void initAnnotation(AnnotatedElement ae) {
      Resource resource = ae.getAnnotation(Resource.class);
      String resourceName = resource.name();
      Class<?> resourceType = resource.type();
      this.isDefaultName = !StringUtils.hasLength(resourceName);
      if (this.isDefaultName) {
        resourceName = this.member.getName();
        if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) {
          resourceName = Introspector.decapitalize(resourceName.substring(3));
        }
      }
      else if (beanFactory instanceof ConfigurableBeanFactory){
        resourceName = ((ConfigurableBeanFactory) beanFactory).resolveEmbeddedValue(resourceName);
      }
      if (resourceType != null && !Object.class.equals(resourceType)) {
        checkResourceType(resourceType);
      }
      else {
        // No resource type specified... check field/method.
        resourceType = getResourceType();
      }
      this.name = resourceName;
      this.lookupType = resourceType;
      this.mappedName = resource.mappedName();
      this.shareable = resource.shareable();
    }
View Full Code Here

    public ResourceElement(Member member, PropertyDescriptor pd) {
      super(member, pd);
    }

    protected void initAnnotation(AnnotatedElement ae) {
      Resource resource = ae.getAnnotation(Resource.class);
      String resourceName = resource.name();
      Class resourceType = resource.type();
      this.isDefaultName = !StringUtils.hasLength(resourceName);
      if (this.isDefaultName) {
        resourceName = this.member.getName();
        if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) {
          resourceName = Introspector.decapitalize(resourceName.substring(3));
        }
      }
      if (resourceType != null && !Object.class.equals(resourceType)) {
        checkResourceType(resourceType);
      }
      else {
        // No resource type specified... check field/method.
        resourceType = getResourceType();
      }
      this.name = resourceName;
      this.lookupType = resourceType;
      this.mappedName = resource.mappedName();
      this.shareable = resource.shareable();
    }
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.