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

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


            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)) {
                if(element.getElementType() == ElementType.FIELD) {
                    // Field field = (Field)element.getAnchor();
                    instanceFactoryProvider.getInjectionSites().add(element);
                    /*
                    if(Modifier.isPublic(field.getModifiers())) {
                        instanceFactoryProvider.getInjectionSites().add(element);
                    } else if(field.getAnnotation(org.osoa.sca.annotations.Property.class) != null) {
                        instanceFactoryProvider.getInjectionSites().add(element);
                    }
                    */
                } else {
                    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


                    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)) {
                    if(element.getElementType() == ElementType.FIELD) {
                        Field field = (Field)element.getAnchor();
                        if(Modifier.isPublic(field.getModifiers())) {
                            instanceFactoryProvider.getInjectionSites().add(element);
                        } else if(field.getAnnotation(org.osoa.sca.annotations.Reference.class) != null) {
                            instanceFactoryProvider.getInjectionSites().add(element);
                        }
                    } else {
                        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

            }
        }
        if (callbackService == null) {
            throw new IllegalCallbackReferenceException("Callback type does not match a service callback interface");
        }
        type.getCallbackMembers().put(callbackClass.getName(), new JavaElementImpl(method, 0));
    }
View Full Code Here

            }
        }
        if (callbackService == null) {
            throw new IllegalCallbackReferenceException("Callback type does not match a service callback interface");
        }
        type.getCallbackMembers().put(callbackClass.getName(), new JavaElementImpl(field));
    }
View Full Code Here

        }
        if (type.getReferenceMembers().get(name) != null) {
            throw new DuplicateReferenceException(name);
        }

        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

            name = field.getName();
        }
        if (type.getReferenceMembers().get(name) != null) {
            throw new DuplicateReferenceException(name);
        }
        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

        if (type.getResources().get(name) != null) {
            throw new DuplicateResourceException(name);
        }

        String mappedName = annotation.mappedName();
        JavaResourceImpl resource = createResource(name, new JavaElementImpl(method, 0));
        resource.setOptional(annotation.optional());
        if (mappedName.length() > 0) {
            resource.setMappedName(mappedName);
        }
        type.getResources().put(resource.getName(), resource);
View Full Code Here

            throw new DuplicateResourceException(name);
        }

        String mappedName = annotation.mappedName();

        JavaResourceImpl resource = createResource(name, new JavaElementImpl(field));
        resource.setOptional(annotation.optional());
        if (mappedName.length() > 0) {
            resource.setMappedName(mappedName);
        }
        type.getResources().put(resource.getName(), resource);
View Full Code Here

        JavaImplementation type = javaImplementationFactory.createJavaImplementation();
        org.apache.tuscany.sca.assembly.Property prop = factory.createProperty();
        prop.setName("foo");
        type.getProperties().add(prop);
        // Hack to add a property member
        JavaElementImpl element = new JavaElementImpl("foo", String.class, null);
        type.getPropertyMembers().put("foo", element);
        visitEnd(Foo1.class, type);
        assertNotNull(type.getConstructor().getConstructor());
        assertEquals("foo", type.getConstructor().getParameters()[0].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.