Package org.apache.tuscany.sca.implementation.java.impl

Examples of org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl


            throw new IllegalCallbackReferenceException("Illegal annotation @Callback found on "+method, method);
        }
        if (method.getParameterTypes().length != 1) {
            throw new IllegalCallbackReferenceException("Setter must have one parameter", method);
        }
        JavaElementImpl element = new JavaElementImpl(method, 0);
        createCallback(type, element);
    }
View Full Code Here


            return;
        }
        if(Modifier.isPrivate(field.getModifiers())) {
            throw new IllegalCallbackReferenceException("Illegal annotation @Callback found on "+field, field);
        }
        JavaElementImpl element = new JavaElementImpl(field);
        createCallback(type, element);
    }
View Full Code Here

                if (!type.getPropertyMembers().containsKey(name) && !type.getReferenceMembers().containsKey(name)) {
                    Class<?> param = method.getParameterTypes()[0];
                    Type genericType = method.getGenericParameterTypes()[0];
                    if (isReferenceType(param, genericType)) {
                        type.getReferences().add(createReference(name, param));
                        type.getReferenceMembers().put(name, new JavaElementImpl(method, 0));
                    } else {
                        type.getProperties().add(createProperty(name, param));
                        type.getPropertyMembers().put(name, new JavaElementImpl(method, 0));
                    }
                }
            }
        }
        // second pass for protected methods with one param
        for (Method method : methods) {
            if (!isProtectedSetter(method)) {
                continue;
            }
            if (method.isAnnotationPresent(Callback.class) || method.isAnnotationPresent(Context.class)) {
                // Add the property name as others
                others.add(toPropertyName(method.getName()));
                continue;
            }
            Class<?> param = method.getParameterTypes()[0];
            String name = toPropertyName(method.getName());
            setters.add(name);
            // avoid duplicate property or ref names
            if (isReferenceType(param, method.getGenericParameterTypes()[0])) {
                if (!type.getReferenceMembers().containsKey(name)) {
                    type.getReferences().add(createReference(name, param));
                    type.getReferenceMembers().put(name, new JavaElementImpl(method, 0));
                }
            } else {
                if (!type.getPropertyMembers().containsKey(name)) {
                    type.getProperties().add(createProperty(name, param));
                    type.getPropertyMembers().put(name, new JavaElementImpl(method, 0));
                }
            }
        }

        // Public or protected fields unless there is a public or protected
        // setter method
        // for the same name
        Set<Field> fields = getAllPublicAndProtectedFields(clazz, false);
        for (Field field : fields) {
            if (field.isAnnotationPresent(Callback.class) || field.isAnnotationPresent(Context.class)) {
                continue;
            }
            if (setters.contains(field.getName()) || others.contains(field.getName())) {
                continue;
            }
            String name = field.getName();
            Class<?> paramType = field.getType();
            if (isReferenceType(paramType, field.getGenericType())) {
                if (!type.getReferenceMembers().containsKey(name)) {
                    type.getReferences().add(createReference(name, paramType));
                    type.getReferenceMembers().put(name, new JavaElementImpl(field));
                }
            } else {
                if (!type.getPropertyMembers().containsKey(name)) {
                    type.getProperties().add(createProperty(name, paramType));
                    type.getPropertyMembers().put(name, new JavaElementImpl(field));
                }
            }
        }
       
        // Private fields unless there is a public or protected
        // setter method for the same name
        Set<Field> privateFields = getPrivateFields(clazz);
        for (Field field : privateFields) {
            if (field.isAnnotationPresent(Callback.class) || field.isAnnotationPresent(Context.class)) {
                continue;
            }
            if (setters.contains(field.getName()) || others.contains(field.getName())) {
                continue;
            }
            String name = field.getName();
            Class<?> paramType = field.getType();
            if (isReferenceType(paramType, field.getGenericType())) {
                if (!type.getReferenceMembers().containsKey(name)) {
                    type.getReferences().add(createReference(name, paramType));
                    type.getReferenceMembers().put(name, new JavaElementImpl(field));
                }
            } else {
                if (!type.getPropertyMembers().containsKey(name)) {
                    type.getProperties().add(createProperty(name, paramType));
                    type.getPropertyMembers().put(name, new JavaElementImpl(field));
                }
            }
        }
    }
View Full Code Here

                                            Map<String, JavaElementImpl> refs) throws AmbiguousConstructorException {

        boolean found = false;
        if (!"".equals(parameter.getName())) {
            // Match by name
            JavaElementImpl prop = props.get(parameter.getName());
            if (prop != null && prop.getType() == parameter.getType()) {
                parameter.setClassifer(Property.class);
                return true;
            }
            JavaElementImpl ref = refs.get(parameter.getName());
            if (ref != null && ref.getType() == parameter.getType()) {
                parameter.setClassifer(Reference.class);
                return true;
            }
        }
        for (JavaElementImpl property : props.values()) {
View Full Code Here

        String setter = JavaIntrospectionHelper.toSetter(name);
        try {
            Method method = impl.getJavaClass().getDeclaredMethod(setter, type);
            int mod = method.getModifiers();
            if ((Modifier.isPublic(mod) || Modifier.isProtected(mod)) && (!Modifier.isStatic(mod))) {
                return new JavaElementImpl(method, 0);
            }
        } catch (NoSuchMethodException e) {
            Field field;
            try {
                field = impl.getJavaClass().getDeclaredField(name);
                int mod = field.getModifiers();
                if ((Modifier.isPublic(mod) || Modifier.isProtected(mod)) && (!Modifier.isStatic(mod))) {
                  return new JavaElementImpl(field);
                }
            } catch (NoSuchFieldException e1) {
                // Ignore
            }
        }
View Full Code Here

                if (ref.getInterfaceContract() != null) {
                    Interface i = ref.getInterfaceContract().getInterface();
                    if (i instanceof JavaInterface) {
                        Class<?> type = ((JavaInterface)i).getJavaClass();
                        if (!refMembers.containsKey(ref.getName())) {
                            JavaElementImpl e = getMemeber(impl, ref.getName(), type);
                            if (e != null) {
                                refMembers.put(ref.getName(), e);
                            }
                        }
                    }
View Full Code Here

        if ("".equals(name)) {
            name = JavaIntrospectionHelper.toPropertyName(method.getName());
            // When the name is not specified, prefix the computed name with the class name
            name = method.getDeclaringClass().getName()+"_"+name;
        }
        JavaElementImpl ref = type.getReferenceMembers().get(name);
        // Setter override field
        if (ref != null && ref.getElementType() != ElementType.FIELD) {
            throw new DuplicateReferenceException(name);
        }
        removeReference(ref, type);

        JavaElementImpl element = new JavaElementImpl(method, 0);
        org.apache.tuscany.sca.assembly.Reference reference = createReference(element, name);
        type.getReferences().add(reference);
        type.getReferenceMembers().put(name, element);
    }
View Full Code Here

        if ("".equals(name)) {
            name = field.getName();
            // When the name is not specified, prefix the computed name with the class name
            name = field.getDeclaringClass().getName()+"_"+name;
        }
        JavaElementImpl ref = type.getReferenceMembers().get(name);
        if (ref != null && ref.getElementType() == ElementType.FIELD) {
            throw new DuplicateReferenceException(name);
        }

        // Setter method override field
        if (ref == null) {
            JavaElementImpl element = new JavaElementImpl(field);
            org.apache.tuscany.sca.assembly.Reference reference = createReference(element, name);
            type.getReferences().add(reference);
            type.getReferenceMembers().put(name, element);
        }
    }
View Full Code Here

            // When the name is not specified, prefix the computed name with the class name
            name = method.getDeclaringClass().getName()+"_"+name;
        }

        Map<String, JavaElementImpl> properties = type.getPropertyMembers();
        JavaElementImpl prop = properties.get(name);
        // Setter override field
        if (prop != null && prop.getElementType() != ElementType.FIELD) {
            throw new DuplicatePropertyException(name);
        }

        removeProperty(prop, type);
       
        JavaElementImpl element = new JavaElementImpl(method, 0);
        Property property = createProperty(name, element);

        property.setMustSupply(annotation.required());
        type.getProperties().add(property);
        properties.put(name, element);
View Full Code Here

            // When the name is not specified, prefix the computed name with the class name
            name = field.getDeclaringClass().getName()+"_"+name;
        }

        Map<String, JavaElementImpl> properties = type.getPropertyMembers();
        JavaElementImpl prop = properties.get(name);
        // Setter override field
        if (prop != null && prop.getElementType() == ElementType.FIELD) {
            throw new DuplicatePropertyException(name);
        }

        if (prop == null) {
            JavaElementImpl element = new JavaElementImpl(field);
            Property property = createProperty(name, element);
            property.setMustSupply(annotation.required());
            type.getProperties().add(property);
            properties.put(name, element);
        }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl

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.