diff options
Diffstat (limited to 'sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model')
42 files changed, 6255 insertions, 0 deletions
diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Binding.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Binding.cpp new file mode 100644 index 0000000000..a654b9f0f7 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Binding.cpp @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/model/Binding.h" + +using namespace std; + +namespace tuscany +{ + namespace sca + { + + namespace model + { + + // Constructor + Binding::Binding(const string& uri) : uri(uri) + { + logentry(); + } + + // Destructor + Binding::~Binding() + { + logentry(); + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Binding.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Binding.h new file mode 100644 index 0000000000..66dc66e853 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Binding.h @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_binding_h +#define tuscany_sca_model_binding_h + +#include <string> + +namespace tuscany +{ + namespace sca + { + namespace model + { + /** + * Represents a binding. + * Bindings are used by services and references. References use bindings + * to describe the access mechanism used to call an external service (which can + * be a service provided by another SCA composite). Services use bindings to describe + * the access mechanism that clients (which can be a client from another SCA composite) + * have to use to call the service. + * This interface will typically be extended by binding implementations to allow + * specification of binding/transport specific information. + */ + class Binding + { + + public: + + /** + * Constructor to create a new binding. + * @param uri The binding URI. + */ + SCA_API Binding(const std::string& uri); + + /** + * Destructor. + */ + SCA_API virtual ~Binding(); + + /** + * Returns the binding type + * @return The binding type. + */ + SCA_API virtual std::string getType() = 0; + + /** + * Returns the binding URI. + * @return The binding URI. + */ + SCA_API virtual const std::string& getURI() const { return uri; }; + + private: + + /** + * The binding URI. + */ + std::string uri; + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_binding_h diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Component.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Component.cpp new file mode 100644 index 0000000000..37bf381811 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Component.cpp @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include <iostream> + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/Exceptions.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/model/ComponentType.h" + +using namespace std; +using namespace commonj::sdo; + +namespace tuscany +{ + namespace sca + { + namespace model + { + // Constructor + Component::Component(Composite* composite, const std::string& componentName, ComponentType *componentType) + : name(componentName), composite(composite), type(componentType) + { + logentry(); + loginfo("Component name: %s", name.c_str()); + + // Initialize the component from its component type + componentType->initializeComponent(this); + + } + + Component::~Component() + { + logentry(); + } + + void Component::addService(Service* service) + { + logentry(); + services[service->getType()->getName()] = service; + } + + Service* Component::findService(const string& serviceName) + { + logentry(); + + // If serviceName is empty then return the ONLY service + if (serviceName == "" + && services.size() == 1) + { + return services.begin()->second; + } + else + { + Service* service = services[serviceName]; + if (service == NULL) + { + // A service with an empty name will match any service name + service = services[""]; + } + return service; + } + } + + void Component::addReference(Reference* reference) + { + logentry(); + references[reference->getType()->getName()] = reference; + } + + Reference* Component::findReference(const std::string& referenceName) + { + logentry(); + return references[referenceName]; + } + + DataObjectPtr Component::getProperties() + { + logentry(); + + if (!properties) + { + properties = type->getPropertyDataFactory()->create("org/osoa/sca", "Properties"); + } + return properties; + } + + void Component::setProperty(const string& name, DataObjectPtr value) + { + logentry(); + + DataObjectPtr props = getProperties(); + + // Get the property's type + PropertyPtr propProperty = props->getInstanceProperty(name); + if (!propProperty) { + std::string msg("Property not found: "); + msg += name; + throwException(SystemConfigurationException, msg.c_str()); + } + const Type& propType = propProperty->getType(); + if (propType.isDataType()) + { + if (propProperty->isMany()) + { + DataObjectList& dol = props->getList(*propProperty); + dol.append(value->getCString("")); + } + else + { + props->setCString(*propProperty, value->getCString("")); + } + } + else + { + // Create a new instance of the DO + // iterate over properties setting each one + // for now: + props->setDataObject(*propProperty, value); + } + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Component.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Component.h new file mode 100644 index 0000000000..882d79a94c --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Component.h @@ -0,0 +1,183 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_component_h +#define tuscany_sca_model_component_h + +#include <string> +#include <map> + +#include "commonj/sdo/SDO.h" + +#include "tuscany/sca/export.h" + + +namespace tuscany +{ + namespace sca + { + namespace model + { + + class Composite; + class ComponentType; + class Reference; + class ReferenceType; + class Service; + class ServiceType; + + /** + * A component is a configured instance of an implementation. Components provide + * and consume services. More than one component can use and configure the same + * implementation, where each component configures the implementation differently. + * For example each component may configure a reference of the same implementation + * to consume a different service. + */ + class Component + { + public: + + /** + * Constructor + * @param composite The composite containing the component. + * @param name The name of the component. + */ + SCA_API Component(Composite *composite, const std::string& name, ComponentType *type); + + /** + * Destructor. + */ + SCA_API virtual ~Component(); + + /** + * Returns the name of this component. + * @return the name of this component + */ + SCA_API const std::string& getName() const { return name; } + + /** + * Returns the composite containing this component. + * @return The composite containing this component. + */ + SCA_API Composite* getComposite() const { return composite; } + + /** + * Returns the type of this component. + * @return The type of this component. + */ + SCA_API ComponentType* getType() const { return type; } + + /** + * Add a new service to this component. + * @param service The service to add. + */ + SCA_API void addService(Service* service); + + /** + * Find an existing service on this component. + * @param serviceName The name of the service to find. + * If the serviceName is the zero length string then if there is + * only one service it will be returned. + * @return The found service, or 0 if not found. + */ + SCA_API Service* findService(const std::string& serviceName); + + /** + * Add a new reference to this component. + * @param reference The reference to add. + */ + SCA_API void addReference(Reference* reference); + + /** + * Find an existing reference on this component. + * @param referenceName The name of the reference to find. + * @return The found reference, or 0 if not found. + */ + SCA_API Reference* findReference(const std::string& referenceName); + + /** + * Returns all the services defined on this component. + * @return All the services defined on this component. + */ + typedef std::map<std::string, Service*> SERVICE_MAP; + SCA_API const SERVICE_MAP& getServices() const { return services; }; + + /** + * Returns all the references defined on this component. + * @return All the references defined on this component. + */ + typedef std::map<std::string, Reference*> REFERENCE_MAP; + SCA_API const REFERENCE_MAP& getReferences() const { return references; }; + + /** + * Set the value of a property defined on this component. The values + * will usually come from a component declaration in a composite file. + * @param name The name of the property. + * @param value The value of the property. + */ + SCA_API void setProperty(const std::string& name, commonj::sdo::DataObjectPtr value); + + /** + * Returns a data object from which all the properties of the component + * and their values can be accessed. + * @return A data object holding the property values. + */ + SCA_API commonj::sdo::DataObjectPtr getProperties(); + + private: + + /** + * Name of the component. + */ + std::string name; + + /** + * Composite containing the component. + */ + Composite* composite; + + /** + * Type of the component. + */ + ComponentType* type; + + /** + * Map of all the services defined on this component. + */ + SERVICE_MAP services; + + /** + * Map of all the references defined on this component. + */ + REFERENCE_MAP references; + + /** + * The properties and their values for this component. + */ + commonj::sdo::DataObjectPtr properties; + + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_component_h diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ComponentType.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ComponentType.cpp new file mode 100644 index 0000000000..20e70ede20 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ComponentType.cpp @@ -0,0 +1,294 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include <iostream> + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/Exceptions.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/model/ComponentType.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/Reference.h" + +using namespace std; +using namespace commonj::sdo; +using namespace tuscany::sca::util; + +namespace tuscany +{ + namespace sca + { + namespace model + { + + // Constructor + ComponentType::ComponentType(Composite* composite, const string& name) + : composite(composite), name(name) + { + logentry(); + } + + // Destructor + ComponentType::~ComponentType() + { + logentry(); + } + + void ComponentType::addServiceType(ServiceType* serviceType) + { + logentry(); + serviceTypes[serviceType->getName()] = serviceType; + } + + ServiceType* ComponentType::findServiceType(const string& serviceName) + { + logentry(); + + // If serviceName is empty then return the ONLY service + if (serviceName == "" + && serviceTypes.size() == 1) + { + return serviceTypes.begin()->second; + } + else + { + return serviceTypes[serviceName]; + } + } + + void ComponentType::addReferenceType(ReferenceType* referenceType) + { + logentry(); + + referenceTypes[referenceType->getName()] = referenceType; + } + + ReferenceType* ComponentType::findReferenceType(const string& referenceName) + { + logentry(); + + return referenceTypes[referenceName]; + } + + void ComponentType::addPropertyType(const string& name, + const string& type, + bool many, + DataObjectPtr* defaultValue) + { + logentry(); + + // Create a Type in the Properties dataFactory + DataFactoryPtr factory = getPropertyDataFactory(); + + string typeUri, typeName; + Utils::tokeniseQName(type, typeUri, typeName); + + if (typeUri == "http://www.w3.org/2001/XMLSchema") + { + typeUri = "commonj.sdo"; + if (typeName == "string") + { + typeName = "String"; + } + else if (typeName == "anyType") + { + typeName = "DataObject"; + } + else if (typeName == "int") + { + typeName = "Int"; + } + else if (typeName == "integer") + { + typeName = "Integer"; + } + else if (typeName == "negativeInteger") + { + typeName = "Integer"; + } + else if (typeName == "nonNegativeInteger") + { + typeName = "Integer"; + } + else if (typeName == "positiveInteger") + { + typeName = "Integer"; + } + else if (typeName == "nonPositiveInteger") + { + typeName = "Integer"; + } + else if (typeName == "unsignedLong") + { + typeName = "Integer"; + } + else if (typeName == "unsignedShort") + { + typeName = "Integer"; + } + else if (typeName == "unsignedInt") + { + typeName = "Long"; + } + else if (typeName == "long") + { + typeName = "Long"; + } + else if (typeName == "double") + { + typeName = "Double"; + } + else if (typeName == "short") + { + typeName = "Short"; + } + else if (typeName == "unsignedByte") + { + typeName = "Short"; + } + else if (typeName == "float") + { + typeName = "Float"; + } + else if (typeName == "boolean") + { + typeName = "Boolean"; + } + else if (typeName == "byte") + { + typeName = "Byte"; + } + else if (typeName == "base64Binary") + { + typeName = "Bytes"; + } + else if (typeName == "hexBinary") + { + typeName = "Bytes"; + } + else if (typeName == "anyURI") + { + typeName = "URI"; + } + else if (typeName == "QName") + { + typeName = "URI"; + } + else + { + // Default unknown xs: types to string?? + typeName = "String"; + } + } + else + { + // It's not an XML type + } + + factory->addPropertyToType( + "org/osoa/sca", + "Properties", + name.c_str(), + typeUri.c_str(), + typeName.c_str(), + many, + false, + true); + + // Set the default for a dataType + if (defaultValue!=NULL) + { + try + { + const Type& propType = factory->getType(typeUri.c_str(), typeName.c_str()); + if (propType.isDataType()) + { + factory->setDefault("org/osoa/sca", "Properties", + name.c_str(), + (char*)(*defaultValue)->getCString("")); + } + } + catch (SDOTypeNotFoundException&) + { + } + } + } + + const Property* ComponentType::findPropertyType(const string& propertyName) + { + logentry(); + const Property* property = NULL; + + DataFactoryPtr dataFactory = getPropertyDataFactory(); + const Type& propertiesType = dataFactory->getType("org/osoa/sca", "Properties"); + + try + { + const Property& prop = propertiesType.getProperty(propertyName); + property = ∝ + } + catch(SDOPropertyNotFoundException) + { + loginfo("Property named %s not found, returning null", propertyName.c_str()); + } + return property; + } + + DataFactoryPtr ComponentType::getPropertyDataFactory() + { + logentry(); + + if (!propertyFactory) + { + propertyFactory = DataFactory::getDataFactory(); + // Add the root type + propertyFactory->addType("org/osoa/sca", "Properties", false, false, false, false); + } + return propertyFactory; + } + + void ComponentType::initializeComponent(Component* component) + { + logentry(); + + for (SERVICETYPE_MAP::iterator iter = serviceTypes.begin(); + iter != serviceTypes.end(); + iter++) + { + Service* service = new Service(component, iter->second); + component->addService(service); + } + for (REFERENCETYPE_MAP::iterator refiter = referenceTypes.begin(); + refiter != referenceTypes.end(); + refiter++) + { + Reference* reference = new Reference(component, refiter->second); + component->addReference(reference); + } + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ComponentType.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ComponentType.h new file mode 100644 index 0000000000..86f17890e9 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ComponentType.h @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_componenttype_h +#define tuscany_sca_model_componenttype_h + +#include <string> +#include <map> + +#include "commonj/sdo/SDO.h" + +#include "tuscany/sca/model/ReferenceType.h" + +namespace tuscany +{ + namespace sca + { + namespace model + { + class ServiceType; + class ReferenceType; + class Interface; + class Component; + class Composite; + + /** + * Component type represents the configurable aspects of an implementation. + * A component type consists of services that are offered, references to other services + * that can be wired and properties that can be set. The settable properties and the settable + * references to services are configured by a component which uses the implementation. + * The component type can be thought of as the contract which is honoured by an implementation. + */ + class ComponentType + { + public: + + /** + * Constructor + */ + SCA_API ComponentType(Composite* composite, const std::string& name); + + /** + * Destructor. + */ + SCA_API virtual ~ComponentType(); + + /** + * Returns the name of the component type + */ + SCA_API const std::string& getName() const { return name; }; + + /** + * Returns the composite containing this component type + */ + SCA_API Composite* getComposite() const { return composite; }; + + /** + * Add a new service type to this component type. + * @param serviceType The service type to add. + */ + SCA_API virtual void addServiceType(ServiceType* serviceType); + + /** + * Find an existing service type on this component type. + * @param serviceName The name of the service type to find. + * If the serviceName is the zero length string then if there is + * only one service type it will be returned. + * @return The found service, or 0 if not found. + */ + SCA_API virtual ServiceType* findServiceType(const std::string& serviceName); + + /** + * Add a new reference type to this component type. + * @param referenceType The reference type to add. + */ + SCA_API virtual void addReferenceType(ReferenceType* referenceType); + + /** + * Find an existing reference type on this component type. + * @param referenceName The name of the reference type to find. + * @return The found reference type, or 0 if not found. + */ + SCA_API virtual ReferenceType* findReferenceType(const std::string& referenceName); + + /** + * Returns the service types defined on this component. + * @return The service types defined on this component. + */ + typedef std::map<std::string, ServiceType*> SERVICETYPE_MAP; + SERVICETYPE_MAP getServiceTypes() const { return serviceTypes; }; + + /** + * Returns the reference types defined on this component. + * @return The reference types defined on this component. + */ + typedef std::map<std::string, ReferenceType*> REFERENCETYPE_MAP; + REFERENCETYPE_MAP getReferenceTypes() const { return referenceTypes; }; + + /** + * Add a new property type to this component type. Property types are added + * one at a time. The property definitions usually come from a component type file. + * @param name The name of the property type. + * @param type The full name of the property data type (including uri and local name). + * @param many True if this is a many valued property. + * @param defaultValue The default value if the property does not have a + * value set. + */ + SCA_API virtual void addPropertyType(const std::string& name, + const std::string& type, + bool many, + commonj::sdo::DataObjectPtr* defaultValue); + + /** + * Find an existing property type on this component type. + * @param propertyName The name of the property type to find. + * @return The found property, or 0 if not found. + */ + SCA_API virtual const commonj::sdo::Property* findPropertyType(const std::string& propertyName); + + /** + * Return the SDO data factory which has the types of the properties defined + * in this component type. + * @return The data factory. + */ + SCA_API virtual commonj::sdo::DataFactoryPtr getPropertyDataFactory(); + + /** + * Initialize a component of this type. + * @param component The component to initialize. + */ + SCA_API virtual void initializeComponent(Component* component); + + private: + + /** + * The name of the component type + */ + std::string name; + + /** + * The composite containing this component type + */ + Composite* composite; + + /** + * Map of all the service types defined on this component. + */ + SERVICETYPE_MAP serviceTypes; + + /** + * Map of all the reference types defined on this component. + */ + REFERENCETYPE_MAP referenceTypes; + + /** + * SDO data factory which has all the types of the properties defined in + * this component type + */ + commonj::sdo::DataFactoryPtr propertyFactory; + + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_componenttype_h + diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Composite.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Composite.cpp new file mode 100644 index 0000000000..6456b0cede --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Composite.cpp @@ -0,0 +1,427 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/CompositeReference.h" +#include "tuscany/sca/model/CompositeReferenceBinding.h" +#include "tuscany/sca/model/CompositeService.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/model/Wire.h" +#include "tuscany/sca/model/WSDLDefinition.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/ServiceBinding.h" +#include "tuscany/sca/model/ReferenceBinding.h" + +using namespace std; +using namespace tuscany::sca::util; + +namespace tuscany +{ + namespace sca + { + + namespace model + { + + // Constructor + Composite::Composite(const string& name, const string& root) + : ComponentType(0, name), root(root) + { + 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() + { + logentry(); + } + + void Composite::addComponent(Component* component) + { + logentry(); + components[component->getName()] = component; + } + + void Composite::addCompositeReference(CompositeReference* compositeReference) + { + logentry(); + components[compositeReference->getName()] = compositeReference; + + // Create a reference type describing the composite reference + ServiceType* serviceType = compositeReference->getType()->findServiceType(""); + ReferenceType* referenceType = new ReferenceType( + this, compositeReference->getName(), + serviceType->getInterface(), + serviceType->getCallbackInterface(), + compositeReference->getMultiplicity()); + addReferenceType(referenceType); + } + + void Composite::addCompositeService(CompositeService* compositeService) + { + logentry(); + components[compositeService->getName()] = compositeService; + + // Create a service type describing the composite service + ReferenceType* referenceType = compositeService->getType()->findReferenceType(""); + ServiceType* serviceType = new ServiceType( + this, compositeService->getName(), + referenceType->getInterface(), + referenceType->getCallbackInterface()); + addServiceType(serviceType); + } + + void Composite::initializeComponent(Component* component) + { + ComponentType::initializeComponent(component); + + // Create bindings for all the services + const Component::SERVICE_MAP& services = component->getServices(); + Component::SERVICE_MAP::const_iterator iter = services.begin(); + for (unsigned int i=0; i< services.size(); i++) + { + Service *service = iter->second; + //CompositeServiceBinding* binding = new CompositeServiceBinding(service); + //service->setBinding(binding); + iter++; + } + + // Create bindings for all the references + const Component::REFERENCE_MAP& references = component->getReferences(); + Component::REFERENCE_MAP::const_iterator refiter = references.begin(); + for (unsigned int ri=0; ri< references.size(); ri++) + { + Reference *reference = refiter->second; + CompositeReferenceBinding* binding = new CompositeReferenceBinding(reference); + reference->setBinding(binding); + refiter++; + } + } + + Component* Composite::findComponent(const std::string& name) + { + logentry(); + Component* component = components[name]; + return component; + } + + std::list<std::string> Composite::getComponents() const + { + logentry(); + + std::list<std::string> componentList; + COMPONENT_MAP::const_iterator iter = components.begin(); + COMPONENT_MAP::const_iterator iterEnd = components.end(); + + for( ; iter != iterEnd; ++iter ) + { + componentList.push_back( iter->first ); + } + + return componentList; + } + + Service* Composite::findComponentService(const std::string& name) + { + logentry(); + + Service* service = 0; + + string componentName; + string serviceName; + Utils::tokeniseUri(name, componentName, serviceName); + + // Locate the component + Component* component = findComponent(componentName); + if (component) + { + // Locate the service + service = component->findService(serviceName); + } + return service; + } + + void Composite::addWire(const std::string& source, const std::string& target) + { + logentry(); + Wire* wire=new Wire(source, target); + wires.push_back(wire); + } + + void Composite::addInclude(Composite* composite) + { + logentry(); + includes[composite->getName()] = composite; + + for (COMPONENT_MAP::iterator iter = composite->components.begin(); + iter != composite->components.end(); + iter++) + { + components[iter->first] = iter->second; + } + } + + void Composite::resolveWires() + { + logentry(); + + for (WIRES::iterator iter = wires.begin(); + iter != wires.end(); + iter++) + { + Wire* wire = *iter; + + // Find the source component and reference + Component* component = findComponent(wire->getSourceComponent()); + Reference* reference; + if (component) + { + reference = component->findReference(wire->getSourceReference()); + if (!reference) + { + logerror("Wire source reference %s not found", wire->getSourceReference().c_str()); + } + } + else + { + reference = NULL; + logerror("Wire source %s not found", wire->getSourceComponent().c_str()); + } + + // Configure the reference binding with the wire target URI + if (reference) + { + reference->getBinding()->configure(wire->getTarget()); + } + } + } + + void Composite::addWSDLDefinition(commonj::sdo::DataObjectPtr wsdlModel) + { + logentry(); + WSDLDefinition* wsdlDefinition = new WSDLDefinition(wsdlModel); + + WSDLDefinition* existingDefinition = wsdlDefinitions[wsdlDefinition->getNamespace()]; + if (existingDefinition == NULL) + { + wsdlDefinitions[wsdlDefinition->getNamespace()] = wsdlDefinition; + } + else{ + existingDefinition->addWSDLModel(wsdlModel); + } + } + + WSDLDefinition* Composite::findWSDLDefinition(const std::string& wsdlNamespace ) + { + logentry(); + // remember the map operator[] inserts a blank object if key not found + WSDL_MAP::iterator iter = wsdlDefinitions.find( wsdlNamespace ); + if( iter == wsdlDefinitions.end() ) + { + return NULL; + } + + return iter->second; + } + + std::list<std::string> Composite::getWSDLNamespaces() const + { + logentry(); + std::list<std::string> namespaceList; + WSDL_MAP::const_iterator iter = wsdlDefinitions.begin(); + WSDL_MAP::const_iterator iterEnd = wsdlDefinitions.end(); + + for( ; iter != iterEnd; ++iter ) + { + namespaceList.push_back( iter->first ); + } + + return namespaceList; + } + + Composite* Composite::findIncludedComposite(const std::string& compositeName) + { + logentry(); + + // remember the map operator[] inserts a blank object if key not found + INCLUDES::iterator iter = includes.find( compositeName ); + if( iter == includes.end() ) + { + return NULL; + } + + return iter->second; + } + + std::list<std::string> Composite::getIncludedComposites() const + { + logentry(); + std::list<std::string> compositeList; + INCLUDES::const_iterator iter = includes.begin(); + INCLUDES::const_iterator iterEnd = includes.end(); + + for( ; iter != iterEnd; ++iter ) + { + compositeList.push_back( iter->first ); + } + + return compositeList; + } + + commonj::sdo::XSDHelperPtr Composite::getXSDHelper() + { + logentry(); + if (xsdHelper == 0) + { + xsdHelper = commonj::sdo::HelperProvider::getXSDHelper(); + } + + return xsdHelper; + } + + commonj::sdo::XMLHelperPtr Composite::getXMLHelper() + { + logentry(); + if (xmlHelper == 0) + { + xmlHelper = commonj::sdo::HelperProvider::getXMLHelper(getXSDHelper()->getDataFactory()); + } + + return xmlHelper; + } + + commonj::sdo::DataFactoryPtr Composite::getDataFactory() + { + logentry(); + return getXSDHelper()->getDataFactory(); + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Composite.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Composite.h new file mode 100644 index 0000000000..40626feb14 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Composite.h @@ -0,0 +1,250 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_composite_h +#define tuscany_sca_model_composite_h + +#include <string> +#include <map> +#include <vector> + +#include "commonj/sdo/SDO.h" + +#include "tuscany/sca/export.h" +#include "tuscany/sca/model/ComponentType.h" + +#define COPY_COMPOSITES_ON_INSTANCIATION + +namespace tuscany +{ + namespace sca + { + + namespace model + { + class Component; + class ComponentType; + class CompositeReference; + class CompositeService; + class Service; + class WSDLDefinition; + class Wire; + + /** + * Represents a composite. + * A composite is used to assemble SCA elements in logical groupings. + * It is the basic unit of composition within an SCA System. An SCA composite contains a + * set of components, services, references and the wires that interconnect them, plus a set + * of properties which can be used to configure components. + */ + class Composite : public ComponentType + { + public: + + /** + * Constructor. + * @param name the name of the composite. + * @param root the root of the composite in the file system. + */ + 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. + */ + SCA_API virtual ~Composite(); + + /** + * Returns the root directory of the composite. + * @return The root of the composite in the file system. + */ + SCA_API const std::string& getRoot() const { return root; } + + /** + * Add a new component to the composite. + * @param component The component to add. + */ + SCA_API void addComponent(Component* component); + + /** + * Add a new composite reference to the composite. + * @param compositeReference The composite reference to add. + */ + SCA_API void addCompositeReference(CompositeReference* compositeReference); + + /** + * Add a new composite service to the composite. + * @param compositeService The composite service to add. + */ + SCA_API void addCompositeService(CompositeService* compositeService); + + /** + * Add/include a composite in this composite. + * @param composite The composite included in this composite. + */ + SCA_API void addInclude(Composite* composite); + + /** + * Add a wire to the model. + * @param source The source location. Either the source component and + * reference (optional), or an entry point. + * @param target The target location. Either the target component and + * service (optional), or an external service. + */ + SCA_API void addWire(const std::string& source, const std::string& target); + + /** + * Find a component by name. + * @param componentName The name of the component to be found. + * @return The component that was found, or 0 if not found. + */ + SCA_API Component* findComponent(const std::string& componentName); + + /** + * Get all included components + * @return A list of Component name strings + */ + SCA_API std::list<std::string> getComponents() const; + + /** + * Find a component and service by name. + * @param componentServiceName A string of the form + * "componentName"/"serviceName" where the service name is optional + * if there is only one service on the component. + * @return The Service that was found, or 0 if not found. + */ + SCA_API Service* findComponentService(const std::string& componentServiceName); + + /** + * Add a WSDL definition to the composite. + * @param wsdlModel A data object holding all the information about + * the WSDL definition from a WSDL file. + */ + SCA_API void addWSDLDefinition(commonj::sdo::DataObjectPtr wsdlModel); + + /** + * Find a WSDL definition by target namespace. + * @param wsdlNamespace The namespace of the WSDL definitions to find. + */ + SCA_API WSDLDefinition* findWSDLDefinition(const std::string& wsdlNamespace); + + /** + * Get all loaded WSDL namespaces + * @return A list of strings, each of which is a different project namespace + */ + SCA_API std::list<std::string> getWSDLNamespaces() const; + + /** + * Find an Included Composite by its name + * @param compositeName The name of the included composite to find. + */ + SCA_API Composite* findIncludedComposite(const std::string& compositeName); + + /** + * Get all included composites + * @return A list of Composite name strings + */ + SCA_API std::list<std::string> getIncludedComposites() const; + + /** + * Initialize a component of this type. + * @param component The component to initialize. + */ + virtual void initializeComponent(Component* component); + + /** + * Return a cached SDO XSDHelper. + */ + SCA_API commonj::sdo::XSDHelperPtr getXSDHelper(void); + + /** + * Return a cached SDO XMLHelper. + */ + SCA_API commonj::sdo::XMLHelperPtr getXMLHelper(void); + + /** + * Return a data factory which has all the types defined in XSDs and + * WSDL files configured for this composite. + * @return The data factory for this composite. + */ + SCA_API commonj::sdo::DataFactoryPtr getDataFactory(void); + + /** + * Work through the list of wires and connect the source and target uris. + */ + SCA_API void resolveWires(); + + private: + + /** + * Directory of the root of the composite. + */ + std::string root; + + /** + * Cached XSDHelper. + */ + commonj::sdo::XSDHelperPtr xsdHelper; + + /** + * Cached XMLHelper. + */ + commonj::sdo::XMLHelperPtr xmlHelper; + + /** + * Map (by name) of all the components in this composite. + */ + typedef std::map<std::string, Component*> COMPONENT_MAP; + COMPONENT_MAP components; + + /** + * Map of all the composites included by this composite. + * Map the Composite name to the Composite + */ + typedef std::map<std::string, Composite*> INCLUDES; + INCLUDES includes; + + /** + * Vector of all the wires in this composite. + */ + typedef std::vector<Wire*> WIRES; + WIRES wires; + + /** + * Map by namespace of all the wsdl definitions in this composite. + */ + typedef std::map<std::string, WSDLDefinition*> WSDL_MAP; + WSDL_MAP wsdlDefinitions; + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_composite_h diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeReference.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeReference.cpp new file mode 100644 index 0000000000..be0bf71a17 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeReference.cpp @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/model/CompositeReference.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/ComponentType.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/Service.h" + +using namespace std; + +namespace tuscany +{ + namespace sca + { + + namespace model + { + + // Constructor + CompositeReference::CompositeReference(Composite* composite, const string& name, + Interface* intface, Interface* callbackInterface, bool conversational, ReferenceType::Multiplicity multiplicity) : + Component(composite, name, new ComponentType(composite, name)) + { + logentry(); + loginfo("Composite reference name: %s", name.c_str()); + + // Initialize the component type, service type and service + ComponentType* componentType = getType(); + ServiceType* serviceType = new ServiceType( + componentType, "", intface, callbackInterface); + componentType->addServiceType(serviceType); + + service = new Service(this, serviceType); + addService(service); + } + + // Destructor + CompositeReference::~CompositeReference() + { + logentry(); + } + + } // End namespace model + + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeReference.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeReference.h new file mode 100644 index 0000000000..f5e2166e06 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeReference.h @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_compositereferencetype_h +#define tuscany_sca_model_compositereferencetype_h + +#include <string> + +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/ReferenceType.h" + +namespace tuscany +{ + namespace sca + { + + namespace model + { + class ComponentType; + class Composite; + class Interface; + class Service; + + /** + * Represents a reference in a composite. + * Composite references represent dependencies that the composite has on services provided elsewhere, + * outside the composite. + */ + class CompositeReference : public Component + { + public: + + /** + * Constructor. + * @param name The name of the reference. + */ + SCA_API CompositeReference(Composite* composite, const std::string& name, + Interface* intface, Interface* callbackInterface, bool conversational, ReferenceType::Multiplicity multiplicity); + + /** + * Destructor. + */ + SCA_API virtual ~CompositeReference(); + + /** + * Returns the service exposed by this composite reference. + * @return The service exposed by this composite reference. + */ + SCA_API Service* getService() const { return service; }; + + /** + * Returns the multiplicity of this composite reference + * @return The multiplicity of the composite reference + */ + SCA_API ReferenceType::Multiplicity getMultiplicity() { return multiplicity; } + + private: + + /** + * The service exposed by this composite reference. + */ + Service* service; + + /** + * The multiplicity of this reference + */ + ReferenceType::Multiplicity multiplicity; + + }; + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_compositereferencetype_h + diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeReferenceBinding.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeReferenceBinding.cpp new file mode 100644 index 0000000000..24191285c5 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeReferenceBinding.cpp @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/model/CompositeReferenceBinding.h" + +using namespace std; + +namespace tuscany +{ + namespace sca + { + namespace model + { + + // Constructor + CompositeReferenceBinding::CompositeReferenceBinding(Reference* reference) + : ReferenceBinding(reference, ""), uri("") + { + } + + // Destructor + CompositeReferenceBinding::~CompositeReferenceBinding() + { + } + + void CompositeReferenceBinding::configure(ServiceBinding *binding) + { + setTargetServiceBinding(binding); + } + + ServiceProxy* CompositeReferenceBinding::getServiceProxy() + { + return serviceProxy; + } + + void CompositeReferenceBinding::configure(const string& uri) + { + this->uri = uri; + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeReferenceBinding.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeReferenceBinding.h new file mode 100644 index 0000000000..5c64c3b657 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeReferenceBinding.h @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_compositereferencebinding_h +#define tuscany_sca_model_compositereferencebinding_h + +#include <string> + +#include "tuscany/sca/model/ReferenceBinding.h" + +namespace tuscany +{ + namespace sca + { + namespace model + { + /** + * A default composite reference binding + */ + class CompositeReferenceBinding : public ReferenceBinding + { + public: + + /** + * Constructor. + * @param uri The uri of the binding. + */ + SCA_API CompositeReferenceBinding(Reference* reference); + + /** + * Destructor. + */ + SCA_API virtual ~CompositeReferenceBinding(); + + /** + * Returns the type of binding. + */ + virtual std::string getType() { return "http://www.osoa.org/xmlns/sca/1.0#CompositeServiceBinding"; }; + + /** + * Configure this binding from a service binding. + */ + SCA_API virtual void configure(ServiceBinding* serviceBinding); + + /** + * Configure this binding from a URI. + */ + SCA_API virtual void configure(const std::string& uri); + + /** + * Create a proxy representing the reference to the + * client component. + */ + SCA_API virtual ServiceProxy* getServiceProxy(); + + /** + * Returns the binding URI. + * @return The binding URI. + */ + SCA_API virtual const std::string& getURI() const { return uri; }; + + private: + + /** + * The proxy representing the reference to the client + * component. + */ + ServiceProxy* serviceProxy; + + /** + * The binding URI + */ + std::string uri; + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_compositereferencebinding_h diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeService.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeService.cpp new file mode 100644 index 0000000000..e06dc548c1 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeService.cpp @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/model/CompositeService.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/ComponentType.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/model/ServiceType.h" + +using namespace std; + +namespace tuscany +{ + namespace sca + { + + namespace model + { + + // Constructor + CompositeService::CompositeService(Composite* composite, const string& name, + Interface* intface, Interface* callbackInterface, bool conversational, + ReferenceType::Multiplicity multiplicity) : + Component(composite, name, new ComponentType(composite, name)) + { + logentry(); + loginfo("Composite service name: %s", name.c_str()); + + // Initialize the component type, reference type and reference + ComponentType* componentType = getType(); + ReferenceType* referenceType = new ReferenceType( + componentType, "", intface, callbackInterface, multiplicity); + componentType->addReferenceType(referenceType); + + reference = new Reference(this, referenceType); + addReference(reference); + } + + // Destructor + CompositeService::~CompositeService() + { + logentry(); + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeService.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeService.h new file mode 100644 index 0000000000..8c626ccac3 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/CompositeService.h @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_compositeservicetype_h +#define tuscany_sca_model_compositeservicetype_h + +#include <string> + +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/ReferenceType.h" + +namespace tuscany +{ + namespace sca + { + namespace model + { + class Composite; + class Component; + class Interface; + class Reference; + + /** + * Represents a service in a composite. + * Composite services define the public services provided by the composite, which can be + * accessed from outside the composite. + */ + class CompositeService : public Component + { + + public: + + /** + * Constructor. + * @param componentType The component type on which this service is defined. + * @param name The name of the service. + */ + SCA_API CompositeService(Composite* composite, const std::string& name, + Interface* intface, Interface* callbackInterface, bool conversational, ReferenceType::Multiplicity multiplicity); + + /** + * Destructor. + */ + SCA_API virtual ~CompositeService(); + + /** + * Returns the reference used by this composite service. + * @return The reference used by this composite service. + */ + SCA_API Reference* getReference() const { return reference; }; + + private: + + /** + * The reference used by this composite service. + */ + Reference* reference; + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_compositeservicetype_h + diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Contract.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Contract.cpp new file mode 100644 index 0000000000..99a1d04dc2 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Contract.cpp @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/model/Contract.h" + + +namespace tuscany +{ + namespace sca + { + + namespace model + { + + // Constructor + Contract::Contract(Interface *intface, Interface* callbackInterface) : + iface(intface), callbackInterface(callbackInterface) + { + logentry(); + } + + // Destructor + Contract::~Contract() + { + logentry(); + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Contract.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Contract.h new file mode 100644 index 0000000000..e1d526f842 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Contract.h @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_contract_h +#define tuscany_sca_model_contract_h + +#include "tuscany/sca/model/Interface.h" + +namespace tuscany +{ + namespace sca + { + namespace model + { + /** + * Interface contracts define one or more business functions. These business functions are + * provided by services and are used by references. Services are defined by the interface which + * they implement. + * This interface will typically be extended to support concrete interface type systems, such as + * CPP classes, Java interfaces, WSDL 1.1 portTypes and WSDL 2.0 interfaces. + */ + class Contract + { + public: + + /** + * Constructor. + */ + SCA_API Contract(Interface* intface, Interface* callbackInterface); + + /** + * Destructor. + */ + SCA_API virtual ~Contract(); + + /** + * Returns the interface for invocations from the requestor to the provider. + * @return The interface for invocations from the requestor to the provider. + */ + SCA_API Interface* getInterface() const { return iface; } + + /** + * Returns the interface for invocations from the provider back to the requestor. + * @return The interface for invocations from the provider back to the requestor. + */ + SCA_API Interface* getCallbackInterface() const { return callbackInterface; } + + private: + + /** + * The interface for invocations from the requestor to the provider. + */ + Interface* iface; + + /** + * The interface for invocations from the provider back to the requestor. + */ + Interface* callbackInterface; + + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_contract_h + diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Interface.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Interface.cpp new file mode 100644 index 0000000000..f8dd02a74a --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Interface.cpp @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/model/Interface.h" + + +namespace tuscany +{ + namespace sca + { + + namespace model + { + + // Constructor + Interface::Interface(bool remotable, bool conversational) + : remotable(remotable), conversational(conversational) + { + logentry(); + } + + Interface::~Interface() + { + logentry(); + } + + } // End namespace model + + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Interface.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Interface.h new file mode 100644 index 0000000000..5ac7736d43 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Interface.h @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_interface_h +#define tuscany_sca_model_interface_h + +#include <string> + +namespace tuscany +{ + namespace sca + { + namespace model + { + + /** + * Information about an interface. Subtypes will hold information + * specific to a type of interface. + */ + class Interface + { + + public: + + /** + * Constructor + */ + SCA_API Interface(bool remotable, bool conversational); + + /** + * Destructor + */ + SCA_API virtual ~Interface(); + + /** + * Returns true if the interface is remotable. + * @return True if the interface is remotable. + */ + SCA_API bool isRemotable() const { return remotable; }; + + /** + * Returns true if the interface is conversational. + * @return True if the interface is conversational. + */ + SCA_API bool isConversational() const { return conversational; }; + + /** + * return the QName of schema type for this interface type + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#WSDLInterface") + */ + SCA_API virtual const std::string& getInterfaceTypeQName() = 0; + + private: + + /** + * True if the interface is remotable + */ + bool remotable; + + /** + * True if the interface is conversational + */ + bool conversational; + + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_interface_h + diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ModelLoader.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ModelLoader.cpp new file mode 100644 index 0000000000..549ffcfc7e --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ModelLoader.cpp @@ -0,0 +1,939 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/export.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/core/Exceptions.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/model/ModelLoader.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/CompositeService.h" +#include "tuscany/sca/model/CompositeReference.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/model/WSDLInterface.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/util/File.h" + + +using namespace std; +using namespace commonj::sdo; +using namespace tuscany::sca::util; + + +#if defined(WIN32) || defined (_WINDOWS) +#define PATH_SEPARATOR ";" +#else +#define PATH_SEPARATOR ":" +#endif + +namespace tuscany +{ + namespace sca + { + + namespace model + { + // =========== + // Constructor + // =========== + ModelLoader::ModelLoader(SCARuntime* runtime, Composite* system) + : system(system), runtime(runtime) + { + logentry(); + } + + // ========== + // Destructor + // ========== + ModelLoader::~ModelLoader() + { + logentry(); + } + + // ========================================================= + // load: Load the runtime model from the deployed xml files + // This class has the responsibility for translating from + // the SCDL files to the SCA runtime's in memory model. + // ========================================================= + void ModelLoader::load(const string& systemRoot, const string& systemPath) + { + logentry(); + loginfo("System root: %s", systemRoot.c_str()); + loginfo("System path: %s", systemPath.c_str()); + + // Load composite implementations + // Composite implementations can occur anywhere on the given search path + if (systemPath != "") + { + loadComposites(systemRoot + PATH_SEPARATOR + systemPath); + } + else + { + loadComposites(systemRoot); + } + + // Load system composites + // Composites on the the system root path get included + // in the System composite + loadSystem(systemRoot); + + // Resolve the wires in the system composite + system->resolveWires(); + } + + // ======================================================================== + // loadSystem: + // Load all the composite files on the system root path + // Translate the composite information to composite model objects + // ======================================================================== + void ModelLoader::loadSystem(const string& systemRoot) + { + logentry(); + + // Get all the composite files on the system root path + // These composites are included in the system composite + for (string path = systemRoot; path != ""; ) + { + string dir; + Utils::tokeniseString(PATH_SEPARATOR, path, dir, path); + if (dir != "") + { + loginfo("System root directory: %s", dir.c_str()); + Files files(dir, "*.composite", false); + for (unsigned int i=0; i < files.size(); i++) + { + string fileName = files[i].getDirectory() + "/" + files[i].getFileName(); + Composite* composite = compositeFiles[fileName]; + if (composite) + { + // Include the composite in the system composite + system->addInclude(composite); + } + else + { + // We already got an error or warning indicating why the file + // didn't turn into a composite + } + } + } + } + } + + // ===================================================================== + // loadComposites: + // Load all the composites from any directory under the composite search path + // Translate the composite information to composite model objects + // ===================================================================== + void ModelLoader::loadComposites(const string& searchPath) + { + logentry(); + + // Get all the composite files on the composite search path + for (string path = searchPath; path != ""; ) + { + string dir; + Utils::tokeniseString(PATH_SEPARATOR, path, dir, path); + if (dir != "") + { + loginfo("Composite path directory: %s", dir.c_str()); + Files files(dir, "*.composite", true); + for (unsigned int i=0; i < files.size(); i++) + { + loadCompositeFile(files[i]); + } + } + } + + // Complete the mapping of the composites + for (COMPOSITE_DATAOBJECTS::iterator iter = compositeDataObjects.begin(); + iter != compositeDataObjects.end(); + iter++) + { + mapCompositePass2(iter->first, iter->second); + } + } + + // ==================================================================== + // loadCompositeFile: + // This method is called for each .composite file found under the composite search + // path. The location of this composite file will indicate the root of a composite. + // ==================================================================== + Composite* ModelLoader::loadCompositeFile(const File& file) + { + logentry(); + + loginfo("Composite file name: %s", file.getFileName().c_str()); + + Composite* composite = NULL; + try + { + string fileName = file.getDirectory() + "/" + file.getFileName(); + if (compositeFiles[fileName] == NULL) + { + XMLDocumentPtr compositeFile = getXMLHelper()->loadFile(fileName.c_str()); + if (compositeFile->getRootDataObject() == NULL) + { + logerror("Unable to load file: %s", fileName.c_str()); + } + else + { + // Map the SCDL + composite = mapCompositePass1(file, compositeFile->getRootDataObject()); + + // Load the xsd types and wsdl files in the composite + loadTypeMetadata(file.getDirectory(), composite); + } + } + + } catch (SDORuntimeException& ex) + { + logerror("Unable to load composite: %s", ex.getMessageText()); + } + return composite; + } + + // =========== + // mapCompositePass1 + // =========== + Composite* ModelLoader::mapCompositePass1(const File& file, DataObjectPtr root) + { + logentry(); + + const string& compositeRootDir = file.getDirectory(); + const string compositeName = root->getCString("name"); + loginfo("Composite: %s, root directory: %s", compositeName.c_str(), compositeRootDir.c_str()); + + Composite* composite = new Composite(compositeName, compositeRootDir); + compositeModels[compositeName] = composite; + compositeDataObjects[compositeName] = root; + compositeFiles[file.getDirectory() + "/" + file.getFileName()] = composite; + + // ------------ + // Composite services + // ------------ + DataObjectList& compositeServiceList = root->getList("service"); + for (unsigned int i = 0; i < compositeServiceList.size(); i++) + { + addCompositeService(composite, compositeServiceList[i]); + } + + // ----------------- + // Composite references + // ----------------- + DataObjectList& compositeReferenceList = root->getList("reference"); + for (unsigned int cri = 0; cri < compositeReferenceList.size(); cri++) + { + addCompositeReference(composite, compositeReferenceList[cri]); + } + + // ----- + // Wires + // ----- + DataObjectList& wireList = root->getList("wire"); + for (unsigned int l = 0; l < wireList.size(); l++) + { + string source = wireList[l]->getCString("source"); + string target = wireList[l]->getCString("target"); + composite->addWire(source, target); + } + + return composite; + } + + // =========== + // mapCompositePass2 + // =========== + Composite* ModelLoader::mapCompositePass2(const string& compositeName, DataObjectPtr root) + { + logentry(); + loginfo("Composite: %s", compositeName.c_str()); + + Composite* composite = compositeModels[compositeName]; + + // ---------------------------- + // Add components to the composite + // ---------------------------- + DataObjectList& componentList = root->getList("component"); + unsigned int i; + for (i=0; i < componentList.size(); i++) + { + addComponent(composite, componentList[i]); + } + + // Resolve all the wires inside the composite + composite->resolveWires(); + + return composite; + } + + // ================================= + // addComponent: + // ================================= + void ModelLoader::addComponent(Composite* composite, DataObjectPtr componentDO) + { + logentry(); + + // ------------------- + // Get the component implementation + // ------------------- + DataObjectPtr impl = componentDO->getDataObject("implementation"); + if (!impl) + { + string message = "No implementation for component: "; + message = message + componentDO->getCString("name"); + throwException(SystemConfigurationException, message.c_str()); + } + + // Create the component type + ComponentType* componentType; + string componentTypeName; + string componentTypePath; + + string implTypeQname = impl->getType().getURI(); + implTypeQname += "#"; + implTypeQname += impl->getType().getName(); + + if (implTypeQname == "http://www.osoa.org/xmlns/sca/1.0#SCAImplementation") + { + // Handle a composite implementation + Composite* compositeComponentType = compositeModels[impl->getCString("name")]; + if (!compositeComponentType) + { + string message = "Composite not found: "; + message = message + impl->getCString("name"); + throwException(SystemConfigurationException, message.c_str()); + } +#if defined(COPY_COMPOSITES_ON_INSTANCIATION) + componentType = new Composite(compositeComponentType, composite); +#else + componentType = compositeComponentType; +#endif + } + else + { + + // Locate extension that handles this implementation type + ImplementationExtension* implExtension = runtime->getImplementationExtension(implTypeQname); + if (implExtension) + { + componentType = implExtension->getImplementation(composite, impl); + + // ----------------------- + // Load the .componentType + // ----------------------- + string typeFileName = composite->getRoot() + "/" + componentType->getName() + ".componentType"; + + // Check that the component type file exists + //TODO We need a better and portable way to do this + string dirName; + string fileName; + Utils::rTokeniseString("/", typeFileName, dirName, fileName); + Files files(dirName, fileName, false); + if (files.size() !=0) + { + try + { + XMLDocumentPtr componentTypeFile = getXMLHelper()->loadFile(typeFileName.c_str()); + if (!componentTypeFile || componentTypeFile->getRootDataObject() == 0) + { + // Component type files are optional + logerror("Unable to load file: %s", typeFileName.c_str()); + } + else + { + //Utils::printDO(componentTypeFile->getRootDataObject()); + //commonj::sdo::SDOUtils::printDataObject(componentTypeFile->getRootDataObject()); + addServiceTypes(composite, componentType, componentTypeFile->getRootDataObject()); + addReferenceTypes(composite, componentType, componentTypeFile->getRootDataObject()); + addPropertyTypes(componentType, componentTypeFile->getRootDataObject()); + } + } catch (SDORuntimeException& ex) + { + logerror("Unable to load file:%s", typeFileName.c_str()); + throwException(SystemConfigurationException, ex); + } + } + } + else + { + logerror("Unsupported implementation type: %s", implTypeQname.c_str()); + + string message = "Implementation type not supported: "; + message = message + implTypeQname; + throwException(SystemConfigurationException, message.c_str()); + } + } + + // First check that references and properties exist, some component types + // will create all used references & properties automatically + DataObjectList& refs = componentDO->getList("reference"); + for (unsigned int i=0; i<refs.size(); i++) + { + string refName = refs[i]->getCString("name"); + if (!componentType->findReferenceType(refName)) + { + // Configuration error: reference is not defined + string message = "Undefined reference: " + refName; + throwException(SystemConfigurationException, message.c_str()); + } + } + + DataObjectList& props = componentDO->getList("property"); + for (unsigned int pi=0; pi<props.size(); pi++) + { + string propName = props[pi]->getCString("name"); + if (!componentType->findPropertyType(propName)) + { + // Configuration error: property is not defined + string message = "Undefined property: " + propName; + throwException(SystemConfigurationException, message.c_str()); + } + } + + + // Create the component + Component* component = new Component(composite, componentDO->getCString("name"), componentType); + composite->addComponent(component); + + // ---------- + // Properties + // ---------- + for (unsigned int pi=0; pi<props.size(); pi++) + { + string propName = props[pi]->getCString("name"); + DataObjectPtr propValue = props[pi]->getDataObject("value"); + + component->setProperty(propName, propValue); + } + + // ---------- + // References + // ---------- + for (unsigned int ri=0; ri<refs.size(); ri++) + { + // ---------------------------------------------------------- + // Add the reference to the composite wires to be resolved later + // ---------------------------------------------------------- + string refName = refs[ri]->getCString("name"); + if (!component->findReference(refName)) + { + // Configuration error: reference is not defined + string message = "Undefined reference: " + refName; + throwException(SystemConfigurationException, message.c_str()); + } + + string src = component->getName() + "/" + refName; + + // Get the reference value + string refValue = refs[ri]->getCString("value"); + + composite->addWire(src, refValue); + } + } + + // ===================================================================== + // addServiceTypes: add the services to the component type + // ===================================================================== + void ModelLoader::addServiceTypes(Composite* composite, ComponentType* componentType, DataObjectPtr componentTypeDO) + { + logentry(); + + DataObjectList& serviceTypes = componentTypeDO->getList("service"); + for (unsigned int i=0; i<serviceTypes.size(); i++) + { + Interface* iface = getInterface(composite, serviceTypes[i]); + ServiceType* serviceType = new ServiceType( + componentType, serviceTypes[i]->getCString("name"), iface, NULL); + componentType->addServiceType(serviceType); + } + } + + // =================================================== + // addReferenceTypes: add the references to the component type + // =================================================== + void ModelLoader::addReferenceTypes(Composite* composite, ComponentType* componentType, DataObjectPtr componentTypeDO) + { + logentry(); + + DataObjectList& refs = componentTypeDO->getList("reference"); + for (unsigned int i=0; i<refs.size(); i++) + { + ReferenceType::Multiplicity multiplicity; + if (refs[i]->isSet("multiplicity")) + { + string s = refs[i]->getCString("multiplicity"); + multiplicity = ReferenceType::getMultiplicityFromString(s); + } + else + { + multiplicity = ReferenceType::ONE_ONE; + } + + Interface* iface = getInterface(composite, refs[i]); + + ReferenceType* referenceType = new ReferenceType( + componentType, refs[i]->getCString("name"), iface, NULL, multiplicity); + componentType->addReferenceType(referenceType); + + } + } + + + // ============== + // getInterface + // ============== + Interface* ModelLoader::getInterface(Composite* composite, DataObjectPtr obj) + { + logentry(); + + // ----------------- + // get the interface + // ----------------- + DataObjectPtr iface = obj->getDataObject("interface"); + if (!iface) + { + string message = "No interface for: "; + message = message + obj->getCString("name"); + throwException(SystemConfigurationException, message.c_str()); + } + + string typeQname = iface->getType().getURI(); + typeQname += "#"; + typeQname += iface->getType().getName(); + + if (typeQname == WSDLInterface::typeQName) + { + // Load a WSDL interface + string qname = iface->getCString("interface"); + + return new WSDLInterface(qname, true, false); + } + else + { + // Locate extension that handles this interface type + InterfaceExtension* ifaceExtension = runtime->getInterfaceExtension(typeQname); + if (ifaceExtension) + { + return ifaceExtension->getInterface(composite, iface); + } + else + { + // log this for now. + logerror("Unsupported interface type: %s", typeQname.c_str()); + return 0; + } + } + + } + + // ============================================== + // addProperties: add properties to the component type + // ============================================== + void ModelLoader::addPropertyTypes(ComponentType* componentType, DataObjectPtr componentTypeDO) + { + logentry(); + + DataObjectList& props = componentTypeDO->getList("property"); + for (unsigned int i=0; i<props.size(); i++) + { + //cout << "Property " << props[i]; + + string name = props[i]->getCString("name"); + string type = props[i]->getCString("type"); + bool many=false; + if (props[i]->isSet("many")) + { + many = props[i]->getBoolean("many"); + } + + //TODO need to add support for complex properties, need the SDO + // folks to help understand how to do this... + DataObjectPtr defaultValue = props[i]->getDataObject("value"); + + componentType->addPropertyType(name, type, many, &defaultValue); + } + } + + // =============================================== + // addCompositeService: add an CompositeService to the composite + // =============================================== + void ModelLoader::addCompositeService(Composite* composite, DataObjectPtr compositeServiceDO) + { + logentry(); + + string compositeServiceName = compositeServiceDO->getCString("name"); + + Interface* iface; + if (compositeServiceDO->getDataObject("interface")) + { + iface = getInterface(composite, compositeServiceDO); + } + else + { + iface = NULL; + } + + ReferenceType::Multiplicity multiplicity; + if (compositeServiceDO->isSet("multiplicity")) + { + string s = compositeServiceDO->getCString("multiplicity"); + multiplicity = ReferenceType::getMultiplicityFromString(s); + } + else + { + multiplicity = ReferenceType::ONE_ONE; + } + + CompositeService* compositeService = new CompositeService( + composite, compositeServiceName, iface, NULL, false, multiplicity); + + composite->addCompositeService(compositeService); + + DataObjectList& refs = compositeServiceDO->getList("reference"); + for (unsigned int i=0; i<refs.size(); i++) + { + // ---------------------------------------------------------- + // Add the reference to the composite wires to be resolved later + // ---------------------------------------------------------- + string targ = refs.getCString(i); + composite->addWire(compositeServiceName, targ); + } + + // Get binding, it will be the first and only binding + DataObjectList& bindings = compositeServiceDO->getList("binding"); + if (bindings.size()==0) + { + string message = "No binding for compositeService: "; + message = message + compositeServiceDO->getCString("name"); + throwException(SystemConfigurationException, message.c_str()); + } + DataObjectPtr binding = bindings[0]; + + // Determine the binding type + string bindingType = binding->getType().getName(); + string bindingTypeQname = binding->getType().getURI(); + bindingTypeQname += "#"; + bindingTypeQname += binding->getType().getName(); + + // Locate the extension that handles this binding type + ReferenceBindingExtension* bindingExtension = runtime->getReferenceBindingExtension(bindingTypeQname); + if (bindingExtension) + { + Reference* reference = compositeService->getReference(); + ReferenceBinding* referenceBinding = bindingExtension->getReferenceBinding(composite, reference, binding); + reference->setBinding(referenceBinding); + } + else + { + logerror("Unsupported binding type: %s", bindingTypeQname.c_str()); + + string message = "Binding type not supported: "; + message = message + bindingTypeQname; + throwException(SystemConfigurationException, message.c_str()); + } + } + + + // ========================================================= + // addCompositeReference: add a CompositeReference to the composite + // ========================================================= + void ModelLoader::addCompositeReference(Composite* composite, DataObjectPtr compositeReferenceDO) + { + logentry(); + + string compositeReferenceName = compositeReferenceDO->getCString("name"); + + Interface* iface; + if (compositeReferenceDO->getDataObject("interface")) + { + iface = getInterface(composite, compositeReferenceDO); + } + else + { + iface = NULL; + } + + CompositeReference* compositeReference = new CompositeReference( + composite, compositeReferenceName, iface, NULL, false, ReferenceType::ONE_ONE); + + composite->addCompositeReference(compositeReference); + + // Get binding, it will be the first and only binding + DataObjectList& bindings = compositeReferenceDO->getList("binding"); + if (bindings.size()==0) + { + string message = "No binding for compositeReference: "; + message = message + compositeReferenceDO->getCString("name"); + throwException(SystemConfigurationException, message.c_str()); + } + DataObjectPtr binding = bindings[0]; + + // Determine the binding type + string bindingType = binding->getType().getName(); + string bindingTypeQname = binding->getType().getURI(); + bindingTypeQname += "#"; + bindingTypeQname += binding->getType().getName(); + + // Locate the extension that handles this binding type + ServiceBindingExtension* bindingExtension = runtime->getServiceBindingExtension(bindingTypeQname); + if (bindingExtension) + { + Service *service = compositeReference->getService(); + ServiceBinding* serviceBinding = bindingExtension->getServiceBinding(composite, service, binding); + service->setBinding(serviceBinding); + } + else + { + logerror("Unsupported binding type: %s", bindingTypeQname.c_str()); + + string message = "Binding type not supported: "; + message = message + bindingTypeQname; + throwException(SystemConfigurationException, message.c_str()); + } + } + + + /// + /// Use the Tuscany.config file in the composite root directory to + /// determine which xsds and wsdls to load into a dataFactory. + /// + void ModelLoader::loadTypeMetadata(const string &compositeRootDir, Composite* composite) + { + logentry(); + + // Load the "Tuscany.config" file, if it exists + Files files(compositeRootDir, "Tuscany.config", false); + if (files.size() !=0) + { + for (unsigned int i=0; i < files.size(); i++) + { + string filename = compositeRootDir + "/" + files[i].getFileName(); + XMLDocumentPtr compositeConfigFile = getXMLHelper()->loadFile(filename.c_str()); + if (compositeConfigFile->getRootDataObject() == 0) + { + logerror("Unable to load file: %s", filename.c_str()); + } + else + { + loginfo("Composite config for: %s, root directory: %s", composite->getName().c_str(), compositeRootDir.c_str()); + + if(compositeConfigFile->getRootDataObject()->isSet("xsd")) + { + DataObjectList& xsds = compositeConfigFile->getRootDataObject()->getList("xsd/file"); + + for (unsigned int i=0; i<xsds.size(); i++) + { + if(xsds[i]->isSet("name")) + { + // Load a xsd file -> set the types in the compositeComponents data factory file + string xsdName = compositeRootDir + "/" +xsds[i]->getCString("name"); + loadXMLSchema(composite, xsdName.c_str()); + } + } + } + + + if( compositeConfigFile->getRootDataObject()->isSet("wsdl")) + { + DataObjectList& wsdls = compositeConfigFile->getRootDataObject()->getList("wsdl/file"); + for (unsigned int j=0; j<wsdls.size(); j++) + { + if(wsdls[i]->isSet("name")) + { + string wsdlName = compositeRootDir + "/" +wsdls[j]->getCString("name"); + // Load a wsdl file -> get the types, then the contents of the wsdl + loadXMLSchema(composite, wsdlName.c_str()); + + // Load the contents of the wsdl files + loadWSDLDefinition(composite, wsdlName.c_str()); + } + } + } + } + } + } + else + { + // The default scheme is to have no Tuscany.config file, then we simply load all + // WSDLs and XSDs that we find under the composite root + + Files xsdFiles(compositeRootDir, "*.xsd", true); + for (unsigned int i=0; i < xsdFiles.size(); i++) + { + // Load a xsd file -> set the types in the compositeComponents data factory file + string xsdName = xsdFiles[i].getDirectory() + "/" + xsdFiles[i].getFileName(); + loadXMLSchema(composite, xsdName.c_str()); + + } + + Files wsdlFiles(compositeRootDir, "*.wsdl", true); + for (unsigned int wi=0; wi < wsdlFiles.size(); wi++) + { + // Load a wsdl file -> get the types, then the contents of the wsdl + string wsdlName = wsdlFiles[wi].getDirectory() + "/" + wsdlFiles[wi].getFileName(); + loadXMLSchema(composite, wsdlName.c_str()); + + // Load the contents of the wsdl files + loadWSDLDefinition(composite, wsdlName.c_str()); + } + } + } + + + /// + /// Use the types from an xsd or wsdl file + /// + void ModelLoader::loadXMLSchema(Composite* composite, const char *fileName) + { + logentry(); + loginfo("Loading XML schema %s", fileName); + // Load a xsd file -> set the types in the data factory associated with + // the composite + try { + composite->getXSDHelper()->defineFile(fileName); + //Utils::printTypes(composite->getXSDHelper()->getDataFactory()); + + } catch (SDORuntimeException& ex) + { + logerror("Unable to load schema: %s", fileName); + throwException(SystemConfigurationException, ex); + } + } + + /// + /// Load the web services definition from a wsdl + /// + void ModelLoader::loadWSDLDefinition(Composite* composite, const char *fileName) + { + logentry(); + + try { + // Load the wsdl file + XMLDocumentPtr doc = getXMLHelper()->loadFile(fileName); + + if (doc!=0 && doc->getRootDataObject()!=0) + { + //Utils::printDO(doc->getRootDataObject()); + + // Add the root WSDL object to the composite + composite->addWSDLDefinition(doc->getRootDataObject()); + + } + else + { + logerror("Unable to load or parse WSDL: %s", fileName); + } + + } catch (SDORuntimeException& ex) + { + logerror("Unable to load or parse WSDL: %s", fileName); + throwException(SystemConfigurationException, ex); + } + } + + ////////////////////////////////////////////////////////////////////////////// + // Methods used to load the model into memory + ////////////////////////////////////////////////////////////////////////////// + + /// + /// Get an XSDHelper that has the appropriate XSDs already loaded + /// + const XSDHelperPtr ModelLoader::getXSDHelper() + { + logentry(); + + if (myXSDHelper == 0) + { + + // Create an xsd helper + myXSDHelper = HelperProvider::getXSDHelper(); + + try { + + // Load the Assembly model schema + string root = runtime->getInstallRoot(); + string filename = root + "/xsd/sca.xsd"; + + myXSDHelper->defineFile(filename.c_str()); + + // Tuscany specific xsd for config files + filename = root + "/xsd/tuscany.xsd"; + myXSDHelper->defineFile(filename.c_str()); + + filename = root + "/xsd/wsdl_11.xsd"; + myXSDHelper->defineFile(filename.c_str()); + + filename = root + "/xsd/wsdl_11_http.xsd"; + myXSDHelper->defineFile(filename.c_str()); + + filename = root + "/xsd/wsdl_11_mime.xsd"; + myXSDHelper->defineFile(filename.c_str()); + + filename = root + "/xsd/wsdl_11_soap.xsd"; + myXSDHelper->defineFile(filename.c_str()); + + filename = root + "/xsd/wsdl_11_soap12.xsd"; + myXSDHelper->defineFile(filename.c_str()); + + // Load any schema from the extensions directory + string extensionsRoot = root + "/extensions"; + + Files files(extensionsRoot, "*.xsd", true); + for (unsigned int i=0; i < files.size(); i++) + { + string extensionSchema = files[i].getDirectory() + "/" + files[i].getFileName(); + myXSDHelper->defineFile(extensionSchema.c_str()); + } + + + } catch (SDORuntimeException& ex) + { + throwException(SystemConfigurationException, ex); + } + } + + return myXSDHelper; + } + + /// + /// Get an XMLHelper to load files + /// + const XMLHelperPtr ModelLoader::getXMLHelper() + { + logentry(); + + if (myXMLHelper == 0) { + + // Create an xml helper + myXMLHelper = HelperProvider::getXMLHelper(getXSDHelper()->getDataFactory()); + + } + + return myXMLHelper; + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ModelLoader.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ModelLoader.h new file mode 100644 index 0000000000..b3b3ec2df6 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ModelLoader.h @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_modelloader_h +#define tuscany_sca_model_modelloader_h + +#include <map> + +#include "commonj/sdo/SDO.h" + +#include "tuscany/sca/export.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/model/Interface.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/ComponentType.h" +#include "tuscany/sca/util/File.h" + +namespace tuscany +{ + namespace sca + { + namespace model + { + + /** + * Provides methods to load the runtime model from the SCDL file. + */ + class ModelLoader { + + public: + /** + * Constructor. + * @param system The SCA system to load. + */ + ModelLoader(tuscany::sca::SCARuntime* runtime, Composite* system); + + /** + * Destructor. + */ + virtual ~ModelLoader(); + + /** + * Load the model from the configuration information. + * @param systemRoot The location of the system configuration + * @param systemPath The search path for composites + */ + void load(const std::string& systemRoot, const std::string& systemPath); + + private: + void loadSystem(const std::string& systemRoot); + + void loadComposites(const std::string& searchPath); + Composite* loadCompositeFile(const tuscany::sca::util::File& file); + Composite* mapCompositePass1(const tuscany::sca::util::File& file, commonj::sdo::DataObjectPtr rootDO); + Composite* mapCompositePass2(const std::string& compositeName, commonj::sdo::DataObjectPtr rootDO); + + void addComponent(Composite* composite, commonj::sdo::DataObjectPtr componentDO); + void addCompositeService(Composite* composite, commonj::sdo::DataObjectPtr compositeServiceDO); + void addCompositeReference(Composite* composite, commonj::sdo::DataObjectPtr referenceServiceDO); + + void addServiceTypes(Composite* composite, ComponentType* componentType, commonj::sdo::DataObjectPtr componentTypeDO); + void addReferenceTypes(Composite* composite, ComponentType* componentType, commonj::sdo::DataObjectPtr componentTypeDO); + void addPropertyTypes(ComponentType* componentType, commonj::sdo::DataObjectPtr componentTypeDO); + + void loadTypeMetadata(const std::string &compositeRootDir, Composite* composite); + + void loadXMLSchema(Composite* composite, const char *fileName); + void loadWSDLDefinition(Composite* composite, const char *fileName); + + Interface* getInterface(Composite* composite, commonj::sdo::DataObjectPtr obj); + + SCARuntime* runtime; + + commonj::sdo::XMLHelperPtr myXMLHelper; // Used to load scdl files + commonj::sdo::XSDHelperPtr myXSDHelper; // Used to load xsds + + const commonj::sdo::XSDHelperPtr getXSDHelper(void); + const commonj::sdo::XMLHelperPtr getXMLHelper(void); + + /** + * The composite describing the composition of the system + */ + Composite* system; + + /** + * Maps of all the composites installed on the system. + */ + typedef std::map<std::string, Composite*> COMPOSITE_MODELS; + COMPOSITE_MODELS compositeModels; + + typedef std::map<std::string, commonj::sdo::DataObjectPtr> COMPOSITE_DATAOBJECTS; + COMPOSITE_DATAOBJECTS compositeDataObjects; + + typedef std::map<std::string, Composite*> COMPOSITE_FILES; + COMPOSITE_FILES compositeFiles; + + }; + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_modelloader_h + diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Reference.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Reference.cpp new file mode 100644 index 0000000000..8820379c4e --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Reference.cpp @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/Exceptions.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/ReferenceType.h" + +using namespace std; + +namespace tuscany +{ + namespace sca + { + namespace model + { + + // Constructor + Reference::Reference(Component* component, ReferenceType* referenceType) + : component(component), type(referenceType), binding(0) + { + logentry(); + } + + // Destructor + Reference::~Reference() + { + logentry(); + } + + void Reference::setBinding(ReferenceBinding* binding) + { + this->binding = binding; + } + + ReferenceBinding* Reference::getBinding() const + { + return binding; + } + + void Reference::addTarget(Service* target) + { + logentry(); + + if (type->getMultiplicity() == ReferenceType::ONE_ONE || type->getMultiplicity() == ReferenceType::ZERO_ONE) + { + if (targets.size() > 0) + { + string message = "Duplicate wire for reference: " + type->getName(); + throwException(SystemConfigurationException, message.c_str()); + } + } + + targets.push_back(target); + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Reference.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Reference.h new file mode 100644 index 0000000000..33413b488f --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Reference.h @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_reference_h +#define tuscany_sca_model_reference_h + +#include <vector> + +namespace tuscany +{ + namespace sca + { + namespace model + { + class Component; + class ReferenceType; + class ReferenceBinding; + class Service; + + /** + * An addressable instance of a reference type associated with a particular component. + * Each reference represents a configured version of a logical + * reference type defined in the component type. If the logical reference + * has a multiplicity greater than 1 (0..n or 1..n) then the configured + * reference many have multiple targets. + */ + class Reference + { + public: + /** + * Constructor. + * @param component The component on which the reference is defined. + * @param referenceType The reference type defining the characteristics of the reference. + */ + SCA_API Reference(Component* component, ReferenceType* referenceType); + + /** + * Destructor. + */ + SCA_API virtual ~Reference(); + + /** + * Returns the component on which this reference is defined. + * @return The component on which this reference is defined. + */ + SCA_API Component* getComponent() const { return component; } + + /** + * Returns the reference type defining the characteristics of the reference. + * @return The reference type defining the characteristics of the reference. + */ + SCA_API ReferenceType* getType() const { return type; } + + /** + * Returns the binding supported by the reference. + * @return The binding supported by the reference. + */ + SCA_API ReferenceBinding* getBinding() const; + + /** + * Sets the binding supported by the reference. + * @param binding The binding supported by the reference. + */ + SCA_API void setBinding(ReferenceBinding* binding); + + /** + * Add a target for this reference. There may be more than + * one if the multiplicity is 0..n or 1..n. + * @param target The target of the reference. + */ + SCA_API void addTarget(Service* target); + + typedef std::vector<Service*> TARGETS; + + /** + * Get a vector of all the targets from this reference. + * @return The targets of this reference. + */ + SCA_API const TARGETS& getTargets() const { return targets; } + + private: + + /** + * The component on which this reference is defined. + */ + Component* component; + + /** + * The reference type defining the characteristics of the reference. + */ + ReferenceType* type; + + /** + * The binding supported by this reference + */ + ReferenceBinding* binding; + + /** + * Vector of all the targets wired from this reference. + */ + TARGETS targets; + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_reference_h diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ReferenceBinding.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ReferenceBinding.cpp new file mode 100644 index 0000000000..c4e9d875b6 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ReferenceBinding.cpp @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/model/ReferenceBinding.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Service.h" + + +using namespace std; + +namespace tuscany +{ + namespace sca + { + + namespace model + { + + // Constructor + ReferenceBinding::ReferenceBinding(Reference *reference, const string& uri) : + Binding(uri), reference(reference), targetServiceBinding(0) + { + logentry(); + } + + // Destructor + ReferenceBinding::~ReferenceBinding() + { + logentry(); + } + + void ReferenceBinding::configure(const string& uri) + { + logentry(); + + // Find the target service + Component* component = reference->getComponent(); + Composite* composite = component->getComposite(); + Service* service; + service = composite->findComponentService(uri); + if (!service) + { + logerror("Wire target %s not found", uri.c_str()); + } + else + { + // Configure this binding from the target service binding + configure(service->getBinding()); + } + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ReferenceBinding.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ReferenceBinding.h new file mode 100644 index 0000000000..197d40aabf --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ReferenceBinding.h @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_referencebinding_h +#define tuscany_sca_model_referencebinding_h + +#include <string> + +#include "tuscany/sca/model/Binding.h" + +namespace tuscany +{ + namespace sca + { + class ServiceProxy; + + + namespace model + { + class Reference; + class ServiceBinding; + + /** + * Represents a reference binding. + * Bindings are used by services and references. References use bindings + * to describe the access mechanism used to call an external service (which can + * be a service provided by another SCA composite). Services use bindings to describe + * the access mechanism that clients (which can be a client from another SCA composite) + * have to use to call the service. + * This interface will typically be extended by binding implementations to allow + * specification of binding/transport specific information. + */ + class ReferenceBinding : public Binding + { + public: + + /** + * Constructor to create a new binding. + */ + SCA_API ReferenceBinding(Reference* reference, const std::string& uri); + + /** + * Destructor. + */ + SCA_API virtual ~ReferenceBinding(); + + /** + * Create a proxy representing the reference to the + * client component. + */ + SCA_API virtual ServiceProxy* getServiceProxy() = 0; + + /** + * Configure this binding from a service binding. + */ + SCA_API virtual void configure(ServiceBinding* serviceBinding) = 0; + + /** + * Configure this binding from a URI. + */ + SCA_API virtual void configure(const std::string& uri); + + /** + * Returns the reference. + * @return The reference. + */ + SCA_API Reference* getReference() const { return reference; }; + + /** + * Returns the target service binding. + */ + SCA_API ServiceBinding* getTargetServiceBinding() const { return targetServiceBinding; }; + + protected: + + /** + * Sets the target service binding. + */ + SCA_API void setTargetServiceBinding(ServiceBinding* binding) { targetServiceBinding = binding; }; + + private: + + /** + * The reference configured with the binding. + */ + Reference* reference; + + /** + * The service binding of the target + */ + ServiceBinding* targetServiceBinding; + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_referencebinding_h diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ReferenceType.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ReferenceType.cpp new file mode 100644 index 0000000000..732a14cace --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ReferenceType.cpp @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/Exceptions.h" +#include "tuscany/sca/model/ReferenceType.h" + +using namespace std; + +namespace tuscany +{ + namespace sca + { + namespace model + { + + + // Constructor + ReferenceType::ReferenceType(ComponentType* componentType, const string& name, + Interface* intface, Interface* callbackInterface, Multiplicity multiplicity) + : Contract(intface, callbackInterface), + componentType(componentType), name(name), multiplicity(multiplicity) + { + logentry(); + } + + ReferenceType::~ReferenceType() + { + logentry(); + } + + ReferenceType::Multiplicity ReferenceType::getMultiplicityFromString(const string& multip) + { + logentry(); + + if (multip == "0..1") + { + return ReferenceType::ZERO_ONE; + } + else if (multip == "1..1") + { + return ReferenceType::ONE_ONE; + } + else if (multip == "0..n") + { + return ReferenceType::ZERO_MANY; + } + else if (multip == "1..n") + { + return ReferenceType::ONE_MANY; + } + else + { + return ReferenceType::UNKNOWN; + } + } + + void ReferenceType::setBinding(Binding* binding) + { + this->binding = binding; + } + + Binding* ReferenceType::getBinding() const + { + return binding; + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ReferenceType.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ReferenceType.h new file mode 100644 index 0000000000..87d38ab330 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ReferenceType.h @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_referencetype_h +#define tuscany_sca_model_referencetype_h + +#include <string> + +#include "tuscany/sca/model/Contract.h" + +namespace tuscany +{ + namespace sca + { + namespace model + { + class ComponentType; + class Interface; + class Binding; + + /** + * Represents an SCA reference. SCA references within an implementation represent + * links to services that the implementation uses that must be provided by other components + * in the SCA system. + */ + class ReferenceType : public Contract + { + public: + + /** + * Multiplicity (how many wires can be connected to this + * reference) + */ + enum Multiplicity + { + ZERO_ONE = 1, + ONE_ONE = 2, + ZERO_MANY = 3, + ONE_MANY = 4, + UNKNOWN = 0, + }; + + /** + * Constructor. + * @param name The name of the reference. + */ + SCA_API ReferenceType(ComponentType* componentType, const std::string& name, + Interface* intface, Interface* callbackInterface, Multiplicity multiplicity); + + /** + * Destructor. + */; + SCA_API virtual ~ReferenceType(); + + /** + * Returns the component type on which this reference is defined. + * @return The component type on which this reference is defined. + */ + SCA_API ComponentType* getComponentType() const { return componentType; } + + /** + * Returns the name of the reference. + * @return The name of the reference. + */ + SCA_API const std::string& getName() const { return name; } + + /** + * Returns the multiplicity allowed for wires connected to this reference. + * @return The multiplicity allowed for wires connected to this reference + */ + SCA_API Multiplicity getMultiplicity() const { return multiplicity; } + + /** + * Returns the binding supported by the reference. + * @return The binding supported by the reference. + */ + SCA_API Binding* getBinding() const; + + /** + * Sets the binding supported by the reference. + * @param binding The binding supported by the reference. + */ + SCA_API void setBinding(Binding* binding); + + /** + * Get the multiplicity corresponding to the given + * string. + */ + static Multiplicity getMultiplicityFromString(const std::string& multip); + + private: + + /** + * The component type on which this reference is defined. + */ + ComponentType *componentType; + + /** + * The name of the reference type. + */ + std::string name; + + /** + * The multiplicity allowed for wires connected to this reference. + */ + Multiplicity multiplicity; + + /** + * The binding supported by this reference type. + */ + Binding* binding; + + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_referencetype_h + diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Service.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Service.cpp new file mode 100644 index 0000000000..4df1d1efc6 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Service.cpp @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/Exceptions.h" +#include "tuscany/sca/model/Service.h" + +namespace tuscany +{ + namespace sca + { + namespace model + { + + // Constructor + Service::Service(Component* component, ServiceType* serviceType) + : component(component), type(serviceType), binding(0) + { + logentry(); + } + + // Destructor + Service::~Service() + { + logentry(); + } + + void Service::setBinding(ServiceBinding* binding) + { + this->binding = binding; + } + + ServiceBinding* Service::getBinding() const + { + return binding; + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Service.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Service.h new file mode 100644 index 0000000000..a1f2c5d672 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Service.h @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_service_h +#define tuscany_sca_model_service_h + + +namespace tuscany +{ + namespace sca + { + namespace model + { + class Component; + class ServiceType; + class ServiceBinding; + + /** + * An addressable instance of a service type associated with a particular component. + */ + class Service + { + public: + /** + * Constructor. + * @param component The component on which the service is defined. + * @param serviceType The service type defining the characteristics of the service. + */ + SCA_API Service(Component* component, ServiceType* serviceType); + + /** + * Destructor. + */ + SCA_API virtual ~Service(); + + /** + * Returns the component on which this service is defined. + * @return The component on which this service is defined. + */ + SCA_API Component* getComponent() const { return component; } + + /** + * Returns the service type defining the characteristics of the service. + * @return The service type defining the characteristics of the service. + */ + SCA_API ServiceType* getType() const { return type; } + + /** + * Returns the binding supported by the service. + * @return The binding supported by the service. + */ + SCA_API ServiceBinding* getBinding() const; + + /** + * Sets the binding supported by the service. + * @param binding The binding supported by the service. + */ + SCA_API void setBinding(ServiceBinding* binding); + + private: + + /** + * The component on which this service is defined. + */ + Component* component; + + /** + * The service type defining the characteristics of the service. + */ + ServiceType* type; + + /** + * The binding supported by this service + */ + ServiceBinding* binding; + + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_service_h diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ServiceBinding.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ServiceBinding.cpp new file mode 100644 index 0000000000..ddc5e6a711 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ServiceBinding.cpp @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/model/ServiceBinding.h" + +using namespace std; + + +namespace tuscany +{ + namespace sca + { + + namespace model + { + + // Constructor + ServiceBinding::ServiceBinding(Service* service, const string& uri) : + Binding(uri), service(service) + { + logentry(); + } + + // Destructor + ServiceBinding::~ServiceBinding() + { + logentry(); + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ServiceBinding.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ServiceBinding.h new file mode 100644 index 0000000000..4e68f492a3 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ServiceBinding.h @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_servicebinding_h +#define tuscany_sca_model_servicebinding_h + +#include <string> + +#include "tuscany/sca/model/Binding.h" + + +namespace tuscany +{ + namespace sca + { + class ServiceWrapper; + + namespace model + { + class Service; + + /** + * Represents a service binding. + * Bindings are used by services and references. References use bindings + * to describe the access mechanism used to call an external service (which can + * be a service provided by another SCA composite). Services use bindings to describe + * the access mechanism that clients (which can be a client from another SCA composite) + * have to use to call the service. + * This interface will typically be extended by binding implementations to allow + * specification of binding/transport specific information. + */ + class ServiceBinding : public Binding + { + public: + + /** + * Constructor to create a new binding. + */ + SCA_API ServiceBinding(Service* service, const std::string& uri); + + /** + * Destructor. + */ + SCA_API virtual ~ServiceBinding(); + + /** + * Create a service wrapper handling the interaction + * with the service configured with this binding. + */ + SCA_API virtual ServiceWrapper* getServiceWrapper() = 0; + + /** + * Returns the service + * @return The service. + */ + SCA_API Service* getService() const { return service; }; + + private: + + /** + * The service configured with the binding. + */ + Service* service; + + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_servicebinding_h diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ServiceType.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ServiceType.cpp new file mode 100644 index 0000000000..819a832443 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ServiceType.cpp @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/model/ServiceType.h" + +using namespace std; + +namespace tuscany +{ + namespace sca + { + namespace model + { + + + // Constructor + ServiceType::ServiceType(ComponentType* componentType, const string& name, + Interface* intface, Interface* callbackInterface) + : Contract(intface, callbackInterface), + componentType(componentType), name(name) + { + logentry(); + } + + // Destructor + ServiceType::~ServiceType() + { + logentry(); + } + + void ServiceType::setBinding(Binding* binding) + { + this->binding = binding; + } + + Binding* ServiceType::getBinding() const + { + return binding; + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ServiceType.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ServiceType.h new file mode 100644 index 0000000000..08a76e3b3f --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/ServiceType.h @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_servicetype_h +#define tuscany_sca_model_servicetype_h + +#include <string> + +#include "tuscany/sca/model/Contract.h" + +namespace tuscany +{ + namespace sca + { + namespace model + { + class ComponentType; + class Binding; + class Interface; + + /** + * Represents a service type. Services are used to publish services provided by + * implementations, so that they are addressable by other components. + */ + class ServiceType : public Contract + { + public: + + /** + * Constructor. + * @param componentType The component type on which this service is defined. + * @param name The name of the service. + */ + SCA_API ServiceType(ComponentType* componentType, const std::string& name, + Interface* intface, Interface* callbackInterface); + + /** + * Destructor. + */ + SCA_API virtual ~ServiceType(); + + /** + * Returns the component type on which this service is defined. + * @return The component type on which this service is defined. + */ + SCA_API ComponentType* getComponentType() const { return componentType; } + + /** + * Returns the name of the service type. + * @return The name of the service type + */ + SCA_API const std::string& getName() const { return name; } + + /** + * Returns the binding supported by this service type. + * @return The binding supported by this service type + */ + SCA_API Binding* getBinding() const; + + /** + * Sets the binding supported by this service type. + * @param binding the binding supported by this service type + */ + SCA_API void setBinding(Binding* binding); + + private: + + /** + * The component type on which this service is defined. + */ + ComponentType* componentType; + + /** + * The name of the service type. + */ + std::string name; + + /** + * The binding supported by this service + */ + Binding* binding; + + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_servicetype_h + diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLDefinition.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLDefinition.cpp new file mode 100644 index 0000000000..53971b5a17 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLDefinition.cpp @@ -0,0 +1,633 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include <sstream> +#include <set> + +#include "tuscany/sca/model/WSDLDefinition.h" +#include "tuscany/sca/model/WSDLOperation.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/core/Exceptions.h" + +using namespace std; +using namespace commonj::sdo; +using namespace tuscany::sca::util; + +namespace tuscany +{ + namespace sca + { + namespace model + { + + // Constructor + WSDLDefinition::WSDLDefinition(DataObjectPtr wsdlModel) + { + logentry(); + + wsdlModels.insert(wsdlModels.end(), wsdlModel); + mapOperations( wsdlModel ); + } + + WSDLDefinition::~WSDLDefinition() + { + logentry(); + } + + /// + /// The namespace of the service and other definitions defined in this wsdl definition + string WSDLDefinition::getNamespace() + { + logentry(); + return wsdlModels[0]->getCString("targetNamespace"); + } + + void WSDLDefinition::addWSDLModel(DataObjectPtr wsdlModel) + { + logentry(); + wsdlModels.insert(wsdlModels.end(), wsdlModel); + mapOperations( wsdlModel ); + } + + /// + /// Find the operation defined in this wsdl + /// + const WSDLOperation& WSDLDefinition::findOperation(const string& serviceName, + const string& portName, + const string& operationName) + { + logentry(); + + string operationKey = serviceName+"#"+portName; + STR_OPERATION_MAP::const_iterator spIter = servicePortMap.find(operationKey); + if( spIter == servicePortMap.end() ) + { + stringstream errMessage; + errMessage + << "Unable to find Service and Port: \"" + << serviceName << "," << portName + << "\" in the WSDL definition"; + throwException(SystemConfigurationException, errMessage.str().c_str()); + } + + OPERATION_MAP::const_iterator opIter = spIter->second.find(operationName); + + if (opIter != spIter->second.end()) + { + return opIter->second; + } + else + { + stringstream errMessage; + errMessage + << "Unable to find operation \"" + << serviceName << ":" << portName << ":" << operationName + << "\" in the WSDL definition"; + + throwException(SystemConfigurationException, errMessage.str().c_str()); + } + } + + /// + /// Find the operation defined in this wsdl + /// + const WSDLOperation& WSDLDefinition::findOperation(const string& portTypeName, + const string& operationName) + { + logentry(); + + STR_OPERATION_MAP::const_iterator ptIter = portTypeMap.find(portTypeName); + if( ptIter == portTypeMap.end() ) + { + stringstream errMessage; + errMessage + << "Unable to find PortType: \"" + << portTypeName + << "\" in the WSDL definition"; + throwException(SystemConfigurationException, errMessage.str().c_str()); + } + + OPERATION_MAP::const_iterator opIter = ptIter->second.find(operationName); + + if (opIter != ptIter->second.end()) + { + return opIter->second; + } + else + { + stringstream errMessage; + errMessage + << "Unable to find Operation \"" + << portTypeName << ":" << operationName + << "\" in the WSDL definition"; + throwException(SystemConfigurationException, errMessage.str().c_str()); + } + } + + std::list<std::string> WSDLDefinition::getPortTypes() + { + logentry(); + + std::list<std::string> ptList; + STR_OPERATION_MAP::const_iterator ptIter = portTypeMap.begin(); + STR_OPERATION_MAP::const_iterator ptIterEnd = portTypeMap.end(); + + for( ; ptIter != ptIterEnd; ++ptIter ) + { + ptList.push_back( ptIter->first ); + } + + return ptList; + } + + std::list<std::string> WSDLDefinition::getOperations( const std::string &portTypeName ) + { + logentry(); + + std::list<std::string> ptOpList; + STR_OPERATION_MAP::const_iterator ptIter = portTypeMap.find( portTypeName ); + + if( ptIter == portTypeMap.end() ) + { + stringstream errMessage; + errMessage + << "Unable to find PortType: \"" + << portTypeName + << "\" in the WSDL definition"; + throwException(SystemConfigurationException, errMessage.str().c_str()); + } + + OPERATION_MAP::const_iterator opIter = ptIter->second.begin(); + OPERATION_MAP::const_iterator opIterEnd = ptIter->second.end(); + + for( ; opIter != opIterEnd; ++opIter ) + { + ptOpList.push_back( opIter->first ); + } + + return ptOpList; + } + + /// + /// Find a service + /// + DataObjectPtr WSDLDefinition::findService(const string& serviceName) + { + logentry(); + + DataObjectPtr service = 0; + + // Find the binding + for (unsigned int m = 0; m < wsdlModels.size(); m++) + { + DataObjectList& serviceList = wsdlModels[m]->getList("service"); + for (unsigned int i=0; i<serviceList.size(); i++) + { + string name(serviceList[i]->getCString("name")); + + if (name.compare(serviceName) == 0) + { + return serviceList[i]; + } + } + } + + return service; + } + + + /// + /// Find a named binding + /// + DataObjectPtr WSDLDefinition::findBinding(const string& bindingName) + { + logentry(); + + DataObjectPtr binding = 0; + string uri; + string name; + + Utils::rTokeniseString("#", bindingName, uri, name); + + // Find the binding + for (unsigned int m = 0; m < wsdlModels.size(); m++) + { + DataObjectList& bindingList = wsdlModels[m]->getList("binding"); + for (unsigned int i=0; i<bindingList.size(); i++) + { + string nameBinding(bindingList[i]->getCString("name")); + + if (nameBinding.compare(name) == 0) + { + return bindingList[i]; + } + } + } + + return binding; + } + + /// + /// Find a named portType + /// + DataObjectPtr WSDLDefinition::findPortType(const string& portTypeName) + { + logentry(); + + DataObjectPtr portType = 0; + string uri; + string name; + + Utils::rTokeniseString("#", portTypeName, uri, name); + + // Find the binding + for (unsigned int m = 0; m < wsdlModels.size(); m++) + { + DataObjectList& portTypeList = wsdlModels[m]->getList("portType"); + for (unsigned int i=0; i<portTypeList.size(); i++) + { + string namePortType(portTypeList[i]->getCString("name")); + + if (namePortType.compare(name) == 0) + { + return portTypeList[i]; + } + } + } + + return portType; + } + + /// + /// Find a named message + /// + DataObjectPtr WSDLDefinition::findMessage(const string& messageName) + { + logentry(); + + DataObjectPtr message = 0; + string uri; + string name; + + Utils::rTokeniseString("#", messageName, uri, name); + + // Find the binding + for (unsigned int m = 0; m < wsdlModels.size(); m++) + { + DataObjectList& messageList = wsdlModels[m]->getList("message"); + for (unsigned int i=0; i<messageList.size(); i++) + { + string nameMessage(messageList[i]->getCString("name")); + + if (nameMessage.compare(name) == 0) + { + return messageList[i]; + } + } + } + + return message; + } + + /// + /// Traverse the WSDL SDO and insert operations into the operationMap + /// + void WSDLDefinition::mapOperations( DataObjectPtr wsdlModel ) + { + logentry(); + + // check for duplicate message/binding/PortType/Service + // with equal name attributes. This cant be enforced by + // the schema, so it has to be enforced at the app level + checkForDuplicates( wsdlModel ); + + DataObjectList& serviceList = wsdlModel->getList("service"); + + // Iterate through the WSDL services + for (unsigned int i=0; i < serviceList.size(); i++) + { + string serviceName( serviceList[i]->getCString("name") ); + + // Iterate through the WSDL service ports + DataObjectList& portList = serviceList[i]->getList("port"); + for (unsigned int j=0; j < portList.size();j++) + { + string portName( portList[j]->getCString("name") ); + string wsBindingName(portList[j]->getCString("binding")); + + // There can only be one soap address and the check must be made + // at the application level since it cant be specified in the xsd +/* + DataObjectList& soapAddressList = portList[j]->getList("address"); + if( soapAddressList.size() != 1 ) + { + // Invalid WSDL + stringstream errMessage; + errMessage + << "service/port/address: \"" + << portName + << "\" cannot be duplicated in the WSDL definition"; + throwException(SystemConfigurationException, errMessage.str().c_str()); + } +*/ + + string targetAddress(portList[j]->getCString("address/location")); + + // get the binding specified in the WSDL service port + DataObjectPtr wsBinding = findBinding(wsBindingName); + if (!wsBinding) + { + // Invalid WSDL + stringstream errMessage; + errMessage + << "Unable to find binding \"" + << wsBindingName + << "\" in the WSDL definition"; + throwException(SystemConfigurationException, errMessage.str().c_str()); + } + + // Check if its a SOAP binding, if not go on to the next binding + // doing a find like this will work for SOAP11 and SOAP12 + DataObjectPtr wsBindingSubBinding = wsBinding->getDataObject("binding"); + string bindingURI(wsBindingSubBinding->getType().getURI()); + if (bindingURI.find("http://schemas.xmlsoap.org/wsdl/soap") == string::npos) + { + loginfo("Discarding non-SOAP Binding %s", wsBindingName.c_str() ); + continue; + } + + // Get the port type specified the WSDL binding + string wsBindingPortTypeName(wsBinding->getCString("type")); + DataObjectPtr portType = findPortType(wsBindingPortTypeName); + if (!portType) + { + // Invalid WSDL + stringstream errMessage; + errMessage + << "Unable to find PortType \"" + << wsBindingPortTypeName + << "\" in the WSDL definition"; + throwException(SystemConfigurationException, errMessage.str().c_str()); + } + string portTypeName( portType->getCString("name") ); + + // Fill in this map with operation names to WSDLOperations + // then after iterating through the operations, add the map + // to the portTypeMap, keyed off of the portTypeName + OPERATION_MAP operationMap; + + // For each binding and portType operation: + // - get the soap action, style, and use from the binding + // - get the input and/or output message types + // its ok if not all of the PortType operations are not defined in the binding + DataObjectList& bindingOperationList = wsBinding->getList("operation"); + DataObjectList& portTypeOperationList = portType->getList("operation"); + for (unsigned int k=0; k < bindingOperationList.size(); k++) + { + DataObjectPtr bindingOp = bindingOperationList[k]; + string operationName = bindingOp->getCString("name"); + + // Get the corresponding PortType operation + // I know this may not be very efficient, but its a necessary evil + bool foundPortType = false; + DataObjectPtr portTypeOp; + for (unsigned int l=0; + (!foundPortType && l < portTypeOperationList.size()); + l++) + { + //portTypeOp = portTypeOperationList[l]->getDataObject("operation"); + portTypeOp = portTypeOperationList[l]; + if (operationName == portTypeOp->getCString("name") ) + { + foundPortType = true; + } + } + + if( !foundPortType ) + { + // Invalid WSDL + stringstream errMessage; + errMessage + << "Unable to find PortType operation for binding operation: \"" + << operationName + << "\" in the WSDL definition"; + throwException(SystemConfigurationException, errMessage.str().c_str()); + } + + string soapAction = ""; + bool documentStyle = true; + bool wrappedStyle = true; + bool useEncodedInput = false; + bool useEncodedOutput = false; + WSDLOperation::soapVersion soapVer = WSDLOperation::SOAP11; + + string opType = bindingOp->getType().getURI(); + if (opType == "http://schemas.xmlsoap.org/wsdl/soap12/") + { + soapVer = WSDLOperation::SOAP12; + } + + // Get the soapAction + soapAction = bindingOp->getCString("operation/soapAction"); + + // Get the style + string style = bindingOp->getCString("operation/style"); + if (style == "") + { + style = wsBinding->getCString("binding/style"); + } + if (style != "document") + { + documentStyle = false; + wrappedStyle = false; + } + + // get the use + string use = bindingOp->getCString("input/body/use"); + if (use == "encoded") + { + useEncodedInput = true; + } + + use = bindingOp->getCString("output/body/use"); + if (use == "encoded") + { + useEncodedOutput = true; + } + + // Get the request message type from the PortType + DataObjectPtr wsMessageIn = + findMessage(portTypeOp->getCString("input/message")); + if (!wsMessageIn) + { + stringstream errMessage; + errMessage + << "unable to find PortType input message \"" + << portTypeOp->getCString("input/message") + << "\" in the wsdl definition"; + throwException(SystemConfigurationException, errMessage.str().c_str()); + } + string inputMessageType( wsMessageIn->getCString("name") ); + // If it doesnt have a namespace prefix, add the target namespace + if (inputMessageType.find("#") == string::npos) + { + inputMessageType.insert(0, (getNamespace() + "#") ); + } + + // Get the response message type from the PortType + DataObjectPtr wsMessageOut = + findMessage(portTypeOp->getCString("output/message")); + if (!wsMessageOut) + { + // TODO this is ok for one way operations, right? + stringstream errMessage; + errMessage + << "unable to find PortType output message \"" + << portTypeOp->getCString("output/message") + << "\" in the wsdl definition"; + throwException(SystemConfigurationException, errMessage.str().c_str()); + } + string outputMessageType( wsMessageOut->getCString("name") ); + // If it doesnt have a namespace prefix, add the target namespace + if (outputMessageType.find("#") == string::npos) + { + outputMessageType.insert(0, (getNamespace() + "#") ); + } + + WSDLOperation wsdlOp; + wsdlOp.setOperationName(operationName); + wsdlOp.setSoapAction(soapAction); + wsdlOp.setEndpoint(targetAddress); + wsdlOp.setSoapVersion(soapVer); + wsdlOp.setDocumentStyle(documentStyle); + wsdlOp.setWrappedStyle(wrappedStyle); + wsdlOp.setInputEncoded(useEncodedInput); + wsdlOp.setOutputEncoded(useEncodedOutput); + wsdlOp.setInputMessageType(inputMessageType); + wsdlOp.setOutputMessageType(outputMessageType); + wsdlOp.setInputMessage(wsMessageIn); + wsdlOp.setOutputMessage(wsMessageOut); + + operationMap[ operationName ] = wsdlOp; + + } // end bindingOperationList + + portTypeMap[portTypeName] = operationMap; + servicePortMap[(serviceName+"#"+portName)] = operationMap; + + } // end portTypeList + } // end serviceList + } // end method mapOperations + + void WSDLDefinition::checkForDuplicates( DataObjectPtr wsdlModel ) + { + logentry(); + + // check for duplicate message/binding/PortType/service + // with equal name attributes. This cant be enforced by + // the schema, so it has to be enforced at the app level + + std::set<string> namesSet; + + DataObjectList &messageList = wsdlModel->getList("message"); + for( unsigned int i = 0; i < messageList.size(); i++ ) + { + if( namesSet.find( messageList[i]->getCString("name") ) == namesSet.end() ) + { + namesSet.insert( messageList[i]->getCString("name") ); + } + else + { + // Invalid WSDL + stringstream errMessage; + errMessage + << "message/name: \"" + << messageList[i]->getCString("name") + << "\" cannot be duplicated in the WSDL definition"; + throwException(SystemConfigurationException, errMessage.str().c_str()); + } + } + + namesSet.clear(); + DataObjectList &bindingList = wsdlModel->getList("binding"); + for( unsigned int i = 0; i < bindingList.size(); i++ ) + { + if( namesSet.find( bindingList[i]->getCString("name") ) == namesSet.end() ) + { + namesSet.insert( bindingList[i]->getCString("name") ); + } + else + { + // Invalid WSDL + stringstream errMessage; + errMessage + << "binding/name: \"" + << bindingList[i]->getCString("name") + << "\" cannot be duplicated in the WSDL definition"; + throwException(SystemConfigurationException, errMessage.str().c_str()); + } + } + + namesSet.clear(); + DataObjectList &portTypeList = wsdlModel->getList("portType"); + for( unsigned int i = 0; i < portTypeList.size(); i++ ) + { + if( namesSet.find( portTypeList[i]->getCString("name") ) == namesSet.end() ) + { + namesSet.insert( portTypeList[i]->getCString("name") ); + } + else + { + // Invalid WSDL + stringstream errMessage; + errMessage + << "portType/name: \"" + << portTypeList[i]->getCString("name") + << "\" cannot be duplicated in the WSDL definition"; + throwException(SystemConfigurationException, errMessage.str().c_str()); + } + } + + namesSet.clear(); + DataObjectList &serviceList = wsdlModel->getList("service"); + for( unsigned int i = 0; i < serviceList.size(); i++ ) + { + if( namesSet.find( serviceList[i]->getCString("name") ) == namesSet.end() ) + { + namesSet.insert( serviceList[i]->getCString("name") ); + } + else + { + // Invalid WSDL + stringstream errMessage; + errMessage + << "service/name: \"" + << serviceList[i]->getCString("name") + << "\" cannot be duplicated in the WSDL definition"; + throwException(SystemConfigurationException, errMessage.str().c_str()); + } + } + } + + } // end namespace model + } // end namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLDefinition.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLDefinition.h new file mode 100644 index 0000000000..baf14fcd6d --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLDefinition.h @@ -0,0 +1,180 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_wsdldefinition_h +#define tuscany_sca_model_wsdldefinition_h + +#include <string> +#include <map> +#include <vector> + +#include "commonj/sdo/SDO.h" + +#include "tuscany/sca/export.h" +#include "tuscany/sca/model/WSDLOperation.h" + + +namespace tuscany +{ + namespace sca + { + namespace model + { + + class WSDLOperation; + + /** + * Holds information about a WSDL definition loaded into the runtime. + */ + class WSDLDefinition + { + public: + /** + * Constructor. + * @param wsdlModel The data object representing the WSDL document + * defining a web service. + */ + SCA_API WSDLDefinition(commonj::sdo::DataObjectPtr wsdlModel); + + /** + * Destructor. + */ + SCA_API virtual ~WSDLDefinition(); + + /** + * Returns the target namespace of the WSDL definitions. + * @return The target namespace. + */ + SCA_API std::string getNamespace(void); + + /** + * Add a WSDL model. + */ + SCA_API void addWSDLModel(commonj::sdo::DataObjectPtr wsdlModel); + + /** + * Find an operation in the WSDL definitions. + * @param serviceName The name of the service on which this + * operation is defined. + * @param portName The name of the port in the service to + * use. + * @param operationName The name of the operation to find. + * @return The operation if found. Exception thrown if not found. + */ + SCA_API const WSDLOperation& findOperation(const std::string& serviceName, + const std::string& portName, + const std::string& operationName); + + /** + * Find an operation in the WSDL definitions. + * @param portTypeName The name of the portType on which this + * operation is defined. + * @param operationName The name of the operation to find. + * @return The operation if found. Exception thrown if not found. + */ + SCA_API const WSDLOperation& findOperation(const std::string& portTypeName, + const std::string& operationName); + + /** + * Get all of the PortTypes in this WSDL definition. + * @return A standard list of standard strings, each being a different PortType + */ + SCA_API std::list<std::string> getPortTypes(); + + /** + * Get all of the Operations for a particular PortType in this WSDL definition. + * @param portTypeName Get all of the operations for this portTypeName + * @return A standard list of standard strings, each of which is a different operation + */ + SCA_API std::list<std::string> getOperations( const std::string &portTypeName ); + + private: + + /** + * Find a service in the wsdl definition. + * @param serviceName The name of the service. + * @return A data object describing the service if found, otherwise + * a 0 if not found. + */ + commonj::sdo::DataObjectPtr findService(const std::string& serviceName); + + /** + * Find a binding in the wsdl definition. + * @param bindingName The name of the binding to find. + * @return A data object describing the binding if found, otherwise + * a 0 if not found. + */ + commonj::sdo::DataObjectPtr findBinding(const std::string& bindingName); + + /** + * Find a portType in the wsdl definition. + * @param portTypeName The name of the portType. + * @return A data object describing the portType if found, otherwise + * a 0 if not found. + */ + commonj::sdo::DataObjectPtr findPortType(const std::string& portTypeName); + + /** + * Find a message in the wsdl definition. + * @param messageName The name of the message. + * @return A data object describing the message if found, otherwise + * a 0 if not found. + */ + commonj::sdo::DataObjectPtr findMessage(const std::string& messageName); + + /** + * Given a wsdl represented by an SDO, traverse the SDO and + * extract all of the necessary information to populate the + * operationMap with WSDLOperation objects. + * This method is called each time a wsdl model is added: so + * that would be be in the constructor and in addWSDLModel(). + * @param wsdlModel A wsdl represented by an SDO + */ + void mapOperations( commonj::sdo::DataObjectPtr wsdlModel ); + + /** + * Given a wsdl represented by an SDO, check for duplicate + * message/binding/PortType/service with equal name attributes. + * This cant be enforced by the schema, so it has to be enforced + * at the app level. If a duplicate is found, a + * SystemConfigurationException exception is thrown. + * @param wsdlModel A wsdl represented by an SDO + */ + void checkForDuplicates( commonj::sdo::DataObjectPtr wsdlModel ); + + /** + * The data object representation of the WSDL document. + */ + typedef std::vector<commonj::sdo::DataObjectPtr> MODEL_VECTOR; + MODEL_VECTOR wsdlModels; + + typedef std::map<std::string, WSDLOperation> OPERATION_MAP; + typedef std::map<std::string, OPERATION_MAP> STR_OPERATION_MAP; + STR_OPERATION_MAP portTypeMap; + STR_OPERATION_MAP servicePortMap; + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_wsdldefinition_h + diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLInterface.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLInterface.cpp new file mode 100644 index 0000000000..5fa45a9967 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLInterface.cpp @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/model/WSDLInterface.h" + +using namespace std; + +namespace tuscany +{ + namespace sca + { + namespace model + { + + const string WSDLInterface::typeQName("http://www.osoa.org/xmlns/sca/1.0#WSDLPortType"); + + // Constructor + WSDLInterface::WSDLInterface( + const string& qname, bool remotable, bool conversational) + : Interface(remotable, conversational) + { + logentry(); + parse(qname); + } + + void WSDLInterface::parse(const string& qname) + { + logentry(); + + // PortType is of the form: <wsdl-namepace-uri>#wsdl.interface(<portType-name>) + string::size_type hash = qname.find("#"); + if (hash != string::npos) + { + // Found a hash + + // Namepace is the part before the # + namespaceURI = qname.substr(0, hash); + + if ( (hash+1) < qname.length()) + { + // Check the next part is wsdl.interface( + int ending = hash+16; + string check = qname.substr(hash+1, 15); + if (check.compare("wsdl.interface(") == 0) + { + // Find the matching ) + int endBracket = qname.find(")",ending); + if (endBracket-1 > ending+1) + { + name = qname.substr(ending, endBracket-ending); + } + else + { + // Nothing between the () + name = ""; + } + } + else + { + // not the correct characters after the #, ignore the rest + name = ""; + } + + } + else + { + // Nothing after the hash + name = ""; + } + } + else + { + // No hash at all + namespaceURI = qname; + name = ""; + } + } + + + WSDLInterface::~WSDLInterface() + { + logentry(); + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLInterface.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLInterface.h new file mode 100644 index 0000000000..b071dd221e --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLInterface.h @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_wsdlinterface_h +#define tuscany_sca_model_wsdlinterface_h + +#include <string> + +#include "tuscany/sca/model/Interface.h" + +namespace tuscany +{ + namespace sca + { + namespace model + { + /** + * Holds information about an interface described using a WSDL + * port type. + */ + class WSDLInterface : public Interface + { + + public: + /** + * Constuctor. + * @param interfaceName Name of the WSDL interface. + */ + WSDLInterface(const std::string& qname, bool remotable, bool conversational); + + /** + * Destructor. + */ + virtual ~WSDLInterface(); + + /** + * Returns the WSDL namespace + */ + std::string getNamespaceURI() const { return namespaceURI; } + + /** + * Returns the interface name + */ + std::string getName() const { return name; } + + /** + * return the QName of the schema type for this interface type + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#interface.cpp") + */ + virtual const std::string& getInterfaceTypeQName() { return typeQName; }; + + /** + * The QName of the schema type for this interface type. + */ + SCA_API static const std::string typeQName; + + private: + + /** + * Parse the WSDL qname + */ + void parse(const std::string& qname); + + /** + * WSDL namespace. + */ + std::string namespaceURI; + + /** + * Name of the WSDL interface. + */ + std::string name; + + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_wsdlinterface_h + diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLMessagePart.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLMessagePart.cpp new file mode 100644 index 0000000000..957d7ab3c1 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLMessagePart.cpp @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include <string> + +#include "tuscany/sca/model/WSDLMessagePart.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" + +using namespace std; +using namespace tuscany::sca::util; + +namespace tuscany +{ + namespace sca + { + namespace model + { + + + // Default Constructor + WSDLMessagePart::WSDLMessagePart() + { + logentry(); + } + + // Constructor + WSDLMessagePart::WSDLMessagePart(std::string partName, + std::string partType, + std::string partUri) : + partName_(partName), + partType_(partType), + partUri_(partUri) + { + logentry(); + } + + WSDLMessagePart::~WSDLMessagePart() + { + logentry(); + } + + + void WSDLMessagePart::setMessagePartType(const string& inputType) + { + logentry(); + Utils::tokeniseQName(inputType, partUri_, partName_); + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLMessagePart.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLMessagePart.h new file mode 100644 index 0000000000..2c381011ba --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLMessagePart.h @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_wsdlmessagepart_h +#define tuscany_sca_model_wsdlmessagepart_h + +#include <map> +#include <list> +#include <string> + +#include "tuscany/sca/export.h" + +namespace tuscany +{ + namespace sca + { + namespace model + { + + /** + * Represents a single WSDL defined message part. + */ + class WSDLMessagePart + { + public: + /** + * Default Constructor + */ + SCA_API WSDLMessagePart(); + + /** + * Constructor. + * @param partName The name of the message part. + * @param partType The type of this message part. + * @param partUri The namespace URI for the message part type. + */ + SCA_API WSDLMessagePart( std::string partName, + std::string partType, + std::string partUri ); + + /** + * Destructor. + */ + SCA_API ~WSDLMessagePart(); + + /** + * Return the name of the WSDL Message part + * @return The name of the WSDL Message part + */ + SCA_API const std::string& getPartName() const {return partName_;} + SCA_API void setPartName(const std::string& partName) {partName_ = partName;} + + /** + * The type of this WSDL Message part + * @return The type of this WSDL Message part + */ + SCA_API const std::string& getPartType() const {return partType_;} + SCA_API void setPartType(const std::string& partType) {partType_ = partType;} + + /** + * Set the WSDL message part type and namespace URI + * @return A prefixed namespace and type of the form prefix:type + */ + SCA_API void setMessagePartType(const std::string& partType); + + /** + * Return the namespace URI of the WSDL Message part + * @return The namespace URI of the WSDL Message part + */ + SCA_API const std::string& getPartUri() const {return partUri_;} + SCA_API void setPartUri(const std::string& partUri) {partUri_ = partUri;} + + private: + /** + * The name of this message part + */ + std::string partName_; + + /** + * The type of this message part + */ + std::string partType_; + + /** + * The namespace URI of the message part type + */ + std::string partUri_; + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_wsdlmessagepart_h + diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLOperation.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLOperation.cpp new file mode 100644 index 0000000000..a61d122a72 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLOperation.cpp @@ -0,0 +1,193 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include <map> +#include <list> +#include <string> +#include <sstream> + +#include "tuscany/sca/model/WSDLOperation.h" +#include "tuscany/sca/model/WSDLMessagePart.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/core/Exceptions.h" + +using namespace std; +using namespace commonj::sdo; +using namespace tuscany::sca::util; + +namespace tuscany +{ + namespace sca + { + namespace model + { + + + // Constructor + WSDLOperation::WSDLOperation() + { + logentry(); + } + + WSDLOperation::~WSDLOperation() + { + logentry(); + } + + + void WSDLOperation::setInputMessageType(const string& inputType) + { + logentry(); + Utils::tokeniseQName(inputType, inputMessageUri, inputMessageName); + } + + void WSDLOperation::setOutputMessageType(const string& outputType) + { + logentry(); + Utils::tokeniseQName(outputType, outputMessageUri, outputMessageName); + } + + void WSDLOperation::setInputMessage( commonj::sdo::DataObjectPtr inputMsg ) + { + logentry(); + + DataObjectList &partList = inputMsg->getList("part"); + for( unsigned int i=0; i < partList.size(); i++) + { + string partUri; + string partType; + string partName = partList[0]->getCString("name"); + + Utils::tokeniseQName(partList[0]->getCString("element"), partUri, partType); + WSDLMessagePart part(partName, partType, partUri); + + inputPartMap[partName] = part; + } + } + + void WSDLOperation::setOutputMessage( commonj::sdo::DataObjectPtr outputMsg ) + { + logentry(); + + DataObjectList &partList = outputMsg->getList("part"); + for( unsigned int i=0; i < partList.size(); i++) + { + string partUri; + string partType; + string partName = partList[0]->getCString("name"); + + Utils::tokeniseQName(partList[0]->getCString("element"), partUri, partType); + WSDLMessagePart part(partName, partType, partUri); + + outputPartMap[partName] = part; + } + } + + const std::list<std::string> WSDLOperation::getInputMessagePartNames() const + { + logentry(); + + std::list<std::string> inputPartNames; + + PART_MAP::const_iterator iter = inputPartMap.begin(); + PART_MAP::const_iterator iterEnd = inputPartMap.end(); + + for( ; iter != iterEnd; ++iter ) + { + inputPartNames.push_back( iter->first ); + } + + return inputPartNames; + } + + const std::list<std::string> WSDLOperation::getOutputMessagePartNames() const + { + logentry(); + + std::list<std::string> outputPartNames; + + PART_MAP::const_iterator iter = outputPartMap.begin(); + PART_MAP::const_iterator iterEnd = outputPartMap.end(); + + for( ; iter != iterEnd; ++iter ) + { + outputPartNames.push_back( iter->first ); + } + + return outputPartNames; + } + + const WSDLMessagePart& + WSDLOperation::getInputMessagePart( const std::string &name ) const + { + logentry(); + + PART_MAP::const_iterator iter = inputPartMap.find( name ); + if( iter == inputPartMap.end() ) + { + stringstream errMessage; + errMessage + << "Unable to find input WSDLMessagePart for partName: " << name; + + throwException(SystemConfigurationException, errMessage.str().c_str()); + } + + return iter->second; + } + + const WSDLMessagePart& + WSDLOperation::getOutputMessagePart( const std::string &name ) const + { + logentry(); + + PART_MAP::const_iterator iter = outputPartMap.find( name ); + if( iter == outputPartMap.end() ) + { + stringstream errMessage; + errMessage + << "Unable to find output WSDLMessagePart for partName: " << name; + + throwException(SystemConfigurationException, errMessage.str().c_str()); + } + + return iter->second; + } + + void WSDLOperation::setInputMessagePart( const std::string &partName, + WSDLMessagePart part ) + { + logentry(); + + inputPartMap[partName] = part; + } + + void WSDLOperation::setOutputMessagePart( const std::string &partName, + WSDLMessagePart part ) + { + logentry(); + + outputPartMap[partName] = part; + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLOperation.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLOperation.h new file mode 100644 index 0000000000..48d848170a --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/WSDLOperation.h @@ -0,0 +1,196 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_wsdloperation_h +#define tuscany_sca_model_wsdloperation_h + +#include <map> +#include <list> +#include <string> + +#include "commonj/sdo/SDO.h" + +#include "tuscany/sca/export.h" +#include "tuscany/sca/model/WSDLMessagePart.h" + + +namespace tuscany +{ + namespace sca + { + namespace model + { + + /** + * Represents a single.,bound WSDL defined operation. + * This class includes information from the soapBinding + * in addition to the WSDL definition of the operation. + */ + class WSDLOperation + { + public: + /** + * Constructor. + */ + SCA_API WSDLOperation(); + + /** + * Destructor. + */ + SCA_API virtual ~WSDLOperation(); + + /** + * Return the name of the operation for use when serializing an + * outgoing message. + * @return The name of the element in the request message. + */ + SCA_API const std::string& getOperationName() const {return operationName;} + SCA_API void setOperationName(const std::string& opName) {operationName = opName;} + + /** + * The soap action string for this operation. + * @return The soap action. + */ + SCA_API const std::string& getSoapAction() const {return soapAction;} + SCA_API void setSoapAction(const std::string& soapAct) {soapAction = soapAct;} + + /** + * Return the endpoint address for the target web service. + * @return The endpoint address. + */ + SCA_API const std::string& getEndpoint() const {return endpoint;} + SCA_API void setEndpoint(const std::string& ep) {endpoint = ep;} + + enum soapVersion + { + SOAP11, + SOAP12 + }; + + SCA_API void setSoapVersion(soapVersion ver) {soapVer = ver;} + SCA_API soapVersion getSoapVersion() const {return soapVer;} + + SCA_API void setDocumentStyle(bool docStyle) {documentStyle = docStyle;} + SCA_API bool isDocumentStyle() const {return documentStyle;} + + SCA_API void setWrappedStyle(bool wrapStyle) {wrappedStyle = wrapStyle;} + SCA_API bool isWrappedStyle() const {return wrappedStyle;} + + SCA_API void setInputEncoded(bool enc) {inputEncoded = enc;} + SCA_API bool isInputEncoded() const {return inputEncoded;} + + SCA_API void setOutputEncoded(bool enc) {outputEncoded = enc;} + SCA_API bool isOutputEncoded() const {return outputEncoded;} + + /** + * Input Message URI and Name. To get the message part URI and name, you + * will have to get the WSDLMessagePart by calling getInputMessagePart() + */ + SCA_API void setInputMessageType(const std::string& inputMessageType); + SCA_API const std::string& getInputMessageUri() const {return inputMessageUri;} + SCA_API const std::string& getInputMessageName() const {return inputMessageName;} + + /** + * Output Message URI and Name. To get the message part URI and name, you + * will have to get the WSDLMessagePart by calling getOutputMessagePart() + */ + SCA_API void setOutputMessageType(const std::string& outputMessageType); + SCA_API const std::string& getOutputMessageUri() const {return outputMessageUri;} + SCA_API const std::string& getOutputMessageName() const {return outputMessageName;} + + // TODO We should add an enum for REQUEST_ONLY, RESPONSE_ONLY, REQUEST_RESPONSE + // and a setter/getter. The enum would be checked by getOutputXXX + + /** + * Parse a WSDL message represented by an SDO into the input/outputPartMap + * @param inputMsg a data object which contains the WSDL message + * ie. <wsdl:message name="getAccountReportResponse"> + * <wsdl:part element="tns:getAccountReportResponse" + * name="getAccountReportResponse" /> + * </wsdl:message> + */ + SCA_API void setInputMessage( commonj::sdo::DataObjectPtr inputMsg ); + SCA_API void setOutputMessage( commonj::sdo::DataObjectPtr outputMsg ); + + /** + * Manually set the input/outputPartMap, as opposed to passing in an SDO WSDL message. + * Populates the input/outputPartMap, setInput/OutputMessageType must still be called. + * @param partName the name of the message part + * @param part the message part + */ + SCA_API void setInputMessagePart( const std::string &partName, WSDLMessagePart part ); + SCA_API void setOutputMessagePart( const std::string &partName, WSDLMessagePart part ); + + /** + * Return a message part keyed off of the message part name + * @param name the message part name + * @return the message part in a WSDLMessagePart object + */ + SCA_API const WSDLMessagePart &getInputMessagePart( const std::string &name ) const; + SCA_API const WSDLMessagePart &getOutputMessagePart( const std::string &name ) const; + + /** + * Get all of the message part names + * @return a list of strings, each being a different message part name + */ + SCA_API const std::list<std::string> getInputMessagePartNames() const; + SCA_API const std::list<std::string> getOutputMessagePartNames() const; + + private: + /** + * The name of the operation for use when serializing an + * outgoing message. + */ + std::string operationName; + + /** + * The soap action string for this operation. + */ + std::string soapAction; + + /** + * The endpoint address of the target web service. + */ + std::string endpoint; + + bool documentStyle; + bool wrappedStyle; + bool inputEncoded; + bool outputEncoded; + soapVersion soapVer; + + std::string inputMessageUri; + std::string inputMessageName; + + std::string outputMessageUri; + std::string outputMessageName; + + typedef std::map<std::string, WSDLMessagePart> PART_MAP; + PART_MAP inputPartMap; + PART_MAP outputPartMap; + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_wsdloperation_h + diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Wire.cpp b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Wire.cpp new file mode 100644 index 0000000000..03f475af09 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Wire.cpp @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/model/Wire.h" + +using namespace tuscany::sca::util; + +namespace tuscany +{ + namespace sca + { + namespace model + { + + // Constructor + Wire::Wire(const std::string& source, const std::string& targ) + { + logentry(); + + Utils::tokeniseUri(source, sourceComponent, sourceReference); + target = targ; + } + + Wire::~Wire() + { + logentry(); + } + + } // End namespace model + + + } // End namespace sca +} // End namespace tuscany diff --git a/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Wire.h b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Wire.h new file mode 100644 index 0000000000..ab136e9109 --- /dev/null +++ b/sca-cpp/branches/cpp-contrib/contrib/runtime/core/src/tuscany/sca/model/Wire.h @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_model_wire_h +#define tuscany_sca_model_wire_h + +#include <string> + +namespace tuscany +{ + namespace sca + { + namespace model + { + /** + * Information about a wire in the model. + */ + class Wire + { + public: + + /** + * Constructor. + * @param source The source of the wire. Either the component and + * reference name (optional) or an entry point. + * @param target The target of the wire. Either a component and service + * service name (optional) or an external sevice. + */ + SCA_API Wire(const std::string& source, const std::string& target); + + /** + * Destructor. + */ + SCA_API virtual ~Wire(); + + /** + * Get the component name defined by the source of the wire. + * @return The component name which is the source of the wire. + */ + SCA_API const std::string& getSourceComponent() const { return sourceComponent; } + + /** + * Get the reference name defined by the source of the wire. + * @return The reference name which is the source of the wire. + */ + SCA_API const std::string& getSourceReference() const { return sourceReference; } + + /** + * Get the target uri defined by the target of the wire. + * @return The target uri which is the source of the wire. + */ + SCA_API const std::string& getTarget() { return target; } + + private: + /** + * The source component of the wire. + */ + std::string sourceComponent; + + /** + * The source reference of the wire. + */ + std::string sourceReference; + + /** + * The target uri of the wire. + */ + std::string target; + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_wire_h + |