Package org.apache.tuscany.sca.assembly

Examples of org.apache.tuscany.sca.assembly.Reference


    public EndpointReference getEndpointReference() {
        try {
            resolve()
           
            // Use the interface contract of the reference on the component type
            Reference componentTypeRef = reference.getReference();
            InterfaceContract sourceContract =
                componentTypeRef == null ? reference.getInterfaceContract() : componentTypeRef.getInterfaceContract();
            sourceContract = sourceContract.makeUnidirectional(false);
            EndpointReference epr = new EndpointReferenceImpl(component, reference, binding, sourceContract);
            ReferenceParameters parameters = getReferenceParameters();
            epr.setReferenceParameters(parameters);
            return epr;
View Full Code Here


        p.setValue("USD");
        p.setMustSupply(true);
        p.setXSDType(new QName("", ""));
        ctype.getProperties().add(p);

        Reference ref1 = factory.createReference();
        ref1.setName("accountDataService");
        ref1.setInterfaceContract(new TestInterfaceContract(factory));
        ref1.setMultiplicity(Multiplicity.ONE_ONE);
        ctype.getReferences().add(ref1);
        ref1.getBindings().add(new TestBinding(factory));

        Reference ref2 = factory.createReference();
        ref2.setName("stockQuoteService");
        ref2.setInterfaceContract(new TestInterfaceContract(factory));
        ref2.setMultiplicity(Multiplicity.ONE_ONE);
        ctype.getReferences().add(ref2);
        ref2.getBindings().add(new TestBinding(factory));

        Service s = factory.createService();
        s.setName("AccountService");
        s.setInterfaceContract(new TestInterfaceContract(factory));
        ctype.getServices().add(s);
View Full Code Here

        String name = annotation.name();
        if ("".equals(name)) {
            name = field.getName();
        }
       
        Reference reference = null;
        if ( (reference = getReferenceByName(name, type)) != null ) {
            readIntents(field.getAnnotation(Requires.class), reference.getRequiredIntents());
            readPolicySets(field.getAnnotation(PolicySets.class), reference.getPolicySets());
        }
    }
View Full Code Here

        }
    }

    @Override
    public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
        Reference reference = null;
        if ( (reference = getReference(method, type)) != null ) {
            readIntents(method.getAnnotation(Requires.class), reference.getRequiredIntents());
            readPolicySets(method.getAnnotation(PolicySets.class), reference.getPolicySets());
        } else {
            if ( type instanceof OperationsConfigurator ) {
                //Read the intents specified on the given implementation method
                if ( (method.getAnnotation(Requires.class) != null ||
                        method.getAnnotation(PolicySets.class) != null ) &&
View Full Code Here

                if (interfaze instanceof JavaInterface) {
                    JavaInterface javaInterface = (JavaInterface)interfaze;
                    if (javaInterface.getJavaClass() == null) {
                        javaInterface.setJavaClass(getJavaClass(resolver, javaInterface.getName()));
                    }
                    Reference ref = createReference(reference, javaInterface.getJavaClass());
                    impl.getReferences().add(ref);
                }
                else
                    impl.getReferences().add(reference);
            }
View Full Code Here

                boolean[] isOSGiToOSGiWire = new boolean[refPlusServices];
                boolean[] wireResolved = new boolean[refPlusServices];
                int index = 0;
                for (RuntimeWire wire : referenceWires.keySet()) {
               
                    Reference reference = referenceWires.get(wire);
                   
                    isOSGiToOSGiWire[index] = wire.getTarget().getComponent() != null &&
                            wire.getTarget().getComponent().getImplementationProvider()
                            instanceof OSGiImplementationProvider;
                           
                    Interface refInterface = reference.getInterfaceContract().getInterface();
                    if (refInterface instanceof JavaInterface) {
                        interfaceClasses[index] = ((JavaInterface)refInterface).getJavaClass();
                   
                        if (!isOSGiToOSGiWire[index])
                            resolveWireCreateDummyBundles(interfaceClasses[index]);
View Full Code Here

    }
   
    public ComponentType read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException {
        ComponentType componentType = null;
        Service service = null;
        Reference reference = null;
        Contract contract = null;
        Property property = null;
        Callback callback = null;
        QName name = null;
       
        try {
            // Read the componentType document
            while (reader.hasNext()) {
                int event = reader.getEventType();
                switch (event) {
                    case START_ELEMENT:
                        name = reader.getName();
   
                        if (Constants.COMPONENT_TYPE_QNAME.equals(name)) {
   
                            // Read a <componentType>
                            componentType = assemblyFactory.createComponentType();
   
                        } else if (Constants.SERVICE_QNAME.equals(name)) {
   
                            // Read a <service>
                            service = assemblyFactory.createService();
                            contract = service;
                            service.setName(getString(reader, Constants.NAME));
                            componentType.getServices().add(service);
                            policyProcessor.readPolicies(service, reader);
   
                        } else if (Constants.REFERENCE_QNAME.equals(name)) {
   
                            // Read a <reference>
                            reference = assemblyFactory.createReference();
                            contract = reference;
                            reference.setName(getString(reader, Constants.NAME));
                            reference.setWiredByImpl(getBoolean(reader, Constants.WIRED_BY_IMPL));
                            readMultiplicity(reference, reader);
                            readTargets(reference, reader);
                            componentType.getReferences().add(reference);
                            policyProcessor.readPolicies(reference, reader);
   
View Full Code Here

            // Next handle the references
            Iterator<SpringSCAReferenceElement> itr = references.iterator();
            while (itr.hasNext()) {
                SpringSCAReferenceElement referenceElement = itr.next();
                Class<?> interfaze = resolveClass(resolver, referenceElement.getType(), context);
                Reference theReference = createReference(interfaze, referenceElement.getName());
                // Override the older bean definition with the latest ones
                // for the duplicate definitions found.
                Reference duplicate = null;
                for (Reference reference : componentType.getReferences()) {
                    if (reference.getName().equals(theReference.getName()))
                        duplicate = reference;
                }
                if (duplicate != null)
                    componentType.getReferences().remove(duplicate);

                // add the required intents and policySets for this reference
                theReference.getRequiredIntents().addAll(referenceElement.getRequiredIntents());
                theReference.getPolicySets().addAll(referenceElement.getPolicySets());
                componentType.getReferences().add(theReference);
            } // end while

            // Next handle the properties
            Iterator<SpringSCAPropertyElement> itsp = scaproperties.iterator();
            while (itsp.hasNext()) {
                SpringSCAPropertyElement scaproperty = itsp.next();
                // Create a component type property if the SCA property element has a name
                // and a type declared...
                if (scaproperty.getType() != null && scaproperty.getName() != null) {
                    Property theProperty = assemblyFactory.createProperty();
                    theProperty.setName(scaproperty.getName());
                    // Get the Java class and then an XSD element type for the property
                    Class<?> propType = Class.forName(scaproperty.getType());
                    theProperty.setXSDType(JavaXMLMapper.getXMLType(propType));
                    // Override the older bean definition with the latest ones
                    // for the duplicate definitions found.
                    Property duplicate = null;
                    for (Property property : componentType.getProperties()) {
                        if (property.getName().equals(theProperty.getName()))
                            duplicate = property;
                    }
                    if (duplicate != null)
                        componentType.getProperties().remove(duplicate);

                    componentType.getProperties().add(theProperty);
                    // Remember the Java Class (ie the type) for this property
                    implementation.setPropertyClass(theProperty.getName(), propType);
                } // end if
            } // end while

            // Finally deal with the beans
            Iterator<SpringBeanElement> itb;
            // If there are no explicit service elements, then expose all the beans
            if (services.isEmpty()) {
                itb = beans.iterator();
                // Loop through all the beans found
                while (itb.hasNext()) {
                    SpringBeanElement beanElement = itb.next();

                    // If its not a valid bean for service, ignore it
                    if (!isValidBeanForService(beanElement)) {
                        continue;
                    }
                    try {
                        // Load the Spring bean class
                        Class<?> beanClass = resolveClass(resolver, beanElement.getClassName(), context);
                        // Introspect the bean
                        beanIntrospector = new SpringBeanIntrospector(registry, beanElement.getCustructorArgs());
                        ComponentType beanComponentType = assemblyFactory.createComponentType();
                        javaImplementation = beanIntrospector.introspectBean(beanClass, beanComponentType);
                        // Set the service name as bean name
                        for (Service componentService : beanComponentType.getServices()) {
                            componentService.setName(beanElement.getId());
                        }
                        // Get the service interface defined by this Spring Bean and add to
                        // the component type of the Spring Assembly
                        List<Service> beanServices = beanComponentType.getServices();
                        componentType.getServices().addAll(beanServices);
                        // Add these services to the Service / Bean map
                        for (Service beanService : beanServices) {
                            implementation.setBeanForService(beanService, beanElement);
                        }
                    } catch (Throwable e) {
                        // [rfeng] FIXME: Some Spring beans have constructors that take pararemters injected by Spring and
                        // Tuscany is not happy with that during the introspection
                        log.log(Level.SEVERE, e.getMessage(), e);
                    }
                } // end while
            } // end if

            // [rfeng] We only try to implicitly map Spring beans if no sca:reference or sca:property is present
            if (references.isEmpty() && scaproperties.isEmpty()) {
                itb = beans.iterator();
                while (itb.hasNext()) {
                    SpringBeanElement beanElement = itb.next();

                    // If its not a valid bean for service, ignore it
                    if (!isValidBeanForService(beanElement)) {
                        continue;
                    }
                    // Ignore if the bean has no properties and constructor arguments
                    if (beanElement.getProperties().isEmpty() && beanElement.getCustructorArgs().isEmpty())
                        continue;

                    ComponentType beanComponentType = assemblyFactory.createComponentType();

                    try {
                        Class<?> beanClass = resolveClass(resolver, beanElement.getClassName(), context);
                        // Introspect the bean
                        beanIntrospector = new SpringBeanIntrospector(registry, beanElement.getCustructorArgs());
                        javaImplementation = beanIntrospector.introspectBean(beanClass, beanComponentType);
                    } catch (Exception e) {
                        // [rfeng] FIXME: Some Spring beans have constructors that take pararemters injected by Spring and
                        // Tuscany is not happy with that during the introspection
                        log.log(Level.SEVERE, e.getMessage(), e);
                        continue;
                    }
                    Map<String, JavaElementImpl> propertyMap = javaImplementation.getPropertyMembers();
                    JavaConstructorImpl constructor = javaImplementation.getConstructor();
                    // Get the references by this Spring Bean and add the unresolved ones to
                    // the component type of the Spring Assembly
                    List<Reference> beanReferences = beanComponentType.getReferences();
                    List<Property> beanProperties = beanComponentType.getProperties();

                    Set<String> excludedNames = new HashSet<String>();
                    Iterator<SpringPropertyElement> itp = beanElement.getProperties().iterator();
                    while (itp.hasNext()) {
                        SpringPropertyElement propertyElement = itp.next();
                        // Exclude the reference that is also known as a spring property
                        excludedNames.add(propertyElement.getName());
                        for (String propertyRef : propertyElement.getRefs()) {
                            if (propertyRefUnresolved(propertyRef, beans, references, scaproperties)) {
                                // This means an unresolved reference from the spring bean...
                                for (Reference reference : beanReferences) {
                                    if (propertyElement.getName().equals(reference.getName())) {
                                        // The name of the reference in this case is the string in
                                        // the @ref attribute of the Spring property element, NOT the
                                        // name of the field in the Spring bean....
                                        reference.setName(propertyRef);
                                        // reference.setWiredByImpl(true);
                                        componentType.getReferences().add(reference);
                                        break;
                                    } // end if
                                } // end for

                                // Store the unresolved references as unresolvedBeanRef in the Spring Implementation type
                                for (Property scaproperty : beanProperties) {
                                    if (propertyElement.getName().equals(scaproperty.getName())) {
                                        // The name of the reference in this case is the string in
                                        // the @ref attribute of the Spring property element, NOT the
                                        // name of the field in the Spring bean....
                                        Class<?> interfaze =
                                            resolveClass(resolver,
                                                         (propertyMap.get(propertyElement.getName()).getType())
                                                             .getName(),
                                                         context);
                                        Reference theReference = createReference(interfaze, propertyRef);
                                        implementation.setUnresolvedBeanRef(propertyRef, theReference);
                                        break;
                                    } // end if
                                } // end for
                            } // end if
                        } // end for
                    } // end while

                    Iterator<SpringConstructorArgElement> itcr = beanElement.getCustructorArgs().iterator();
                    while (itcr.hasNext()) {
                        SpringConstructorArgElement conArgElement = itcr.next();
                        for (String constructorArgRef : conArgElement.getRefs()) {
                            if (propertyRefUnresolved(constructorArgRef, beans, references, scaproperties)) {
                                for (JavaParameterImpl parameter : constructor.getParameters()) {
                                    String paramType = parameter.getType().getName();
                                    Class<?> interfaze = resolveClass(resolver, paramType, context);
                                    // Create a component type reference/property if the constructor-arg element has a
                                    // type attribute OR index attribute declared...
                                    if ((conArgElement.getType() != null && paramType.equals(conArgElement.getType())) || (conArgElement
                                        .getIndex() != -1 && (conArgElement.getIndex() == parameter.getIndex()))) {
                                        // [rfeng] Commenting out the following code as the constructor parameter based SCA
                                        // references are added already
                                        /*
                                        if (parameter.getClassifer() == org.oasisopen.sca.annotation.Reference.class) {
                                            Reference theReference = createReference(interfaze, constructorArgRef);
                                            componentType.getReferences().add(theReference);
                                        }
                                        */
                                        if (parameter.getClassifer() == org.oasisopen.sca.annotation.Property.class) {
                                            // Store the unresolved references as unresolvedBeanRef in the Spring Implementation type
                                            // we might need to verify with the component definition later.
                                            Reference theReference = createReference(interfaze, constructorArgRef);
                                            implementation.setUnresolvedBeanRef(constructorArgRef, theReference);
                                        }
                                    }
                                } // end for
                            } // end if
View Full Code Here

        connectReferencesToComponentType(component, monitor);

        // look at each component reference in turn and calculate its
        // configuration based on OASIS rules
        for (ComponentReference componentReference : component.getReferences()) {
            Reference componentTypeReference = componentReference.getReference();

            if (componentTypeReference == null) {
                // raise error?
                // can be null in some of the assembly-xml unit tests
                continue;
View Full Code Here

            if (component.getImplementation() == null) {
                // is null in some of our basic unit tests
                continue;
            }

            Reference reference = component.getImplementation().getReference(componentReference.getName());

            if (reference != null) {
                componentReference.setReference(reference);
            } else {
                Monitor.error(monitor,
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.assembly.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.