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

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


        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

    public void testExcludedPropertyAndReference() throws Exception {
        JavaImplementation type = javaImplementationFactory.createJavaImplementation();
        org.apache.tuscany.sca.assembly.Reference ref = factory.createReference();
        ref.setName("reference");
        type.getReferences().add(ref);
        type.getReferenceMembers().put("reference", new JavaElementImpl("reference", Ref.class, null));
        org.apache.tuscany.sca.assembly.Reference ref2 = factory.createReference();
        ref2.setName("reference2");
        type.getReferences().add(ref2);
        type.getReferenceMembers().put("reference2", new JavaElementImpl("reference2", Ref.class, null));
        org.apache.tuscany.sca.assembly.Property prop1 = factory.createProperty();
        prop1.setName("string1");
        type.getProperties().add(prop1);
        type.getPropertyMembers().put("string1", new JavaElementImpl("string1", String.class, null));
        org.apache.tuscany.sca.assembly.Property prop2 = factory.createProperty();
        prop2.setName("string2");
        type.getProperties().add(prop2);
        type.getPropertyMembers().put("string2", new JavaElementImpl("string2", String.class, null));
        visitEnd(MockService.class, type);
        assertEquals(1, type.getServices().size());
    }
View Full Code Here

            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));
                }
            }
        }
    }
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

            configureProperty(p);
        }
    }

    private void configureProperty(ComponentProperty configuredProperty) {
        JavaElementImpl element =
            instanceFactoryProvider.getImplementation().getPropertyMembers().get(configuredProperty.getName());

        if (element != null && configuredProperty.getValue() != null) {
            if (!(element.getAnchor() instanceof Constructor)) {
                instanceFactoryProvider.getInjectionSites().add(element);
            }

            //Class propertyJavaType = JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
            ObjectFactory<?> propertyObjectFactory =
                createPropertyValueFactory(configuredProperty, configuredProperty.getValue(), element);
            instanceFactoryProvider.setObjectFactory(element, propertyObjectFactory);
           
            JavaConstructorImpl constructor = instanceFactoryProvider.getImplementation().getConstructor();
            for(JavaElementImpl p: constructor.getParameters()){
                if(element.getName().equals(p.getName())) {
                    instanceFactoryProvider.setObjectFactory(p, propertyObjectFactory);
                }
            }
        }
    }
View Full Code Here

                if (wires == null) {
                    // this can happen when there are no client wires to a
                    // component that has a callback
                    continue;
                }
                JavaElementImpl element = entry.getValue();
                Class<?> businessInterface = element.getType();
                ObjectFactory<?> factory = null;
                if (CallableReference.class.isAssignableFrom(element.getType())) {
                    businessInterface =
                        JavaIntrospectionHelper.getBusinessInterface(element.getType(), element.getGenericType());
                    factory =
                        new CallbackReferenceObjectFactory(businessInterface, proxyFactory, wires);
                } else {
                    factory = new CallbackWireObjectFactory(businessInterface, proxyFactory, wires);
                }
                if (!(element.getAnchor() instanceof Constructor)) {
                    instanceFactoryProvider.getInjectionSites().add(element);
                }
                instanceFactoryProvider.setObjectFactory(element, factory);
            }
        }
        for (Reference ref : instanceFactoryProvider.getImplementation().getReferences()) {
            JavaElementImpl element =
                instanceFactoryProvider.getImplementation().getReferenceMembers().get(ref.getName());
            if (element != null) {
                if (!(element.getAnchor() instanceof Constructor)) {
                    instanceFactoryProvider.getInjectionSites().add(element);
                }
                ComponentReference componentReference = null;
                List<RuntimeWire> wireList = null;
                for (ComponentReference reference : component.getReferences()) {
                    if (reference.getName().equals(ref.getName())) {
                        wireList = ((RuntimeComponentReference)reference).getRuntimeWires();
                        componentReference = reference;
                        break;
                    }
                }
                if (ref.getMultiplicity() == Multiplicity.ONE_N || ref.getMultiplicity() == Multiplicity.ZERO_N) {
                    List<ObjectFactory<?>> factories = new ArrayList<ObjectFactory<?>>();
                    Class<?> baseType =
                        JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
                    for (int i = 0; i < wireList.size(); i++) {
                        ObjectFactory<?> factory = null;
                        if (CallableReference.class.isAssignableFrom(baseType)) {
                            Type callableRefType = JavaIntrospectionHelper.getParameterType(element.getGenericType());
                            // Type businessType = JavaIntrospectionHelper.getParameterType(callableRefType);
                            Class<?> businessInterface =
                                JavaIntrospectionHelper.getBusinessInterface(baseType, callableRefType);
                            factory =
                                new CallableReferenceObjectFactory(businessInterface, component,
                                                                   (RuntimeComponentReference)wireList.get(i)
                                                                       .getSource().getContract(), wireList.get(i)
                                                                       .getSource().getBinding());
                        } else {
                            factory = createObjectFactory(baseType, wireList.get(i));
                        }
                        factories.add(factory);
                    }
                    instanceFactoryProvider.setObjectFactories(element, factories);
                    JavaConstructorImpl constructor = instanceFactoryProvider.getImplementation().getConstructor();
                    for(JavaElementImpl p: constructor.getParameters()){
                        if(element.getName().equals(p.getName())) {
                            instanceFactoryProvider.setObjectFactories(p, factories);
                        }
                    }
                } else {
                    if (wireList == null && ref.getMultiplicity() == Multiplicity.ONE_ONE) {
                        throw new IllegalStateException("Required reference is missing: " + ref.getName());
                    }
                    if (wireList != null && !wireList.isEmpty()) {
                        ObjectFactory<?> factory = null;
                        if (CallableReference.class.isAssignableFrom(element.getType())) {
                            Class<?> businessInterface =
                                JavaIntrospectionHelper.getBusinessInterface(element.getType(), element
                                    .getGenericType());
                            factory =
                                new CallableReferenceObjectFactory(businessInterface, component,
                                                                   (RuntimeComponentReference)componentReference, null);
                        } else {
                            factory = createObjectFactory(element.getType(), wireList.get(0));
                        }
                        instanceFactoryProvider.setObjectFactory(element, factory);
                        JavaConstructorImpl constructor = instanceFactoryProvider.getImplementation().getConstructor();
                        for(JavaElementImpl p: constructor.getParameters()){
                            if(element.getName().equals(p.getName())) {
                                instanceFactoryProvider.setObjectFactory(p, factory);
                            }
                        }
                    }
                }
View Full Code Here

    void addConversationIDFactories(List<Member> names) {
        ObjectFactory<String> factory = new ConversationIDObjectFactory();
        for (Member name : names) {
            if (name instanceof Field) {
                JavaElementImpl element = new JavaElementImpl((Field)name);
                element.setClassifer(ConversationID.class);
                instanceFactoryProvider.setObjectFactory(element, factory);
            } else if (name instanceof Method) {
                JavaElementImpl element = new JavaElementImpl((Method)name, 0);
                element.setName(JavaIntrospectionHelper.toPropertyName(name.getName()));
                element.setClassifer(ConversationID.class);
                instanceFactoryProvider.setObjectFactory(element, factory);
            } else {
                throw new InvalidAccessorException("Member must be a field or method: " + name.getName());
            }
        }
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.