Package org.oasisopen.sca.annotation

Examples of org.oasisopen.sca.annotation.Reference


            reference.setAllowsPassByReference(implementation.isAllowsPassByReference());
        }

        // reference.setMember((Member)element.getAnchor());
        boolean required = true;
        Reference ref = element.getAnnotation(Reference.class);
        if (ref != null) {
            required = ref.required();
        }
        // reference.setRequired(required);
        reference.setName(name);
        Class<?> rawType = element.getType();
        if (rawType.isArray() || Collection.class.isAssignableFrom(rawType)) {
View Full Code Here


        super(registry);
    }   

    @Override
    public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
        Reference annotation = method.getAnnotation(Reference.class);
        if (annotation != null) {
 
          if (!JavaIntrospectionHelper.isSetter(method)) {
              throw new IllegalReferenceException("Annotated method is not a setter: " + method, method);
          }
        
          if(Modifier.isStatic(method.getModifiers())) {
            throw new IllegalPropertyException("Static method " + method.getName() +" in class " + method.getDeclaringClass().getName() + " can not be annotated as a Reference");
          }
         
          String name = annotation.name();
          if ("".equals(name)) {
              name = JavaIntrospectionHelper.toPropertyName(method.getName());
          }
          JavaElementImpl ref = type.getReferenceMembers().get(name);
          // Setter override field
View Full Code Here

    }


    @Override
    public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
        Reference annotation = field.getAnnotation(Reference.class);
        if (annotation == null) {
            return;
        }
       
        if(Modifier.isStatic(field.getModifiers())) {
          throw new IllegalReferenceException("Static field " + field.getName() +" in class " + field.getDeclaringClass().getName() + " can not be annotated as Reference");
        }
        String name = annotation.name();
        if ("".equals(name)) {
            name = field.getName();
        }
        JavaElementImpl ref = type.getReferenceMembers().get(name);
        if (ref != null && ref.getElementType() == ElementType.FIELD) {
View Full Code Here

    }

    @Override
    public void visitConstructorParameter(JavaParameterImpl parameter, JavaImplementation type)
        throws IntrospectionException {
        Reference refAnnotation = parameter.getAnnotation(Reference.class);
        if (refAnnotation == null) {
            return;
        }
       
        if (!refAnnotation.required()) {
            throw new InvalidReferenceException("[JCA90016] Constructor has @Reference with required=false: " + type.getName());
        }
       
        if (refAnnotation.name() == null || refAnnotation.name().length() < 1) {
            throw new InvalidReferenceException("[JCA90018] @Reference in a Constructor must have a name attribute" + type.getName());
        }
       
        String paramName = parameter.getName();
        String name = getReferenceName(paramName, parameter.getIndex(), refAnnotation.name());
        JavaElementImpl ref = type.getReferenceMembers().get(name);

        // Setter override field
        if (ref != null && ref.getElementType() != ElementType.FIELD) {
            throw new DuplicateReferenceException(name);
View Full Code Here

    }

    public Object getFieldValue(Field field, Object instance) {
        Object value = null;
        if (field.isAnnotationPresent(Reference.class)) {
            Reference ref = field.getAnnotation(Reference.class);
            String name = ref.name() != null && !ref.name().equals("") ? ref.name() : field.getName();
            value = ContextHelper.getReference(name, field.getType(), contextLocator.getServletContext());
        } else if (field.isAnnotationPresent(Property.class)) {
            Property prop = field.getAnnotation(Property.class);
            String name = prop.name() != null && !prop.name().equals("") ? prop.name() : field.getName();
            value = ContextHelper.getProperty(name, contextLocator.getServletContext());
View Full Code Here

        super(registry);
    }   

    @Override
    public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
        Reference annotation = method.getAnnotation(Reference.class);
        if (annotation != null) {
 
          if (!JavaIntrospectionHelper.isSetter(method)) {
              throw new IllegalReferenceException("Annotated method is not a setter: " + method, method);
          }
        
          if(Modifier.isStatic(method.getModifiers())) {
            throw new IllegalPropertyException("Static method " + method.getName() +" in class " + method.getDeclaringClass().getName() + " can not be annotated as a Reference");
          }
         
          String name = annotation.name();
          if ("".equals(name)) {
              name = JavaIntrospectionHelper.toPropertyName(method.getName());
          }
          JavaElementImpl ref = type.getReferenceMembers().get(name);
          // Setter override field
View Full Code Here

    }


    @Override
    public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
        Reference annotation = field.getAnnotation(Reference.class);
        if (annotation == null) {
            return;
        }
       
        if(Modifier.isStatic(field.getModifiers())) {
          throw new IllegalReferenceException("Static field " + field.getName() +" in class " + field.getDeclaringClass().getName() + " can not be annotated as Reference");
        }
        String name = annotation.name();
        if ("".equals(name)) {
            name = field.getName();
        }
        JavaElementImpl ref = type.getReferenceMembers().get(name);
        if (ref != null && ref.getElementType() == ElementType.FIELD) {
View Full Code Here

    }

    @Override
    public void visitConstructorParameter(JavaParameterImpl parameter, JavaImplementation type)
        throws IntrospectionException {
        Reference refAnnotation = parameter.getAnnotation(Reference.class);
        if (refAnnotation == null) {
            return;
        }
       
        if (!refAnnotation.required()) {
            throw new InvalidReferenceException("[JCA90016] Constructor has @Reference with required=false: " + type.getName());
        }
       
        if (refAnnotation.name() == null || refAnnotation.name().length() < 1) {
            throw new InvalidReferenceException("[JCA90018] @Reference in a Constructor must have a name attribute" + type.getName());
        }
       
        String paramName = parameter.getName();
        String name = getReferenceName(paramName, parameter.getIndex(), refAnnotation.name());
        JavaElementImpl ref = type.getReferenceMembers().get(name);

        // Setter override field
        if (ref != null && ref.getElementType() != ElementType.FIELD) {
            throw new DuplicateReferenceException(name);
View Full Code Here

        JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
        reference.setInterfaceContract(interfaceContract);

        // reference.setMember((Member)element.getAnchor());
        boolean required = true;
        Reference ref = element.getAnnotation(Reference.class);
        if (ref != null) {
            required = ref.required();
        }
        // reference.setRequired(required);
        reference.setName(name);
        Class<?> rawType = element.getType();
        if (rawType.isArray() || Collection.class.isAssignableFrom(rawType)) {
View Full Code Here

        final Class<?> clazz = bean.getClass();

        ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() {
            public void doWith(Method method) {

                Reference annotation = (Reference)method.getAnnotation(getReferenceAnnotationType());

                if (annotation != null) {
                    if (Modifier.isStatic(method.getModifiers())) {
                        throw new IllegalStateException("Reference annotation is not supported on static methods");
                    }

                    /*
                    if (Modifier.isPrivate(method.getModifiers())) {
                        throw new IllegalStateException("Reference annotation is not supported on private methods");
                    }
                    */

                    if (method.getParameterTypes().length == 0) {
                        throw new IllegalStateException(
                                                        "Reference annotation requires at least one argument: " + method);
                    }

                    PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
                    if (pd != null) {
                        String refName = annotation.name();
                        if ("".equals(refName)) {
                            injectReference(bean, pd, pd.getName());
                        } else {
                            injectReference(bean, pd, refName);
                        }
                    }
                }
            }
        });

        ReflectionUtils.doWithFields(clazz, new ReflectionUtils.FieldCallback() {
            public void doWith(Field field) {

                Reference annotation = (Reference)field.getAnnotation(getReferenceAnnotationType());

                if (annotation != null) {
                    if (Modifier.isStatic(field.getModifiers())) {
                        throw new IllegalStateException("Reference annotation is not supported on static fields");
                    }

                    /*
                    if (Modifier.isPrivate(field.getModifiers())) {
                        throw new IllegalStateException("Reference annotation is not supported on private fields");
                    }
                    */

                    ReflectionUtils.makeAccessible(field);

                    Object referenceObj = null;
                    String refName = annotation.name();
                    if ("".equals(refName)) {
                        referenceObj = component.getService(field.getType(), field.getName());
                    } else {
                        referenceObj = component.getService(field.getType(), refName);
                    }
View Full Code Here

TOP

Related Classes of org.oasisopen.sca.annotation.Reference

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.