diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2008-10-20 09:50:20 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2008-10-20 09:50:20 +0000 |
commit | 4c69eb46c553337e27b2bd81bc1e30f41cdd48cd (patch) | |
tree | ffe3c02793725d9918da4274eed6e9cbb992e17a | |
parent | 28a8730ea280024f75075b0826c931756c394e3d (diff) |
TUSCANY-2643 - Patch supplied by Julien Bigot to correct the handling of composite scoped components. Thanks Julien.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@706173 13f79535-47bb-0310-9956-ffa450edef68
7 files changed, 145 insertions, 17 deletions
diff --git a/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.cpp b/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.cpp index b855f8eb95..6456b0cede 100644 --- a/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.cpp +++ b/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.cpp @@ -53,6 +53,109 @@ namespace tuscany 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() { diff --git a/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.h b/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.h index a50216c1cb..40626feb14 100644 --- a/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.h +++ b/cpp/sca/runtime/core/src/tuscany/sca/model/Composite.h @@ -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 @@ namespace tuscany */ 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. */ diff --git a/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp b/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp index b8aad705e2..549ffcfc7e 100644 --- a/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp +++ b/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp @@ -318,14 +318,18 @@ namespace tuscany 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 { diff --git a/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.cpp b/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.cpp index fbf8281178..1304ab92a0 100644 --- a/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.cpp +++ b/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.cpp @@ -44,11 +44,6 @@ namespace tuscany { namespace cpp { - - // =================== - // Static data members - // =================== - void* CPPServiceWrapper::staticImpl = 0; // =========== // Constructor @@ -80,11 +75,12 @@ namespace tuscany 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) { diff --git a/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.h b/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.h index e8111b6423..899deca07a 100644 --- a/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.h +++ b/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.h @@ -120,11 +120,6 @@ namespace tuscany 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; diff --git a/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.cpp b/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.cpp index 9e5a227f01..56098ced93 100644 --- a/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.cpp +++ b/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.cpp @@ -45,7 +45,7 @@ namespace tuscany 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 @@ namespace tuscany } } + void CPPImplementation::setStaticImplementation(void* staticImpl) + { + this->staticImpl = staticImpl; + } + } // End namespace cpp } // End namespace sca } // End namespace tuscany diff --git a/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.h b/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.h index 11f487361d..2dfdac616e 100644 --- a/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.h +++ b/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.h @@ -107,6 +107,16 @@ namespace tuscany */ 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 @@ namespace tuscany * Scope of the implementation */ Scope scope; + + /** + * Holds the implementation instance if the scope is set to composite. + */ + void* staticImpl; }; } // End namespace cpp |