You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2008/10/20 11:50:21 UTC

svn commit: r706173 - in /tuscany/cpp/sca/runtime: core/src/tuscany/sca/model/ extensions/cpp/src/tuscany/sca/cpp/ extensions/cpp/src/tuscany/sca/cpp/model/

Author: slaws
Date: Mon Oct 20 02:50:20 2008
New Revision: 706173

URL: http://svn.apache.org/viewvc?rev=706173&view=rev
Log:
TUSCANY-2643 - Patch supplied by Julien Bigot to correct the handling of composite scoped components. Thanks Julien.

Modified:
    tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.cpp
    tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.h
    tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp
    tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.cpp
    tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.h
    tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.cpp
    tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.h

Modified: tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.cpp
URL: http://svn.apache.org/viewvc/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.cpp?rev=706173&r1=706172&r2=706173&view=diff
==============================================================================
--- tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.cpp (original)
+++ tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.cpp Mon Oct 20 02:50:20 2008
@@ -53,6 +53,109 @@
                 logentry(); 
             }
             
+#if defined(COPY_COMPOSITES_ON_INSTANCIATION) 
+            // Constructor
+            Composite::Composite(Composite* templateComposite, Composite* containerComposite)
+                : ComponentType(containerComposite, templateComposite->getName()), root(templateComposite->root)
+            {
+                logentry();
+                components = templateComposite->components;
+                includes = templateComposite->includes;
+                wires = templateComposite->wires;
+                wsdlDefinitions = templateComposite->wsdlDefinitions;
+                // Copy all services from the cloned template
+                SERVICETYPE_MAP serviceTypeMap = templateComposite->getServiceTypes();
+                for (SERVICETYPE_MAP::iterator serviter = serviceTypeMap.begin();
+                serviter != serviceTypeMap.end();
+                ++serviter)
+                {
+                    addServiceType(serviter->second);
+                }
+                // Copy all references from the cloned template
+                REFERENCETYPE_MAP referenceTypeMap = templateComposite->getReferenceTypes();
+                for (REFERENCETYPE_MAP::iterator refiter = referenceTypeMap.begin();
+                refiter != referenceTypeMap.end();
+                refiter++)
+                {
+                    addReferenceType(refiter->second);
+                }
+                // Copy the dataFactory from the cloned template
+                commonj::sdo::DataFactoryPtr propertyFactory = getPropertyDataFactory();
+                commonj::sdo::DataFactoryPtr dataFactory = templateComposite->getPropertyDataFactory();
+                commonj::sdo::TypeList typeList = dataFactory->getTypes();
+                for (int typeiter1=0;
+                typeiter1 < typeList.size();
+                ++typeiter1)
+                {
+                    const commonj::sdo::Type& type = typeList[typeiter1];
+                    propertyFactory->addType(
+                        type.getURI(),
+                        type.getName(),
+                        type.isSequencedType(),
+                        type.isOpenType(),
+                        type.isAbstractType(),
+                        type.isDataType());
+                }
+                for (int typeiter2=0;
+                typeiter2 < typeList.size();
+                ++typeiter2)
+                {
+                    const commonj::sdo::Type& type = typeList[typeiter2];
+                    commonj::sdo::PropertyList propertyList = type.getProperties();
+                    for (int propertyiter=0;
+                    propertyiter < propertyList.size();
+                    ++propertyiter)
+                    {
+                        const commonj::sdo::Property& property = propertyList[propertyiter];
+                        propertyFactory->addPropertyToType(
+                            type.getURI(),
+                            type.getName(),
+                            property.getName(),
+                            property.getType().getURI(),
+                            property.getType().getName(),
+                            property.isMany(),
+                            property.isReadOnly(),
+                            property.isContainment());
+                    }
+                    for (int propertyiter=0;
+                    propertyiter < propertyList.size();
+                    ++propertyiter)
+                    {
+                        const commonj::sdo::Property& property = propertyList[propertyiter];
+                        for (int aliasiter = 0;
+                        aliasiter < property.getAliasCount();
+                        ++aliasiter)
+                        {
+                            propertyFactory->setAlias(
+                                type.getURI(),
+                                type.getName(),
+                                property.getName(),
+                                property.getAlias(aliasiter));
+                        }
+                    }
+                    for (int aliasiter = 0;
+                    aliasiter < type.getAliasCount();
+                    ++aliasiter)
+                    {
+                        propertyFactory->setAlias(
+                            type.getURI(),
+                            type.getName(),
+                            type.getAlias(aliasiter));
+                    }
+                    if ( type.getBaseType() )
+                    {
+                        propertyFactory->setBaseType(
+                            type.getURI(),
+                            type.getName(),
+                            type.getBaseType()->getURI(),
+                            type.getBaseType()->getName(),
+                            false); //TODO: Where do we know if the cloned Type is a restriction ???
+                    }
+                }
+                
+            }
+#endif
+            
             // Destructor
             Composite::~Composite()
             {

Modified: tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.h
URL: http://svn.apache.org/viewvc/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.h?rev=706173&r1=706172&r2=706173&view=diff
==============================================================================
--- tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.h (original)
+++ tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.h Mon Oct 20 02:50:20 2008
@@ -31,6 +31,7 @@
 #include "tuscany/sca/export.h"
 #include "tuscany/sca/model/ComponentType.h"
 
+#define COPY_COMPOSITES_ON_INSTANCIATION
 
 namespace tuscany
 {
@@ -65,6 +66,15 @@
                  */
                 SCA_API Composite(const std::string& name, const std::string& root);
 
+#if defined(COPY_COMPOSITES_ON_INSTANCIATION) 
+                /**
+                 * Constructor to create a composite representing an instance by copying a template.
+                 * @param templateComposite the template copmosite that will be copied.
+                 * @param containerComposite the container of the instance.
+                 */
+                SCA_API Composite(Composite* templateComposite, Composite* containerComposite);
+#endif
+
                 /**
                  * Destructor.
                  */

Modified: tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp
URL: http://svn.apache.org/viewvc/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp?rev=706173&r1=706172&r2=706173&view=diff
==============================================================================
--- tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp (original)
+++ tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp Mon Oct 20 02:50:20 2008
@@ -318,14 +318,18 @@
                 if (implTypeQname == "http://www.osoa.org/xmlns/sca/1.0#SCAImplementation")
                 {
                     // Handle a composite implementation 
-                    Composite* composite = compositeModels[impl->getCString("name")];
-                    if (!composite)
+                    Composite* compositeComponentType = compositeModels[impl->getCString("name")];
+                    if (!compositeComponentType)
                     {
                         string message = "Composite not found: ";
                         message = message + impl->getCString("name");
                         throwException(SystemConfigurationException, message.c_str());
                     }
-                    componentType = composite;
+#if defined(COPY_COMPOSITES_ON_INSTANCIATION) 
+                    componentType = new Composite(compositeComponentType, composite);
+#else
+                    componentType = compositeComponentType;
+#endif
                 }
                 else
                 {

Modified: tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.cpp
URL: http://svn.apache.org/viewvc/tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.cpp?rev=706173&r1=706172&r2=706173&view=diff
==============================================================================
--- tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.cpp (original)
+++ tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.cpp Mon Oct 20 02:50:20 2008
@@ -44,11 +44,6 @@
     {
         namespace cpp
         {
-            
-            // ===================
-            // Static data members
-            // ===================
-            void* CPPServiceWrapper::staticImpl = 0;
     
             // ===========
             // Constructor
@@ -80,11 +75,12 @@
                 logentry();
                 if (implementation->getScope() == CPPImplementation::COMPOSITE)
                 {
-                    if (!staticImpl)
+                    // fill the cache if needed
+                    if ( !implementation->getStaticImplementation() )
                     {
-                        staticImpl = newImplementation();
+                        implementation->setStaticImplementation(newImplementation());
                     }
-                    return staticImpl;
+                    return implementation->getStaticImplementation();
                 }
                 else // (scope == CPPInterface::STATELESS)
                 {

Modified: tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.h
URL: http://svn.apache.org/viewvc/tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.h?rev=706173&r1=706172&r2=706173&view=diff
==============================================================================
--- tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.h (original)
+++ tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.h Mon Oct 20 02:50:20 2008
@@ -120,11 +120,6 @@
     
             private:
                 /**
-                 * Holds an implementation instance if the scope is set to composite.
-                 */
-                static void* staticImpl;
-    
-                /**
                  * The component to which this wrapper refers.
                  */
                 tuscany::sca::model::Component* component;

Modified: tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.cpp
URL: http://svn.apache.org/viewvc/tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.cpp?rev=706173&r1=706172&r2=706173&view=diff
==============================================================================
--- tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.cpp (original)
+++ tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.cpp Mon Oct 20 02:50:20 2008
@@ -45,7 +45,7 @@
                     const string&headerPath, const string& headerStub, const string& className, Scope scope)
                 : ComponentType(composite, headerPath + headerStub),
                     library(library), header(header), headerPath(headerPath),
-                    headerStub(headerStub), className(className), scope(scope)
+                    headerStub(headerStub), className(className), scope(scope), staticImpl(0)
             {
             }
 
@@ -80,6 +80,11 @@
                 }
             }
             
+            void CPPImplementation::setStaticImplementation(void* staticImpl)
+            {
+              this->staticImpl = staticImpl; 
+            }
+            
         } // End namespace cpp
     } // End namespace sca
 } // End namespace tuscany

Modified: tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.h
URL: http://svn.apache.org/viewvc/tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.h?rev=706173&r1=706172&r2=706173&view=diff
==============================================================================
--- tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.h (original)
+++ tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.h Mon Oct 20 02:50:20 2008
@@ -107,6 +107,16 @@
                  */
                  Scope getScope() { return scope; }
                 
+                /**
+                 * Returns the implementation instance (to be used if the scope is set to composite)
+                 */
+                 void* getStaticImplementation() { return staticImpl; }
+                
+                /**
+                 * Sets the implementation instance (to be used if the scope is set to composite)
+                 */
+                 void setStaticImplementation(void* staticImpl);
+                
             private:
                 
                 /**
@@ -139,6 +149,11 @@
                  * Scope of the implementation
                  */
                 Scope scope;
+    
+                /**
+                 * Holds the implementation instance if the scope is set to composite.
+                 */
+                void* staticImpl;
             };
             
         } // End namespace cpp