diff options
Diffstat (limited to 'cpp/sca/runtime/core/src')
3 files changed, 120 insertions, 3 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 { |