Package org.apache.tuscany.sca.implementation.spring

Examples of org.apache.tuscany.sca.implementation.spring.SpringSCAPropertyElement


                            SpringSCAReferenceElement reference =
                                new SpringSCAReferenceElement(reader.getAttributeValue(null, "name"), reader
                                    .getAttributeValue(null, "type"));
                            references.add(reference);
                        } else if (SpringImplementationConstants.SCAPROPERTY_ELEMENT.equals(qname)) {
                            SpringSCAPropertyElement scaproperty =
                                new SpringSCAPropertyElement(reader.getAttributeValue(null, "name"), reader
                                    .getAttributeValue(null, "type"));
                            scaproperties.add(scaproperty);
                        } else if (SpringImplementationConstants.BEAN_ELEMENT.equals(qname)) {
                            bean = new SpringBeanElement(reader.getAttributeValue(null, "id"), reader
                                    .getAttributeValue(null, "class"));
View Full Code Here


            } // 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));
                    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 a innerBean, ignore it
                    if (beanElement.isInnerBean()) continue;
                    // Load the Spring bean class
                    Class<?> beanClass = resolveClass(resolver, beanElement.getClassName());
                    // Introspect the bean
                    beanIntrospector =
                        new SpringBeanIntrospector(assemblyFactory, javaFactory, policyFactory, beanElement.getCustructorArgs());
                    ComponentType beanComponentType = assemblyFactory.createComponentType();
                    javaImplementation = beanIntrospector.introspectBean(beanClass, beanComponentType);
                    // 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);
                    }
                } // end while
            } // end if

            itb = beans.iterator();
            while (itb.hasNext()) {
                SpringBeanElement beanElement = itb.next();
                // Ignore if the bean has no properties and constructor arguments
                if (beanElement.getProperties().isEmpty() && beanElement.getCustructorArgs().isEmpty())
                  continue;

                Class<?> beanClass = resolveClass(resolver, beanElement.getClassName());
                // Introspect the bean
                beanIntrospector =
                    new SpringBeanIntrospector(assemblyFactory, javaFactory, policyFactory, beanElement.getCustructorArgs());
                ComponentType beanComponentType = assemblyFactory.createComponentType();
                javaImplementation = beanIntrospector.introspectBean(beanClass, beanComponentType);
                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();

                Iterator<SpringPropertyElement> itp = beanElement.getProperties().iterator();
                while (itp.hasNext()) {
                    SpringPropertyElement propertyElement = itp.next();
                    if (propertyRefUnresolved(propertyElement.getRef(), 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(propertyElement.getRef());
                                componentType.getReferences().add(reference);
                            } // 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());
                                Reference theReference = createReference(interfaze, propertyElement.getRef());
View Full Code Here

            } // end if
            // Scan over the SCA property elements looking for a match
            if (unresolved) {
                Iterator<SpringSCAPropertyElement> itsp = scaproperties.iterator();
                while (itsp.hasNext()) {
                    SpringSCAPropertyElement propertyElement = itsp.next();
                    if (ref.equals(propertyElement.getName())) {
                        unresolved = false;
                        break;
                    } // end if
                } // end while
            } // end if
View Full Code Here

            } // 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

            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);
                                    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,
View Full Code Here

            } // end if
              // Scan over the SCA property elements looking for a match
            if (unresolved) {
                Iterator<SpringSCAPropertyElement> itsp = scaproperties.iterator();
                while (itsp.hasNext()) {
                    SpringSCAPropertyElement propertyElement = itsp.next();
                    if (ref.equals(propertyElement.getName())) {
                        unresolved = false;
                        break;
                    } // end if
                } // end while
            } // end if
View Full Code Here

                if (referenceElement.getName().equals(beanElement.getId()))
                    isUniqueReferenceName = false;
            }
            Iterator<SpringSCAPropertyElement> itp = scaproperties.iterator();
            while (itp.hasNext()) {
                SpringSCAPropertyElement propertyElement = itp.next();
                if (referenceElement.getName().equals(propertyElement.getName()))
                    isUniqueReferenceName = false;
            }
            if (!defaultBeanExists)
                error(monitor, "DefaultBeanDoesNotExist", beans);
            if (!isUniqueReferenceName)
                error(monitor, "ScaReferenceNameNotUnique", beans);
        } // end while

        // The value of the @name attribute of an <sca:property/> subelement of a <beans/>
        // element MUST be unique amongst the @name attributes of the <sca:reference/>
        // subelements and the <bean/> subelements of the <beans/> element.     
        Iterator<SpringSCAPropertyElement> itp = scaproperties.iterator();
        while (itp.hasNext()) {
            SpringSCAPropertyElement propertyElement = itp.next();
            boolean isUniquePropertyName = true;
            Iterator<SpringBeanElement> itb = beans.iterator();
            while (itb.hasNext()) {
                SpringBeanElement beanElement = itb.next();
                if (propertyElement.getName().equals(beanElement.getId()))
                    isUniquePropertyName = false;
            }
            Iterator<SpringSCAReferenceElement> itrp = references.iterator();
            while (itrp.hasNext()) {
                SpringSCAReferenceElement referenceElement = itrp.next();
                if (propertyElement.getName().equals(referenceElement.getName()))
                    isUniquePropertyName = false;
            }
            if (!isUniquePropertyName)
                error(monitor, "ScaPropertyNameNotUnique", beans);
        } // end while
View Full Code Here

    public BeanDefinition parse(Element element, ParserContext parserContext) {
        BeanDefinitionRegistry registry = parserContext.getRegistry();
        if (registry instanceof SCAGenericApplicationContext) {
            SCAGenericApplicationContext context = (SCAGenericApplicationContext)registry;
            SpringSCAPropertyElement propertyElement =
                new SpringSCAPropertyElement(element.getAttributeNS(null, "name"), element.getAttributeNS(null, "type"));
            context.addSCAPropertyElement(propertyElement);
        }
        // do nothing, this is handled by Tuscany
        return null;
    }
View Full Code Here

                            SpringSCAReferenceElement reference =
                                new SpringSCAReferenceElement(reader.getAttributeValue(null, "name"), reader
                                    .getAttributeValue(null, "type"));
                            references.add(reference);
                        } else if (SpringImplementationConstants.SCAPROPERTY_ELEMENT.equals(qname)) {
                            SpringSCAPropertyElement scaproperty =
                                new SpringSCAPropertyElement(reader.getAttributeValue(null, "name"), reader
                                    .getAttributeValue(null, "type"));
                            scaproperties.add(scaproperty);
                        } else if (SpringImplementationConstants.BEAN_ELEMENT.equals(qname)) {
                            bean = new SpringBeanElement(reader.getAttributeValue(null, "id"), reader
                                    .getAttributeValue(null, "class"));
View Full Code Here

            } // 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.
                    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 a innerBean, ignore it
                    if (beanElement.isInnerBean()) continue;
                    // Load the Spring bean class
                    Class<?> beanClass = resolveClass(resolver, beanElement.getClassName());
                    // Introspect the bean
                    beanIntrospector =
                        new SpringBeanIntrospector(assemblyFactory, javaFactory, policyFactory, 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);
                    }
                } // end while
            } // end if

            itb = beans.iterator();
            while (itb.hasNext()) {
                SpringBeanElement beanElement = itb.next();
                // Ignore if the bean has no properties and constructor arguments
                if (beanElement.getProperties().isEmpty() && beanElement.getCustructorArgs().isEmpty())
                  continue;

                Class<?> beanClass = resolveClass(resolver, beanElement.getClassName());
                // Introspect the bean
                beanIntrospector =
                    new SpringBeanIntrospector(assemblyFactory, javaFactory, policyFactory, beanElement.getCustructorArgs());
                ComponentType beanComponentType = assemblyFactory.createComponentType();
                javaImplementation = beanIntrospector.introspectBean(beanClass, beanComponentType);
                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();

                Iterator<SpringPropertyElement> itp = beanElement.getProperties().iterator();
                while (itp.hasNext()) {
                    SpringPropertyElement propertyElement = itp.next();
                    if (propertyRefUnresolved(propertyElement.getRef(), 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(propertyElement.getRef());
                                componentType.getReferences().add(reference);
                            } // 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());
                                Reference theReference = createReference(interfaze, propertyElement.getRef());
View Full Code Here

            } // end if
            // Scan over the SCA property elements looking for a match
            if (unresolved) {
                Iterator<SpringSCAPropertyElement> itsp = scaproperties.iterator();
                while (itsp.hasNext()) {
                    SpringSCAPropertyElement propertyElement = itsp.next();
                    if (ref.equals(propertyElement.getName())) {
                        unresolved = false;
                        break;
                    } // end if
                } // end while
            } // end if
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.implementation.spring.SpringSCAPropertyElement

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.