Package org.osoa.sca.annotations

Examples of org.osoa.sca.annotations.Reference


        this.javaFactory = javaFactory;
    }

    @Override
    public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
        Reference annotation = method.getAnnotation(Reference.class);
        if (annotation == null) {
            return; // Not a reference annotation.
        }
        if (method.getParameterTypes().length != 1) {
            throw new IllegalReferenceException("Setter must have one parameter", method);
        }
        String name = annotation.name();
        if ("".equals(name)) {
            name = JavaIntrospectionHelper.toPropertyName(method.getName());
        }
        if (type.getReferenceMembers().get(name) != null) {
            throw new DuplicateReferenceException(name);
View Full Code Here


        type.getReferenceMembers().put(name, element);
    }

    @Override
    public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
        Reference annotation = field.getAnnotation(Reference.class);
        if (annotation == null) {
            return;
        }
        String name = annotation.name();
        if ("".equals(name)) {
            name = field.getName();
        }
        if (type.getReferenceMembers().get(name) != null) {
            throw new DuplicateReferenceException(name);
View Full Code Here

    }

    @Override
    public void visitConstructorParameter(JavaParameterImpl parameter, JavaImplementation type)
        throws IntrospectionException {
        Reference refAnnotation = parameter.getAnnotation(Reference.class);
        if (refAnnotation == null) {
            return;
        }
        String paramName = parameter.getName();
        String name = getReferenceName(paramName, parameter.getIndex(), refAnnotation.name());
        if (type.getReferenceMembers().get(name) != null) {
            throw new DuplicateReferenceException(name);
        }
        org.apache.tuscany.sca.assembly.Reference reference = createReference(parameter, name);
        type.getReferences().add(reference);
View Full Code Here

        JavaInterfaceContract interfaceContract = javaFactory.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) {
                //Annotation annotation = method.getAnnotation(getReferenceAnnotationType());               
                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) {
                //Annotation annotation = field.getAnnotation(getReferenceAnnotationType());               
                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.getComponentContext().getService(field.getType(), field.getName());
                    } else {
                        referenceObj = component.getComponentContext().getService(field.getType(), refName);
                    }                       
View Full Code Here

       
        // Initialize fields annotations
        Field[] fields = instance.getClass().getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            if (fields[i].isAnnotationPresent(Reference.class)) {
                Reference annotation = fields[i].getAnnotation(Reference.class);
                injectFieldResource(instance, fields[i], annotation);
            }
        }
       
        // Initialize methods annotations
        Method[] methods = instance.getClass().getDeclaredMethods();
        for (int i = 0; i < methods.length; i++) {
            if (methods[i].isAnnotationPresent(Reference.class)) {
                Reference annotation = methods[i].getAnnotation(Reference.class);
                injectMethodResource(instance, methods[i], annotation);
            }
        }

    }
View Full Code Here

        this.javaFactory = javaFactory;
        this.interfaceIntrospector = interfaceIntrospector;
    }

    public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
        Reference annotation = method.getAnnotation(Reference.class);
        if (annotation == null) {
            return; // Not a reference annotation.
        }
        if (method.getParameterTypes().length != 1) {
            throw new IllegalReferenceException("Setter must have one parameter", method);
        }
        String name = annotation.name();
        if ("".equals(name)) {
            name = JavaIntrospectionHelper.toPropertyName(method.getName());
        }
        if (type.getReferenceMembers().get(name) != null) {
            throw new DuplicateReferenceException(name);
View Full Code Here

        type.getReferences().add(reference);
        type.getReferenceMembers().put(name, element);
    }

    public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
        Reference annotation = field.getAnnotation(Reference.class);
        if (annotation == null) {
            return;
        }
        String name = annotation.name();
        if ("".equals(name)) {
            name = field.getName();
        }
        if (type.getReferenceMembers().get(name) != null) {
            throw new DuplicateReferenceException(name);
View Full Code Here

        type.getReferenceMembers().put(name, element);
    }

    public void visitConstructorParameter(JavaParameterImpl parameter, JavaImplementation type)
        throws IntrospectionException {
        Reference refAnnotation = parameter.getAnnotation(Reference.class);
        if (refAnnotation == null) {
            return;
        }
        String paramName = parameter.getName();
        String name = getReferenceName(paramName, parameter.getIndex(), refAnnotation.name());
        if (type.getReferenceMembers().get(name) != null) {
            throw new DuplicateReferenceException(name);
        }
        org.apache.tuscany.sca.assembly.Reference reference = createReference(parameter, name);
        type.getReferences().add(reference);
View Full Code Here

        JavaInterfaceContract interfaceContract = javaFactory.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

TOP

Related Classes of org.osoa.sca.annotations.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.