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

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


                                    List<SpringBeanElement> beans,
                                    List<SpringSCAServiceElement> services,
                                    List<SpringSCAReferenceElement> references,
                                    List<SpringSCAPropertyElement> scaproperties) throws ContributionReadException {

      SpringBeanElement innerbean = null;
        SpringPropertyElement property = null;
        SpringConstructorArgElement constructorArg = null;
        int autoConstructorIndex = -1;

        try {
            boolean completed = false;
            while (!completed) {
                switch (reader.next()) {
                    case START_ELEMENT:
                        QName qname = reader.getName();
                        if (SpringImplementationConstants.BEAN_ELEMENT.equals(qname)) {
                          innerbean = new SpringBeanElement(reader.getAttributeValue(null, "id"), reader
                                    .getAttributeValue(null, "class"));
                            innerbean.setInnerBean(true);
                            beans.add(innerbean);
                            readBeanDefinition(resolver, reader, contextPath, innerbean, beans, services, references, scaproperties);
                        } else if (SpringImplementationConstants.PROPERTY_ELEMENT.equals(qname)) {
                            property = new SpringPropertyElement(reader.getAttributeValue(null, "name"), reader
                                    .getAttributeValue(null, "ref"));
View Full Code Here


            // 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());
                                implementation.setUnresolvedBeanRef(propertyElement.getRef(), theReference);
                            } // end if
                      } // end for
                    } // end if
                } // end while

                Iterator<SpringConstructorArgElement> itcr = beanElement.getCustructorArgs().iterator();
                while (itcr.hasNext()) {
                  SpringConstructorArgElement conArgElement = itcr.next();
                    if (propertyRefUnresolved(conArgElement.getRef(), beans, references, scaproperties)) {
                      for (JavaParameterImpl parameter : constructor.getParameters()) {
                        String paramType = parameter.getType().getName();
View Full Code Here

        if (ref != null) {
            // Scan over the beans looking for a match
            Iterator<SpringBeanElement> itb = beans.iterator();
            while (itb.hasNext()) {
                SpringBeanElement beanElement = itb.next();
                // Does the bean name match the ref?
                if (ref.equals(beanElement.getId())) {
                    unresolved = false;
                    break;
                } // end if
            } // end while
            // Scan over the SCA reference elements looking for a match
View Full Code Here

                                       List<SpringBeanElement> beans,
                                       List<SpringSCAServiceElement> services,
                                       List<SpringSCAReferenceElement> references,
                                       List<SpringSCAPropertyElement> scaproperties) throws ContributionReadException {

        SpringBeanElement bean = null;

        try {
            boolean completed = false;
            while (!completed) {
                switch (reader.next()) {
                    case START_ELEMENT:
                        QName qname = reader.getName();
                        //System.out.println("Spring TypeLoader - found element with name: " + qname.toString());
                        if (SpringImplementationConstants.IMPORT_ELEMENT.equals(qname)) {
                          //FIXME - put the sequence of code below which gets the ireader into a subsidiary method
                            String location = reader.getAttributeValue(null, "resource");
                            if (location != null) {
                              // FIXME - need to find a right way of generating this path
                                String resourcePath = contextPath.substring(0, contextPath.lastIndexOf("/")+1) + location;
                                XMLStreamReader ireader = getApplicationContextReader(resolver, resourcePath);
                                // Read the context definition for the identified imported resource
                                readContextDefinition(resolver, ireader, contextPath, beans, services, references, scaproperties);
                            }
                        } else if (SpringImplementationConstants.SERVICE_ELEMENT.equals(qname)) {
                            SpringSCAServiceElement service =
                                new SpringSCAServiceElement(reader.getAttributeValue(null, "name"), reader
                                    .getAttributeValue(null, "type"), reader.getAttributeValue(null, "target"));
                            services.add(service);
                        } else if (SpringImplementationConstants.REFERENCE_ELEMENT.equals(qname)) {
                            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"));
                            beans.add(bean);
                            // Read the <bean> element and its child elements
                            readBeanDefinition(resolver, reader, contextPath, bean, beans, services, references, scaproperties);
                        } // end if*/
 
View Full Code Here

                                    List<SpringBeanElement> beans,
                                    List<SpringSCAServiceElement> services,
                                    List<SpringSCAReferenceElement> references,
                                    List<SpringSCAPropertyElement> scaproperties) throws ContributionReadException {

      SpringBeanElement innerbean = null;
        SpringPropertyElement property = null;
        SpringConstructorArgElement constructorArg = null;
        int autoConstructorIndex = -1;

        try {
            boolean completed = false;
            while (!completed) {
                switch (reader.next()) {
                    case START_ELEMENT:
                        QName qname = reader.getName();
                        if (SpringImplementationConstants.BEAN_ELEMENT.equals(qname)) {
                          innerbean = new SpringBeanElement(reader.getAttributeValue(null, "id"), reader
                                    .getAttributeValue(null, "class"));
                            innerbean.setInnerBean(true);
                            beans.add(innerbean);
                            readBeanDefinition(resolver, reader, contextPath, innerbean, beans, services, references, scaproperties);
                        } else if (SpringImplementationConstants.PROPERTY_ELEMENT.equals(qname)) {
                            property = new SpringPropertyElement(reader.getAttributeValue(null, "name"), reader
                                    .getAttributeValue(null, "ref"));
View Full Code Here

            // 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());
                                implementation.setUnresolvedBeanRef(propertyElement.getRef(), theReference);
                            } // end if
                      } // end for
                    } // end if
                } // end while

                Iterator<SpringConstructorArgElement> itcr = beanElement.getCustructorArgs().iterator();
                while (itcr.hasNext()) {
                  SpringConstructorArgElement conArgElement = itcr.next();
                    if (propertyRefUnresolved(conArgElement.getRef(), beans, references, scaproperties)) {
                      for (JavaParameterImpl parameter : constructor.getParameters()) {
                        String paramType = parameter.getType().getName();
View Full Code Here

        if (ref != null) {
            // Scan over the beans looking for a match
            Iterator<SpringBeanElement> itb = beans.iterator();
            while (itb.hasNext()) {
                SpringBeanElement beanElement = itb.next();
                // Does the bean name match the ref?
                if (ref.equals(beanElement.getId())) {
                    unresolved = false;
                    break;
                } // end if
            } // end while
            // Scan over the SCA reference elements looking for a match
View Full Code Here

        if (ref != null) {
            // Scan over the beans looking for a match
            Iterator<SpringBeanElement> itb = beans.iterator();
            while (itb.hasNext()) {
                SpringBeanElement beanElement = itb.next();
                // Does the bean name match the ref?
                if (ref.equals(beanElement.getId())) {
                    unresolved = false;
                    break;
                } // end if
            } // end while
            // Scan over the SCA reference elements looking for a match
View Full Code Here

        while (its.hasNext()) {
          SpringSCAServiceElement serviceElement = its.next();
          boolean targetBeanExists = false;
          Iterator<SpringBeanElement> itb = beans.iterator();
          while (itb.hasNext()) {
            SpringBeanElement beanElement = itb.next();
            if (serviceElement.getTarget().equals(beanElement.getId()))
              targetBeanExists = true;
          }
          if (!targetBeanExists)
            error("TargetBeanDoesNotExist", beans);
        } // end while
       
      // The value of the @name attribute of an <sca:reference/> subelement of a <beans/>
      // element MUST be unique amongst the @name attributes of the <sca:property/>
        // subelements and the <bean/> subelements of the <beans/> element.
        //                   AND
        // The @default attribute of a <sca:reference/> subelement of a <beans/> 
        // element MUST have the value of the @name attribute of one of the <bean/>
        // subelements of the <beans/> element.
        Iterator<SpringSCAReferenceElement> itr = references.iterator();
        while (itr.hasNext()) {
          SpringSCAReferenceElement referenceElement = itr.next();
          boolean defaultBeanExists = true;
          boolean isUniqueReferenceName = true;
          Iterator<SpringBeanElement> itb = beans.iterator();
          while (itb.hasNext()) {
            SpringBeanElement beanElement = itb.next();
            if (referenceElement.getDefaultBean() != null)
              if (referenceElement.getDefaultBean().equals(beanElement.getId()))
                defaultBeanExists = false;
            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("DefaultBeanDoesNotExist", beans);
          if (!isUniqueReferenceName)
            error("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();
View Full Code Here

                                       List<SpringBeanElement> beans,
                                       List<SpringSCAServiceElement> services,
                                       List<SpringSCAReferenceElement> references,
                                       List<SpringSCAPropertyElement> scaproperties, ProcessorContext context) throws ContributionReadException {

        SpringBeanElement bean = null;

        try {
            boolean completed = false;
            while (!completed) {
                switch (reader.next()) {
                    case START_ELEMENT:
                        QName qname = reader.getName();
                        //System.out.println("Spring TypeLoader - found element with name: " + qname.toString());
                        if (SpringImplementationConstants.IMPORT_ELEMENT.equals(qname)) {
                          //FIXME - put the sequence of code below which gets the ireader into a subsidiary method
                            String location = reader.getAttributeValue(null, "resource");
                            if (location != null) {
                              // FIXME - need to find a right way of generating this path
                                String resourcePath = contextPath.substring(0, contextPath.lastIndexOf("/")+1) + location;
                                XMLStreamReader ireader = getApplicationContextReader(resolver, resourcePath, context);
                                // Read the context definition for the identified imported resource
                                readContextDefinition(resolver, ireader, contextPath, beans, services, references, scaproperties, context);
                            }
                        } else if (SpringImplementationConstants.SCA_SERVICE_ELEMENT.equals(qname)) {
                          // The value of the @name attribute of an <sca:service/> subelement of a <beans/>
                          // element MUST be unique amongst the <sca:service/> subelements of the <beans/> element.
                          if (!services.isEmpty() && (services.contains(reader.getAttributeValue(null, "name"))))
                                error("ScaServiceNameNotUnique", resolver);
                         
                          SpringSCAServiceElement service =
                                new SpringSCAServiceElement(reader.getAttributeValue(null, "name"),
                                              reader.getAttributeValue(null, "target"));
                            if (reader.getAttributeValue(null, "type") != null)
                              service.setType(reader.getAttributeValue(null, "type"));
                            policyProcessor.readPolicies(service, reader);
                            services.add(service);
                        } else if (SpringImplementationConstants.SCA_REFERENCE_ELEMENT.equals(qname)) {
                          // The value of the @name attribute of an <sca:reference/> subelement of a <beans/>
                          // element MUST be unique amongst the @name attributes of the <sca:reference/> subelements,
                          // of the <beans/> element.
                          if (!references.isEmpty() && (references.contains(reader.getAttributeValue(null, "name"))))
                                error("ScaReferenceNameNotUnique", resolver);
                         
                          SpringSCAReferenceElement reference =
                                new SpringSCAReferenceElement(reader.getAttributeValue(null, "name"),
                                                reader.getAttributeValue(null, "type"));
                            if (reader.getAttributeValue(null, "default") != null)
                              reference.setDefaultBean(reader.getAttributeValue(null, "default"));
                            policyProcessor.readPolicies(reference, reader);
                            references.add(reference);                           
                        } else if (SpringImplementationConstants.SCA_PROPERTY_ELEMENT.equals(qname)) {
                          // 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:property/> subelements,
                          // of the <beans/> element.
                          if (!scaproperties.isEmpty() && (scaproperties.contains(reader.getAttributeValue(null, "name"))))
                                error("ScaPropertyNameNotUnique", resolver);
                         
                          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"));
                            if (reader.getAttributeValue(null, "abstract") != null)
                              if (reader.getAttributeValue(null, "abstract").equals("true"))
                                bean.setAbstractBean(true);
                            if (reader.getAttributeValue(null, "parent") != null)
                              if (!reader.getAttributeValue(null, "parent").equals(""))
                                bean.setParentAttribute(true);                            
                            if (reader.getAttributeValue(null, "factory-bean") != null)
                              if (!reader.getAttributeValue(null, "factory-bean").equals(""))
                                bean.setFactoryBeanAttribute(true);                             
                            if (reader.getAttributeValue(null, "factory-method") != null)
                              if (!reader.getAttributeValue(null, "factory-method").equals(""))
                                bean.setFactoryMethodAttribute(true);                            
                            // Set the first name as bean name, when the @id attribute is absent.
                            if (reader.getAttributeValue(null, "id") == null) {
                              if (reader.getAttributeValue(null, "name") != null) {
                                String[] names = (reader.getAttributeValue(null, "name")).split(",");
                                bean.setId(names[0]);
                              }
                            }
                            beans.add(bean);
                            // Read the <bean> element and its child elements
                            readBeanDefinition(reader, bean, beans);
View Full Code Here

TOP

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

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.