diff options
Diffstat (limited to 'tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core')
78 files changed, 10707 insertions, 0 deletions
diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/Makefile.am new file mode 100644 index 0000000000..2b9491ec1c --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/Makefile.am @@ -0,0 +1,18 @@ +# 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. + +SUBDIRS = src diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/deploy.bat b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/deploy.bat new file mode 100644 index 0000000000..178ffb7b39 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/deploy.bat @@ -0,0 +1,72 @@ +@echo off + +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. + + +setlocal + +if . == .%1 ( +echo sca root not specified +goto usage +) +set rootdir=%1 +set deploydir=%rootdir%\deploy +set srcdir=%rootdir%\runtime\core\src + +if . == .%2 ( +echo input directory not specified +goto usage +) +set inpath=%2 +echo %inpath% + + +if not exist %deploydir% mkdir %deploydir% +if not exist %deploydir%\bin mkdir %deploydir%\bin +if not exist %deploydir%\lib mkdir %deploydir%\lib +if not exist %deploydir%\include mkdir %deploydir%\include +if not exist %deploydir%\include\tuscany mkdir %deploydir%\include\tuscany +if not exist %deploydir%\include\tuscany\sca mkdir %deploydir%\include\tuscany\sca +if not exist %deploydir%\include\tuscany\sca\core mkdir %deploydir%\include\tuscany\sca\core +if not exist %deploydir%\include\tuscany\sca\extension mkdir %deploydir%\include\tuscany\sca\extension +if not exist %deploydir%\include\tuscany\sca\model mkdir %deploydir%\include\tuscany\sca\model +if not exist %deploydir%\include\tuscany\sca\util mkdir %deploydir%\include\tuscany\sca\util +if not exist %deploydir%\xsd mkdir %deploydir%\xsd + +del %deploydir%\bin\tuscany_sca.* +del %deploydir%\lib\*.lib + +copy %srcdir%\tuscany\sca\*.h %deploydir%\include\tuscany\sca +copy %srcdir%\tuscany\sca\core\*.h %deploydir%\include\tuscany\sca\core +copy %srcdir%\tuscany\sca\extension\*.h %deploydir%\include\tuscany\sca\extension +copy %srcdir%\tuscany\sca\model\*.h %deploydir%\include\tuscany\sca\model +copy %srcdir%\tuscany\sca\util\*.h %deploydir%\include\tuscany\sca\util + +copy %rootdir%\xsd\*.* %deploydir%\xsd + +copy %inpath%\tuscany_sca.lib %deploydir%\lib +copy %inpath%\tuscany_sca.dll %deploydir%\bin + +if exist %inpath%\tuscany_sca.pdb copy %inpath%\tuscany_sca.pdb %deploydir%\bin + +goto end +:usage +echo Usage: deploy <sca-root> <build-output> +:end + +endlocal diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/Makefile.am new file mode 100644 index 0000000000..ce28bed32e --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/Makefile.am @@ -0,0 +1,74 @@ +# 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. + +lib_LTLIBRARIES = libtuscany_sca.la + +nobase_include_HEADERS = \ +tuscany/sca/*.h \ +tuscany/sca/core/*.h \ +tuscany/sca/model/*.h \ +tuscany/sca/util/*.h \ +tuscany/sca/extension/*.h + +## To list the source files execute the following: +## ls -1 tuscany/sca/util/*.cpp tuscany/sca/extension/*.cpp tuscany/sca/model/*.cpp tuscany/sca/core/*.cpp tuscany/sca/cpp/*.cpp tuscany/sca/ws/*.cpp | awk '{ print $1 " \\" }' +## and copy/paste the output below +libtuscany_sca_la_SOURCES = \ +tuscany/sca/core/Operation.cpp \ +tuscany/sca/core/SCARuntime.cpp \ +tuscany/sca/core/ServiceProxy.cpp \ +tuscany/sca/core/ServiceWrapper.cpp \ +tuscany/sca/core/TuscanyRuntime.cpp \ +tuscany/sca/extension/ImplementationExtension.cpp \ +tuscany/sca/extension/InterfaceExtension.cpp \ +tuscany/sca/extension/ReferenceBindingExtension.cpp \ +tuscany/sca/extension/ServiceBindingExtension.cpp \ +tuscany/sca/model/Binding.cpp \ +tuscany/sca/model/Component.cpp \ +tuscany/sca/model/ComponentType.cpp \ +tuscany/sca/model/Composite.cpp \ +tuscany/sca/model/CompositeReference.cpp \ +tuscany/sca/model/CompositeService.cpp \ +tuscany/sca/model/Contract.cpp \ +tuscany/sca/model/Interface.cpp \ +tuscany/sca/model/ModelLoader.cpp \ +tuscany/sca/model/ReferenceBinding.cpp \ +tuscany/sca/model/Reference.cpp \ +tuscany/sca/model/ReferenceType.cpp \ +tuscany/sca/model/ServiceBinding.cpp \ +tuscany/sca/model/Service.cpp \ +tuscany/sca/model/ServiceType.cpp \ +tuscany/sca/model/Wire.cpp \ +tuscany/sca/model/WSDLDefinition.cpp \ +tuscany/sca/model/WSDLInterface.cpp \ +tuscany/sca/model/WSDLOperation.cpp \ +tuscany/sca/util/DefaultLogWriter.cpp \ +tuscany/sca/util/Exceptions.cpp \ +tuscany/sca/util/File.cpp \ +tuscany/sca/util/FileLogWriter.cpp \ +tuscany/sca/util/Library.cpp \ +tuscany/sca/util/Logger.cpp \ +tuscany/sca/util/LogWriter.cpp \ +tuscany/sca/util/Utils.cpp + +libtuscany_sca_la_LIBADD = -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo + +INCLUDES = -I$(top_builddir)/runtime/core/src \ + -I${TUSCANY_SDOCPP}/include + +AM_CPPFLAGS = $(CPPFLAGS) -D_DEBUG +
\ No newline at end of file diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/Operation.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/Operation.cpp new file mode 100644 index 0000000000..aa030a1ce7 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/Operation.cpp @@ -0,0 +1,372 @@ +/* + * 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/core/Operation.h" +#include <stdarg.h> + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/SCARuntime.h" + + +namespace tuscany +{ + namespace sca + { + // =========== + // Constructor + // =========== + Operation::Operation(const char* operationName) + { + LOGENTRY(1,"Operation::constructor"); + + if (operationName != 0) + { + name = operationName; + } + + LOGEXIT(1,"Operation::constructor"); + } + + // ========== + // Destructor + // ========== + Operation::~Operation() + { + LOGENTRY(1,"Operation::destructor"); + clean(); + LOGEXIT(1,"Operation::destructor"); + } + + // ========== + // Copy Constructor + // ========== + Operation::Operation(const Operation& op) + { + LOGENTRY(1,"Operation::copy contructor"); + copy(op); + LOGEXIT(1,"Operation::copy contructor"); + } + + // ========== + // operator= + // ========== + Operation& Operation::operator=(const Operation& op) + { + LOGENTRY(1,"Operation::operator="); + if (&op != this) + { + copy(op); + } + LOGEXIT(1,"Operation::operator="); + return *this; + } + + // ========== + // Clean + // ========== + void Operation::clean() + { + LOGENTRY(1,"Operation::clean"); + for (unsigned int i = 0; i < getNParms(); i++) + { + const Parameter& parm = getParameter(i); + if (parm.getType() == DATAOBJECT) + { + delete (DataObjectPtr*)parm.getValue(); + } + } + + parameters.empty(); + + if (getReturnType() == DATAOBJECT) + { + delete (DataObjectPtr*)getReturnValue(); + } + + LOGEXIT(1,"Operation::clean"); + } + + // ========== + // Copy + // ========== + void Operation::copy(const Operation& op) + { + LOGENTRY(1,"Operation::copy"); + clean(); + for (unsigned int i = 0; i < op.getNParms(); i++) + { + const Parameter& parm = op.getParameter(i); + if (parm.getType() == DATAOBJECT) + { + addParameter((const DataObject*)parm.getValue()); + } + else + { + parameters.insert(parameters.end(), parm); + } + } + + if (getReturnType() == DATAOBJECT) + { + setReturnValue((const DataObjectPtr*)op.getReturnValue()); + } + else + { + returnValue = op.returnValue; + } + + LOGEXIT(1,"Operation::copy"); + } + + // ============================================== + // getParameter: return parameter at position pos + // ============================================== + void* Operation::getParameterValue(unsigned int pos) const + { + if (pos < parameters.size()) + { + return parameters[pos].getValue(); + } + + return 0; + } + + // ============================================== + // getParameter: return of parameter + // ============================================== + const Operation::Parameter& Operation::getParameter(unsigned int pos) const + { + if (pos < parameters.size()) + { + return parameters[pos]; + } + + throw "index out of range"; + } + + + // ============================================== + // getParameterType: return type of parameter + // ============================================== + Operation::ParameterType Operation::getParameterType(unsigned int pos) const + { + if (pos < parameters.size()) + { + return parameters[pos].getType(); + } + + return VOID_TYPE; + } + + // =========================================== + // addParameter: set parameter at position pos + // =========================================== + void Operation::addParameter(const void *parm) + { + LOGINFO(4, "Operation::addParameter(void*)"); + parameters.insert(parameters.end(), Parameter((void*)parm, VOID_TYPE)); + } + + void Operation::addParameter(const bool *parm) + { + LOGINFO(4, "Operation::addParameter(bool)"); + parameters.insert(parameters.end(), Parameter((void*)parm, BOOL)); + } + + void Operation::addParameter(const short *parm) + { + LOGINFO(4, "Operation::addParameter(short)"); + parameters.insert(parameters.end(), Parameter((void*)parm, SHORT)); + } + + void Operation::addParameter(const int *parm) + { + LOGINFO(4, "Operation::addParameter(int)"); + parameters.insert(parameters.end(), Parameter((void*)parm, INT)); + } + + void Operation::addParameter(const long *parm) + { + LOGINFO(4, "Operation::addParameter(long)"); + parameters.insert(parameters.end(), Parameter((void*)parm, LONG)); + } + + void Operation::addParameter(const unsigned short *parm) + { + LOGINFO(4, "Operation::addParameter(unsigned short)"); + parameters.insert(parameters.end(), Parameter((void*)parm, USHORT)); + } + + void Operation::addParameter(const unsigned int *parm) + { + LOGINFO(4, "Operation::addParameter(unsigned int)"); + parameters.insert(parameters.end(), Parameter((void*)parm, UINT)); + } + + void Operation::addParameter(const unsigned long *parm) + { + LOGINFO(4, "Operation::addParameter(unsigned long)"); + parameters.insert(parameters.end(), Parameter((void*)parm, ULONG)); + } + + void Operation::addParameter(const float *parm) + { + LOGINFO(4, "Operation::addParameter(float)"); + parameters.insert(parameters.end(), Parameter((void*)parm, FLOAT)); + } + + void Operation::addParameter(const double *parm) + { + LOGINFO(4, "Operation::addParameter(double)"); + parameters.insert(parameters.end(), Parameter((void*)parm, DOUBLE)); + } + + void Operation::addParameter(const long double *parm) + { + LOGINFO(4, "Operation::addParameter(long double)"); + parameters.insert(parameters.end(), Parameter((void*)parm, LONGDOUBLE)); + } + + void Operation::addParameter(const char* *parm) + { + LOGINFO(4, "Operation::addParameter(char*)"); + parameters.insert(parameters.end(), Parameter((void*)parm, CHARS)); + } + + void Operation::addParameter(const char *parm) + { + LOGINFO(4, "Operation::addParameter(char)"); + parameters.insert(parameters.end(), Parameter((void*)parm, CHAR)); + } + + void Operation::addParameter(const string *parm) + { + LOGINFO(4, "Operation::addParameter(string)"); + parameters.insert(parameters.end(), Parameter((void*)parm, STRING)); + } + + void Operation::addParameter(const DataObjectPtr *parm) + { + LOGINFO(4, "Operation::addParameter(DataObjectPtr)"); + parameters.insert(parameters.end(), Parameter((void*)new DataObjectPtr(*parm), DATAOBJECT)); + } + + Operation::Parameter::Parameter(void* val, Operation::ParameterType typ) + : value(val), type(typ) + { + } + + // =========================================== + // setReturnValue + // =========================================== + void Operation::setReturnValue(const void *parm) + { + LOGINFO(4, "Operation::setReturnValue(void*)"); + returnValue = Parameter((void*)parm, VOID_TYPE); + } + + void Operation::setReturnValue(const bool *parm) + { + LOGINFO(4, "Operation::setReturnValue(bool*)"); + returnValue = Parameter((void*)parm, BOOL); + } + + void Operation::setReturnValue(const short *parm) + { + LOGINFO(4, "Operation::setReturnValue(short*)"); + returnValue = Parameter((void*)parm, SHORT); + } + + void Operation::setReturnValue(const int *parm) + { + LOGINFO(4, "Operation::setReturnValue(int)"); + returnValue = Parameter((void*)parm, INT); + } + + void Operation::setReturnValue(const long *parm) + { + LOGINFO(4, "Operation::setReturnValue(long*)"); + returnValue = Parameter((void*)parm, LONG); + } + + void Operation::setReturnValue(const unsigned short *parm) + { + LOGINFO(4, "Operation::setReturnValue(unsigned short*)"); + returnValue = Parameter((void*)parm, USHORT); + } + + void Operation::setReturnValue(const unsigned int *parm) + { + LOGINFO(4, "Operation::setReturnValue(unsigned int)"); + returnValue = Parameter((void*)parm, UINT); + } + + void Operation::setReturnValue(const unsigned long *parm) + { + LOGINFO(4, "Operation::setReturnValue(unsigned long*)"); + returnValue = Parameter((void*)parm, ULONG); + } + + void Operation::setReturnValue(const float *parm) + { + LOGINFO(4, "Operation::setReturnValue(float*)"); + returnValue = Parameter((void*)parm, FLOAT); + } + + void Operation::setReturnValue(const double *parm) + { + LOGINFO(4, "Operation::setReturnValue(double*)"); + returnValue = Parameter((void*)parm, DOUBLE); + } + + void Operation::setReturnValue(const long double *parm) + { + LOGINFO(4, "Operation::setReturnValue(long double*)"); + returnValue = Parameter((void*)parm, LONGDOUBLE); + } + + void Operation::setReturnValue(const char *parm) + { + LOGINFO(4, "Operation::setReturnValue(char)"); + returnValue = Parameter((void*)parm, CHAR); + } + + void Operation::setReturnValue(const char* *parm) + { + LOGINFO(4, "Operation::setReturnValue(char*)"); + returnValue = Parameter((void*)parm, CHARS); + } + + void Operation::setReturnValue(const string *parm) + { + LOGINFO(4, "Operation::setReturnValue(string*)"); + returnValue = Parameter((void*)parm, STRING); + } + + void Operation::setReturnValue(const DataObjectPtr *parm) + { + LOGINFO(4, "Operation::setReturnValue(DataObjectPtr*)"); + returnValue = Parameter((void*)new DataObjectPtr(*parm), DATAOBJECT); + } + + + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/Operation.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/Operation.h new file mode 100644 index 0000000000..84338ae9e8 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/Operation.h @@ -0,0 +1,198 @@ +/* + * 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_core_operation_h +#define tuscany_sca_core_operation_h +#include "tuscany/sca/export.h" +#include "commonj/sdo/SDO.h" +using commonj::sdo::DataObjectPtr; +#include <string> +using std::string; +#include <vector> +using std::vector; + +namespace tuscany +{ + namespace sca + { + /** + * Holds the details of a single invocation of a business method. + * This class is used to pass the parameters and operation name from the + * client to a service. It will also hold the return value on the + * return from the business method. + */ + class Operation + { + public: + /** + * Create a new operation. + * @param operationName The method name of the business method to be invoked. + * @param numParameters The number of parameters to be passed. + */ + SCA_API Operation(const char* operationName = 0); + + /** + * Destructor. + */ + SCA_API virtual ~Operation(); + + /** + * Copy constructor. + */ + SCA_API Operation(const Operation& op); + + /** + * Assignment operator. + */ + SCA_API Operation& operator=(const Operation& op); + + /** + * Return the operation name. + * @return The name of the operation. + */ + SCA_API const string& getName() const {return name;} + + + enum ParameterType + { + UNSET = 0, + VOID_TYPE, + BOOL, + SHORT, + INT, + LONG, + USHORT, + UINT, + ULONG, + FLOAT, + DOUBLE, + LONGDOUBLE, + CHARS, + CHAR, + STRING, + DATAOBJECT + }; + + class Parameter + { + public: + SCA_API Parameter(void* value = NULL, ParameterType type = VOID_TYPE); + SCA_API void* getValue() const {return value;} + SCA_API ParameterType getType() const {return type;} + + private: + void* value; + ParameterType type; + }; + + /** + * Set a return value for the operation. + * @param retVal Pointer to the return value. + */ + SCA_API void setReturnValue(const void *retVal); + SCA_API void setReturnValue(const bool *retVal); + SCA_API void setReturnValue(const short *retVal); + SCA_API void setReturnValue(const int *retVal); + SCA_API void setReturnValue(const long *retVal); + SCA_API void setReturnValue(const unsigned short *retVal); + SCA_API void setReturnValue(const unsigned int *retVal); + SCA_API void setReturnValue(const unsigned long *retVal); + SCA_API void setReturnValue(const float *retVal); + SCA_API void setReturnValue(const double *retVal); + SCA_API void setReturnValue(const long double *retVal); + SCA_API void setReturnValue(const char *retVal); + SCA_API void setReturnValue(const char* *retVal); + SCA_API void setReturnValue(const string *retVal); + SCA_API void setReturnValue(const DataObjectPtr *retVal); + + /** + * Set a parameter on the operation. + * @param pos The position of the parameter in the parameter list. + * @param parm Pointer to the parameter to be passed. + */ + SCA_API void addParameter(const void *parm); + SCA_API void addParameter(const bool *parm); + SCA_API void addParameter(const short *parm); + SCA_API void addParameter(const int *parm); + SCA_API void addParameter(const long *parm); + SCA_API void addParameter(const unsigned short *parm); + SCA_API void addParameter(const unsigned int *parm); + SCA_API void addParameter(const unsigned long *parm); + SCA_API void addParameter(const float *parm); + SCA_API void addParameter(const double *parm); + SCA_API void addParameter(const long double *parm); + SCA_API void addParameter(const char *parm); + SCA_API void addParameter(const char* *parm); + SCA_API void addParameter(const string *parm); + SCA_API void addParameter(const DataObjectPtr *parm); + + SCA_API unsigned int getNParms() const {return parameters.size();} + + /** + * Get a parameter from the operation. + * @param pos The position of the parameter in the parameter list. + * @return Pointer to the paramter at the given postion. Should be + * cast to the appropriate type. + */ + SCA_API const Parameter& getParameter(unsigned int pos) const; + + /** + * Get a parameter type from the operation. + * @param pos The position of the parameter in the parameter list. + * @return Pointer to the paramter at the given postion. Should be + * cast to the appropriate type. + */ + SCA_API ParameterType getParameterType(unsigned int pos) const; + + /** + * Get a parameter from the operation. + * @param pos The position of the parameter in the parameter list. + * @return Pointer to the paramter at the given postion. Should be + * cast to the appropriate type. + */ + SCA_API void* getParameterValue(unsigned int pos) const; + + SCA_API ParameterType getReturnType() const {return returnValue.getType();} + SCA_API void* getReturnValue() const {return returnValue.getValue();} + + private: + /** + * Operation name (method name). + */ + string name; + + /** + * Array of parameters. + */ + typedef std::vector<Parameter> PARAMETER_VECTOR; + + PARAMETER_VECTOR parameters; + + Parameter returnValue; + + void clean(); + void copy(const Operation& op); + + }; + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_core_operation_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/SCARuntime.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/SCARuntime.cpp new file mode 100644 index 0000000000..49ec646bb1 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/SCARuntime.cpp @@ -0,0 +1,487 @@ +/* + * 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/core/SCARuntime.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/model/ModelLoader.h" +#include "tuscany/sca/util/File.h" +#include "tuscany/sca/util/Exceptions.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Component.h" + +#if defined(WIN32) || defined (_WINDOWS) +#include <windows.h> +#endif + +namespace tuscany +{ + namespace sca + { + /** + * Environment variable names + */ + static const char* TUSCANY_SCACPP = "TUSCANY_SCACPP"; + static const char* TUSCANY_SCACPP_SYSTEM_ROOT = "TUSCANY_SCACPP_SYSTEM_ROOT"; + static const char* TUSCANY_SCACPP_DEFAULT_COMPONENT = "TUSCANY_SCACPP_DEFAULT_COMPONENT"; + + static const char* TUSCANY_SCACPP_ROOT = "TUSCANY_SCACPP_ROOT"; + static const char* TUSCANY_SCACPP_COMPONENT = "TUSCANY_SCACPP_COMPONENT"; + static const char* TUSCANY_SCACPP_PATH = "TUSCANY_SCACPP_PATH"; + + // ========================================================== + // Initialize static class member to not pointing at anything + // ========================================================== + SCARuntime* SCARuntime::instance = 0; + string SCARuntime::systemRoot = ""; + string SCARuntime::systemPath = ""; + string SCARuntime::defaultComponentName = ""; + + + // ========================================================== + // Set the system configuration root + // ========================================================== + void SCARuntime::setSystemRoot(const string& root) + { + LOGENTRY(1, "SCARuntime::setSystemRoot"); + systemRoot = root; + LOGINFO_1(3, "SCARuntime::setSystemRoot - set to %s", root.c_str()); + LOGEXIT(1, "SCARuntime::setSystemRoot"); + } + + // ========================================================== + // Set the system configuration root + // ========================================================== + void SCARuntime::setSystemPath(const string& path) + { + LOGENTRY(1, "SCARuntime::setSystemPath"); + systemPath = path; + LOGINFO_1(3, "SCARuntime::setSystemPath - set to %s", path.c_str()); + LOGEXIT(1, "SCARuntime::setSystemPath"); + } + + // ========================================================== + // Set the default component name + // ========================================================== + void SCARuntime::setDefaultComponentName(const string& componentName) + { + LOGENTRY(1, "SCARuntime::setDefaultComponentName"); + defaultComponentName = componentName; + LOGINFO_1(3, "SCARuntime::setDefaultComponentName - set to %s", componentName.c_str()); + LOGEXIT(1, "SCARuntime::setDefaultComponentName"); + } + + // =================================================================== + // Constructor for the SCARuntime class. This will be a singleton that + // holds all the information about the current runtime. + // =================================================================== + SCARuntime::SCARuntime() : system(0), defaultComponent(0) + { + LOGENTRY(1, "SCARuntime::constructor"); + + // Locate the SCA install root + char* root = 0; + root = getenv(TUSCANY_SCACPP); + if (root == 0) + { + string msg = TUSCANY_SCACPP; + msg += " environment variable not set"; + throw SystemConfigurationException(msg.c_str()); + } + else + { + SCARoot = root; + } + + LOGEXIT(1, "SCARuntime::constructor"); + } + + // =================================================================== + // Destructor for the SCARuntime class. + // =================================================================== + SCARuntime::~SCARuntime() + { + LOGENTRY(1, "SCARuntime::destructor"); + + if (system) + { + delete system; + } + + LOGEXIT(1, "SCARuntime::destructor"); + } + + // ============================================================= + // Get the instance of the runtime, creates it if does not exist + // static method + // ============================================================= + SCARuntime* SCARuntime::getInstance() + { + LOGENTRY(1, "SCARuntime::getInstance"); + + if (instance == NULL) + { + instance = new SCARuntime(); + + // load extensions + instance->loadExtensions(); + + if (systemRoot == "") + { + // Get root from environment variable TUSCANY_SCACPP_ROOT + char* systemRootEnv = getenv(TUSCANY_SCACPP_ROOT); + if (systemRootEnv == 0) + { + // Get root from environment variable TUSCANY_SCACPP_SYSTEM_ROOT + systemRootEnv = getenv(TUSCANY_SCACPP_SYSTEM_ROOT); + } + if (systemRootEnv == 0) + { + string msg = TUSCANY_SCACPP_ROOT; + msg += " environment variable not set"; + throw SystemConfigurationException(msg.c_str()); + } + + systemRoot = systemRootEnv; + } + if (systemPath == "") + { + + // Get system path from environment variable TUSCANY_SCACPP_PATH + char* systemPathEnv = getenv(TUSCANY_SCACPP_PATH); + if (systemPathEnv == 0) + { + // Make the path optional for now +// string msg = TUSCANY_SCACPP_PATH; +// msg += " environment variable not set"; +// throw SystemConfigurationException(msg.c_str()); + } + else + { + systemPath = systemPathEnv; + } + } + } + + LOGEXIT(1, "SCARuntime::getInstance"); + + return instance; + + } + + + // ============================================================= + // Release the instance of the runtime. + // ============================================================= + void SCARuntime::releaseInstance() + { + LOGENTRY(1, "SCARuntime::releaseInstance"); + + if (instance) + { + delete instance; + instance = 0; + systemRoot = ""; + systemPath = ""; + defaultComponentName = ""; + } + + LOGEXIT(1, "SCARuntime::releaseInstance"); + } + + // ====================================== + // Load up all the details of the runtime + // ====================================== + void SCARuntime::load() + { + LOGENTRY(1, "SCARuntime::load"); + + LOGINFO_1(2,"configuration root: %s", systemRoot.c_str()); + LOGINFO_1(2,"configuration path: %s", systemPath.c_str()); + + // Load the system composite + ModelLoader loader(system); + loader.load(systemRoot, systemPath); + + LOGEXIT(1, "SCARuntime::load"); + } + + + // ====================================== + // Load up extensions to the runtime + // ====================================== + void SCARuntime::loadExtensions() + { + LOGENTRY(1, "SCARuntime::loadExtensions"); + + string extensionsRoot = SCARoot + "/extensions"; + +#if defined(WIN32) || defined (_WINDOWS) + string pattern = "*.dll"; +#else + string pattern = "*.so"; +#endif + + Files files(extensionsRoot, pattern, true); + for (unsigned int i=0; i < files.size(); i++) + { + try + { + Library lib = Library( files[i].getDirectory() + "/" + files[i].getFileName()); + extensionsList.push_back(lib); + TUSCANY_IMPLEMENTATION_EXTENSION_INITIALIZE extension = + (TUSCANY_IMPLEMENTATION_EXTENSION_INITIALIZE)lib.getSymbol("tuscany_sca_extension_initialize"); + if (extension) + { + extension(); + } + } + catch (TuscanyRuntimeException& ex) + { + LOGERROR_3(0, "SCARuntime::loadExtensions failed to load extension library: %s: %s: %s", + files[i].getFileName().c_str(), ex.getEClassName(), ex.getMessageText()); + } + } + + LOGEXIT(1, "SCARuntime::loadExtensions"); + } + + + // ====================================== + // register an interfaceExtension + // ====================================== + void SCARuntime::registerInterfaceExtension(InterfaceExtension* extension) + { + LOGENTRY(1, "SCARuntime::registerInterfaceExtension"); + if (extension) + { + interfaceExtensions[extension->getExtensionTypeQName()] = extension; + } + LOGEXIT(1, "SCARuntime::registerInterfaceExtension"); + } + + // ====================================== + // find an InterfaceExtension + // ====================================== + InterfaceExtension* SCARuntime::getInterfaceExtension(const string& extensionTypeQName) + { + return interfaceExtensions[extensionTypeQName]; + } + + // ====================================== + // register an implementationExtension + // ====================================== + void SCARuntime::registerImplementationExtension(ImplementationExtension* extension) + { + LOGENTRY(1, "SCARuntime::registerImplementationExtension"); + if (extension) + { + implementationExtensions[extension->getExtensionTypeQName()] = extension; + } + LOGEXIT(1, "SCARuntime::registerImplementationExtension"); + } + + // ====================================== + // find an implementationExtension + // ====================================== + ImplementationExtension* SCARuntime::getImplementationExtension(const string& extensionTypeQName) + { + return implementationExtensions[extensionTypeQName]; + } + + // ====================================== + // register a referenceBindingExtension + // ====================================== + void SCARuntime::registerReferenceBindingExtension(ReferenceBindingExtension* extension) + { + LOGENTRY(1, "SCARuntime::registerReferenceBindingExtension"); + if (extension) + { + referenceBindingExtensions[extension->getExtensionTypeQName()] = extension; + } + LOGEXIT(1, "SCARuntime::registerReferenceBindingExtension"); + } + + // ====================================== + // find a referenceBindingExtension + // ====================================== + ReferenceBindingExtension* SCARuntime::getReferenceBindingExtension(const string& extensionTypeQName) + { + return referenceBindingExtensions[extensionTypeQName]; + } + + // ====================================== + // register a serviceBindingExtension + // ====================================== + void SCARuntime::registerServiceBindingExtension(ServiceBindingExtension* extension) + { + LOGENTRY(1, "SCARuntime::registerServiceBindingExtension"); + if (extension) + { + serviceBindingExtensions[extension->getExtensionTypeQName()] = extension; + } + LOGEXIT(1, "SCARuntime::registerServiceBindingExtension"); + } + + // ====================================== + // find a serviceBindingExtension + // ====================================== + ServiceBindingExtension* SCARuntime::getServiceBindingExtension(const string& extensionTypeQName) + { + return serviceBindingExtensions[extensionTypeQName]; + } + + + // =================================== + // Return the top of the runtime model + // =================================== + Composite* SCARuntime::getSystem() + { + if (!system) + { + system = new Composite("tuscany/sca/system", ""); + load(); + } + return system; + } + + + // =================================================== + // setCurrentComponent: push component for this thread + // =================================================== + void SCARuntime::setCurrentComponent(Component* component) + { + +#if defined(WIN32) || defined (_WINDOWS) + DWORD currentThreadId = GetCurrentThreadId(); +#else + pthread_t currentThreadId = pthread_self(); +#endif + COMPONENTS_MAP::iterator iter = components.find(currentThreadId); + if (iter == components.end()) + { + components[currentThreadId] = COMPONENT_STACK(); + iter = components.find(currentThreadId); + } + + COMPONENT_STACK& compStack = iter->second; + compStack.push(component); + } + + + // ==================================================== + // unsetCurrentComponent: pop component for this thread + // ==================================================== + Component* SCARuntime::unsetCurrentComponent() + { +#if defined(WIN32) || defined (_WINDOWS) + DWORD currentThreadId = GetCurrentThreadId(); +#else + pthread_t currentThreadId = pthread_self(); +#endif + + COMPONENTS_MAP::iterator iter = components.find(currentThreadId); + if (iter != components.end()) + { + COMPONENT_STACK& compStack = iter->second; + if (compStack.size() > 0) + { + Component* component = compStack.top(); + compStack.pop(); + return component; + } + } + + return 0; + } + + // ============================================================= + // getCurrentComponent: return current component for this thread + // ============================================================= + Component* SCARuntime::getCurrentComponent() + { +#if defined(WIN32) || defined (_WINDOWS) + DWORD currentThreadId = GetCurrentThreadId(); +#else + pthread_t currentThreadId = pthread_self(); +#endif + + COMPONENTS_MAP::iterator iter = components.find(currentThreadId); + if (iter == components.end()) + { + components[currentThreadId] = COMPONENT_STACK(); + iter = components.find(currentThreadId); + } + + COMPONENT_STACK& compStack = iter->second; + if (compStack.size() > 0) + { + return compStack.top(); + } + else + { + return 0; + } + + } + + // =========================================== + // getCurrentCompositeComponent: return the current composite component + // =========================================== + Component* SCARuntime::getDefaultComponent() + { + + // ---------------------- + // Get the default Component + // ---------------------- + if (!defaultComponent) + { + // ------------------------------------------- + // Get the default component name from the environment + // ------------------------------------------- + if (defaultComponentName == "") + { + const char* defComp = getenv(TUSCANY_SCACPP_COMPONENT); + if (!defComp) + { + defComp = getenv(TUSCANY_SCACPP_DEFAULT_COMPONENT); + } + if (!defComp) + { + string message = TUSCANY_SCACPP_COMPONENT; + message += " environment variable not set"; + throw SystemConfigurationException(message.c_str()); + } + defaultComponentName = defComp; + } + + defaultComponent = getSystem()->findComponent(defaultComponentName); + if (!defaultComponent) + { + string message = "Component \'" + defaultComponentName + "\' not found"; + throw SystemConfigurationException(message.c_str()); + } + } + return defaultComponent; + } + + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/SCARuntime.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/SCARuntime.h new file mode 100644 index 0000000000..ef78296480 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/SCARuntime.h @@ -0,0 +1,262 @@ +/* + * 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_core_scaruntime_h +#define tuscany_sca_core_scaruntime_h + +#include "tuscany/sca/export.h" + +#include "tuscany/sca/extension/InterfaceExtension.h" +#include "tuscany/sca/extension/ImplementationExtension.h" +#include "tuscany/sca/extension/ReferenceBindingExtension.h" +#include "tuscany/sca/extension/ServiceBindingExtension.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/util/Library.h" + +#if defined(WIN32) || defined (_WINDOWS) +#include <windows.h> +#else +#include <pthread.h> +#endif + +#include <stack> +#include <string> +#include <map> +#include <list> +using namespace std; + +using namespace tuscany::sca::model; + + +namespace tuscany +{ + namespace sca + { + + /** + * A singleton which represents the executing SCA runtime. + */ + class SCARuntime { + public: + + /** + * Get the single instance. + * @return The single instance of the runtime. + */ + SCA_API static SCARuntime* getInstance(); + + /** + * Release the single instance. + */ + SCA_API static void releaseInstance(); + + /** + * Load the SCA configuration from the scdl files (sca.composite, + * *.fragment, etc). + * This will create the runtime model from which the SCA runtime + * will operate. + */ + SCA_API void load(); + + /** + * Set the system root + * @param root The path to the system configuration. + */ + static void setSystemRoot(const string& root); + + /** + * Set the search path for composites. + * @param path The search path for composites. + */ + static void setSystemPath(const string& path); + + /** + * Set the default Component for the system + * @param componentName The name of the default component. + */ + static void setDefaultComponentName(const string& componentName); + + /** + * Set the current component for the current thread. + * @param component The current component. + */ + SCA_API void setCurrentComponent(Component* component); + + /** + * Remove the current component from this thread, and return + * to the previous component (if there was one). + * @return The previous component. + */ + SCA_API Component* unsetCurrentComponent(); + + /** + * Get a pointer to the configured SCA system which this + * SCA runtime represents. + * The rest of the SCA configuration can be navigated from + * the System. + * @return The configured SCA system. + */ + SCA_API Composite* getSystem(); + + /** + * The directory in which the Tuscany runtime has been installed. + */ + SCA_API const string& getInstallRoot() {return SCARoot;} + + /** + * Return the current component for this thread. + * @return The current component for this thread. + */ + SCA_API Component* getCurrentComponent(); + + /** + * Get the default component set for this runtime. + * @return The default composite. + */ + SCA_API Component* getDefaultComponent(); + + /** + * Register an implementation extension + */ + SCA_API void registerImplementationExtension(ImplementationExtension* extension); + + /** + * Returns the implementation extension associated with + * the specified qname + */ + SCA_API ImplementationExtension* getImplementationExtension(const string& typeQname); + + /** + * Register a reference binding extension + */ + SCA_API void registerReferenceBindingExtension(ReferenceBindingExtension* extension); + + /** + * Returns the reference binding extension associated with + * the specified qname + */ + SCA_API ReferenceBindingExtension* getReferenceBindingExtension(const string& typeQname); + + /** + * Register a service binding extension + */ + SCA_API void registerServiceBindingExtension(ServiceBindingExtension* extension); + + /** + * Returns the service binding extension associated with + * the specified qname + */ + SCA_API ServiceBindingExtension* getServiceBindingExtension(const string& typeQname); + + /** + * Register an interface extension + */ + SCA_API void registerInterfaceExtension(InterfaceExtension* extension); + + /** + * Returns the interface extension associated with + * the specified qname + */ + SCA_API InterfaceExtension* getInterfaceExtension(const string& typeQname); + + private: + /** + * Default constructor is private to prevent more than one instance. + */ + SCARuntime(); + + virtual ~SCARuntime(); + + /** + * The single instance of this class. + */ + static SCARuntime* instance; + + /** + * Pointer to the top of the runtime model. + */ + Composite* system; + + /** + * The installed path of the Tuscany runtime. + */ + string SCARoot; + + /** + * The path to the system configuration + */ + static string systemRoot; + + /** + * The search path for composites. + */ + static string systemPath; + + /** + * The default CompositeComponent. + */ + static string defaultComponentName; + + /** + * The default component set for this runtime. + */ + Component* defaultComponent; + + + typedef stack<Component*> COMPONENT_STACK; +#if defined(WIN32) || defined (_WINDOWS) + typedef map<DWORD, COMPONENT_STACK> COMPONENTS_MAP; +#else + typedef map<pthread_t, COMPONENT_STACK> COMPONENTS_MAP; +#endif + + /** + * A map of threads to components. + */ + COMPONENTS_MAP components; + + typedef map<string, ImplementationExtension*> IMPLEMENTATION_EXTENSIONS_MAP; + IMPLEMENTATION_EXTENSIONS_MAP implementationExtensions; + + typedef map<string, ReferenceBindingExtension*> REFERENCE_BINDING_EXTENSIONS_MAP; + REFERENCE_BINDING_EXTENSIONS_MAP referenceBindingExtensions; + + typedef map<string, ServiceBindingExtension*> SERVICE_BINDING_EXTENSIONS_MAP; + SERVICE_BINDING_EXTENSIONS_MAP serviceBindingExtensions; + + typedef map<string, InterfaceExtension*> INTERFACE_EXTENSIONS_MAP; + INTERFACE_EXTENSIONS_MAP interfaceExtensions; + + // Runtime Extensions + void loadExtensions(); + + typedef list<Library> EXTENSIONS_LIST; + EXTENSIONS_LIST extensionsList; + + }; + + } // End namespace sca +} // End namespace tuscany + +typedef void (* TUSCANY_IMPLEMENTATION_EXTENSION_INITIALIZE) (); + +#endif // tuscany_sca_core_scaruntime_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/ServiceProxy.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/ServiceProxy.cpp new file mode 100644 index 0000000000..f835b53267 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/ServiceProxy.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/core/ServiceProxy.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Exceptions.h" + +namespace tuscany +{ + namespace sca + { + // ============================ + // Constructor: Create a proxy + // ============================ + ServiceProxy::ServiceProxy(Reference* reference) + : reference(reference) + { + LOGENTRY(1,"ServiceProxy::constructor"); + LOGEXIT(1,"ServiceProxy::constructor"); + + } + + // ========== + // Destructor + // ========== + ServiceProxy::~ServiceProxy() + { + LOGENTRY(1,"ServiceProxy::destructor"); + LOGEXIT(1,"ServiceProxy::destructor"); + } + + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/ServiceProxy.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/ServiceProxy.h new file mode 100644 index 0000000000..69af373062 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/ServiceProxy.h @@ -0,0 +1,81 @@ +/* + * 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_core_serviceproxy_h +#define tuscany_sca_core_serviceproxy_h + +#include "tuscany/sca/export.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/core/ServiceWrapper.h" + +#include <vector> +using std::vector; + +using namespace tuscany::sca::model; + + +namespace tuscany +{ + namespace sca + { + + /** + * Holds a proxy for a given component and reference. + * The proxy which is held inside a ServiceProxy will be specific to the component + * and reference and will have been code generated and be contained in a dll + * created by a developer of an SCA application. + */ + class SCA_API ServiceProxy + { + public: + /** + * Create a new service proxy for a reference. The proxy will contain a pointer to + * the target ServiceWrapper. + * @param reference The reference on the source component. + * @param target The wrapper of the service which is wired to this reference. + */ + ServiceProxy(Reference* reference); + + /** + * Destructor. + */ + virtual ~ServiceProxy(); + + /** + * Returns the reference represented by this proxy. + * @return The Reference represented by this proxy. + */ + Reference* getReference() const { return reference; }; + + private: + + /** + * The reference represented by this proxy. + */ + Reference* reference; + + }; + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_core_serviceproxy_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/ServiceWrapper.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/ServiceWrapper.cpp new file mode 100644 index 0000000000..51ee4f02b7 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/ServiceWrapper.cpp @@ -0,0 +1,52 @@ +/* + * 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/core/ServiceWrapper.h" +#include "tuscany/sca/util/Logging.h" + +namespace tuscany +{ + namespace sca + { + + // =========== + // Constructor + // =========== + ServiceWrapper::ServiceWrapper(Service* service) + : service(service) + { + LOGENTRY(1,"ServiceWrapper::constructor"); + + LOGEXIT(1,"ServiceWrapper::constructor"); + + } + + // ========== + // Destructor + // ========== + ServiceWrapper::~ServiceWrapper() + { + LOGENTRY(1,"ServiceWrapper::destructor"); + LOGEXIT(1,"ServiceWrapper::destructor"); + } + + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/ServiceWrapper.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/ServiceWrapper.h new file mode 100644 index 0000000000..816e1d06f4 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/ServiceWrapper.h @@ -0,0 +1,79 @@ +/* + * 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_core_servicewrapper_h +#define tuscany_sca_core_servicewrapper_h + +#include "tuscany/sca/export.h" +#include "tuscany/sca/core/Operation.h" +#include "tuscany/sca/model/Service.h" + +using namespace tuscany::sca::model; + + +namespace tuscany +{ + namespace sca + { + + /** + * An abstract class that wraps a component implementation or an external + * service. + */ + class SCA_API ServiceWrapper + { + public: + /** + * Constructor. + * @param target The service wrapper wraps the target of a wire. + */ + ServiceWrapper(Service* service); + + /** + * Destructor. + */ + virtual ~ServiceWrapper(); + + /** + * Get the service represented by this wrapper. + * @return The service represented by this wrapper. + */ + Service* getService() const { return service; } + + /** + * All business method calls on the target service are performed through + * this invoke method. + * @param operation The details of the method, paramaters and return value for the + * business method to be called on the target service. + */ + virtual void invoke(Operation& operation) = 0; + + private: + /** + * The target represented by this wrapper. + */ + Service* service; + + }; + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_core_servicewrapper_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/TuscanyRuntime.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/TuscanyRuntime.cpp new file mode 100644 index 0000000000..5e6cd4a197 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/TuscanyRuntime.cpp @@ -0,0 +1,111 @@ +/* + * 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/core/TuscanyRuntime.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/util/Exceptions.h" +#include "tuscany/sca/core/SCARuntime.h" + +namespace tuscany +{ + namespace sca + { + + // ========================================================== + // Set the system configuration root path + // ========================================================== + void TuscanyRuntime::setSystemRoot(const string& root) + { + LOGENTRY(1, "TuscanyRuntime::setSystemRoot"); + systemRoot = root; + LOGINFO_1(3, "TuscanyRuntime::setSystemRoot - set to %s", root.c_str()); + LOGEXIT(1, "TuscanyRuntime::setSystemRoot"); + } + + // ========================================================== + // Set the search path for composites + // ========================================================== + void TuscanyRuntime::setSystemPath(const string& path) + { + LOGENTRY(1, "TuscanyRuntime::setSystemPath"); + systemPath = path; + LOGINFO_1(3, "TuscanyRuntime::setSystemPath - set to %s", path.c_str()); + LOGEXIT(1, "TuscanyRuntime::setSystemPath"); + } + + // ========================================================== + // Set the default component name + // ========================================================== + void TuscanyRuntime::setDefaultComponentName(const string& componentName) + { + LOGENTRY(1, "TuscanyRuntime::setDefaultComponentName"); + defaultComponentName = componentName; + LOGINFO_1(3, "TuscanyRuntime::setDefaultComponentName - set to %s", componentName.c_str()); + LOGEXIT(1, "TuscanyRuntime::setDefaultComponentName"); + } + + // =================================================================== + // Constructor for the TuscanyRuntime class. + // =================================================================== + TuscanyRuntime::TuscanyRuntime(const string& componentName, const string& root, const string& path) + { + LOGENTRY(1, "TuscanyRuntime::constructor"); + setSystemRoot(root); + setSystemPath(path); + setDefaultComponentName(componentName); + LOGEXIT(1, "TuscanyRuntime::constructor"); + } + + // =================================================================== + // Destructor for the TuscanyRuntime class. + // =================================================================== + TuscanyRuntime::~TuscanyRuntime() + { + LOGENTRY(1, "TuscanyRuntime::destructor");; + LOGEXIT(1, "TuscanyRuntime::destructor"); + } + + // =================================================================== + // Start the runtime. + // =================================================================== + void TuscanyRuntime::start() + { + LOGENTRY(1, "TuscanyRuntime::start"); + SCARuntime::setSystemRoot(systemRoot); + SCARuntime::setSystemPath(systemPath); + SCARuntime::setDefaultComponentName(defaultComponentName); + SCARuntime::getInstance(); + LOGEXIT(1, "TuscanyRuntime::start"); + } + + // =================================================================== + // Stop the runtime. + // =================================================================== + void TuscanyRuntime::stop() + { + LOGENTRY(1, "TuscanyRuntime::stop"); + SCARuntime::releaseInstance(); + LOGEXIT(1, "TuscanyRuntime::stop"); + } + + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/TuscanyRuntime.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/TuscanyRuntime.h new file mode 100644 index 0000000000..f1ac59f357 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/core/TuscanyRuntime.h @@ -0,0 +1,95 @@ +/* + * 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_core_tuscanyruntime_h +#define tuscany_sca_core_tuscanyruntime_h + +#include "tuscany/sca/export.h" +#include <string> +using std::string; + +namespace tuscany +{ + namespace sca + { + + /** + * A singleton which represents the executing SCA runtime. + */ + class SCA_API TuscanyRuntime + { + public: + /** + * Default constructor + */ + TuscanyRuntime(const string& defaultComponentName = "", + const string& root = "", const string& path = ""); + + /** + * Destructor + */ + virtual ~TuscanyRuntime(); + + + /** + * Set the system root configuration path + * @param root The path to the system configuration. + */ + void setSystemRoot(const string& root); + + /** + * Set the system composite search path + * @param root The search path for composites. + */ + void setSystemPath(const string& path); + + /** + * Set the default component for the system + * @param componentName The name of the default component. + */ + void setDefaultComponentName(const string& componentName); + + /** + * start the runtime + */ + void start(); + + /** + * stop the runtime + */ + void stop(); + + + private: + string systemRoot; + string systemPath; + string defaultComponentName; + }; + + + } // End namespace sca +} // End namespace tuscany + + + + +#endif // tuscany_sca_core_tuscanyruntime_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/export.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/export.h new file mode 100644 index 0000000000..79b02fe4cf --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/export.h @@ -0,0 +1,41 @@ +/* + * 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_export_h +#define tuscany_sca_export_h + +#if defined(WIN32) || defined (_WINDOWS) +#pragma warning(disable: 4786) + +#ifdef SCA_EXPORTS +#define SCA_API __declspec(dllexport) +#else +#define SCA_API __declspec(dllimport) +#endif + +#else +#include <sys/time.h> +#include <inttypes.h> +#include <stdlib.h> +#define SCA_API +#endif + +#endif // tuscany_sca_export_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ImplementationExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ImplementationExtension.cpp new file mode 100644 index 0000000000..21eab40c72 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ImplementationExtension.cpp @@ -0,0 +1,48 @@ +/* + * 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/extension/ImplementationExtension.h" +#include "tuscany/sca/util/Logging.h" +namespace tuscany +{ + namespace sca + { + // =================================================================== + // Constructor for the ImplementationExtension class. + // =================================================================== + ImplementationExtension::ImplementationExtension() + { + LOGENTRY(1, "ImplementationExtension::constructor"); + LOGEXIT(1, "ImplementationExtension::constructor"); + } + + // =================================================================== + // Destructor for the ImplementationExtension class. + // =================================================================== + ImplementationExtension::~ImplementationExtension() + { + LOGENTRY(1, "ImplementationExtension::destructor");; + LOGEXIT(1, "ImplementationExtension::destructor"); + } + + + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ImplementationExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ImplementationExtension.h new file mode 100644 index 0000000000..4744a5b14c --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ImplementationExtension.h @@ -0,0 +1,80 @@ +/* + * 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_extension_implementationextension_h +#define tuscany_sca_extension_implementationextension_h + +#include "tuscany/sca/export.h" +#include <string> +using std::string; + +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/model/Composite.h" + +#include "commonj/sdo/SDO.h" + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + class SCA_API ImplementationExtension + { + public: + /** + * Default constructor + */ + ImplementationExtension(); + + /** + * Destructor + */ + virtual ~ImplementationExtension(); + + /** + * return the name of the extension (e.g. "cpp" "php") + */ + virtual const string& getExtensionName() = 0; + + /** + * return the QName of schema elemant for this implementation extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#implementation.cpp") + */ + virtual const string& getExtensionTypeQName() = 0; + + /** + * Get an implementation from a DataObject representing + * an SCDL implementation element + */ + virtual ComponentType* getImplementation(Composite* composite, commonj::sdo::DataObjectPtr scdlImplementation) = 0; + + }; + + + } // End namespace sca +} // End namespace tuscany + + +#endif // tuscany_sca_extension_implementationextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/InterfaceExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/InterfaceExtension.cpp new file mode 100644 index 0000000000..f0cb0b1b2d --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/InterfaceExtension.cpp @@ -0,0 +1,48 @@ +/* + * 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/extension/InterfaceExtension.h" +#include "tuscany/sca/util/Logging.h" +namespace tuscany +{ + namespace sca + { + // =================================================================== + // Constructor for the InterfaceExtension class. + // =================================================================== + InterfaceExtension::InterfaceExtension() + { + LOGENTRY(1, "InterfaceExtension::constructor"); + LOGEXIT(1, "InterfaceExtension::constructor"); + } + + // =================================================================== + // Destructor for the InterfaceExtension class. + // =================================================================== + InterfaceExtension::~InterfaceExtension() + { + LOGENTRY(1, "InterfaceExtension::destructor");; + LOGEXIT(1, "InterfaceExtension::destructor"); + } + + + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/InterfaceExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/InterfaceExtension.h new file mode 100644 index 0000000000..545eb92caa --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/InterfaceExtension.h @@ -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$ */ + +#ifndef tuscany_sca_extension_interfaceextension_h +#define tuscany_sca_extension_interfaceextension_h + +#include "tuscany/sca/export.h" +#include <string> +using std::string; + +#include "tuscany/sca/model/Interface.h" +#include "tuscany/sca/model/Composite.h" +#include "commonj/sdo/SDO.h" + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + class SCA_API InterfaceExtension + { + public: + /** + * Default constructor + */ + InterfaceExtension(); + + /** + * Destructor + */ + virtual ~InterfaceExtension(); + + /** + * return the name of the extension (e.g. "cpp" "php") + */ + virtual const string& getExtensionName() = 0; + + /** + * return the QName of schema elemant for this interface extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#interface.cpp") + */ + virtual const string& getExtensionTypeQName() = 0; + + /** + * Get an interface from a DataObject representing an + * SCDL interface + */ + virtual Interface* getInterface(Composite *composite, commonj::sdo::DataObjectPtr scdlInterface) = 0; + + }; + + + } // End namespace sca +} // End namespace tuscany + + +#endif // tuscany_sca_extension_interfaceextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ReferenceBindingExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ReferenceBindingExtension.cpp new file mode 100644 index 0000000000..9797cb33a9 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ReferenceBindingExtension.cpp @@ -0,0 +1,47 @@ +/* + * 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/extension/ReferenceBindingExtension.h" +#include "tuscany/sca/util/Logging.h" +namespace tuscany +{ + namespace sca + { + // =================================================================== + // Constructor for the ReferenceBindingExtension class. + // =================================================================== + ReferenceBindingExtension::ReferenceBindingExtension() + { + LOGENTRY(1, "ReferenceBindingExtension::constructor"); + LOGEXIT(1, "ReferenceBindingExtension::constructor"); + } + + // =================================================================== + // Destructor for the ReferenceBindingExtension class. + // =================================================================== + ReferenceBindingExtension::~ReferenceBindingExtension() + { + LOGENTRY(1, "ReferenceBindingExtension::destructor");; + LOGEXIT(1, "ReferenceBindingExtension::destructor"); + } + + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ReferenceBindingExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ReferenceBindingExtension.h new file mode 100644 index 0000000000..1af89e6c5a --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ReferenceBindingExtension.h @@ -0,0 +1,81 @@ +/* + * 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_extension_referencebindingextension_h +#define tuscany_sca_extension_referencebindingextension_h + +#include "tuscany/sca/export.h" + +#include <string> +using std::string; + +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/ReferenceBinding.h" + +#include "commonj/sdo/SDO.h" + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + class SCA_API ReferenceBindingExtension + { + public: + /** + * Default constructor + */ + ReferenceBindingExtension(); + + /** + * Destructor + */ + virtual ~ReferenceBindingExtension(); + + /** + * return the name of the extension (e.g. "cpp" "php") + */ + virtual const string& getExtensionName() = 0; + + /** + * return the QName of schema elemant for this binding extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#binding.ws") + */ + virtual const string& getExtensionTypeQName() = 0; + + /** + * Get a reference binding from a DataObject representing + * an SCDL binding element + */ + virtual ReferenceBinding* getReferenceBinding(Composite* composite, Reference* reference, commonj::sdo::DataObjectPtr scdlBinding) = 0; + + }; + + + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_extension_referencebindingextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ServiceBindingExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ServiceBindingExtension.cpp new file mode 100644 index 0000000000..9ffb4d10d1 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ServiceBindingExtension.cpp @@ -0,0 +1,47 @@ +/* + * 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/extension/ServiceBindingExtension.h" +#include "tuscany/sca/util/Logging.h" +namespace tuscany +{ + namespace sca + { + // =================================================================== + // Constructor for the ServiceBindingExtension class. + // =================================================================== + ServiceBindingExtension::ServiceBindingExtension() + { + LOGENTRY(1, "ServiceBindingExtension::constructor"); + LOGEXIT(1, "ServiceBindingExtension::constructor"); + } + + // =================================================================== + // Destructor for the ServiceBindingExtension class. + // =================================================================== + ServiceBindingExtension::~ServiceBindingExtension() + { + LOGENTRY(1, "ServiceBindingExtension::destructor");; + LOGEXIT(1, "ServiceBindingExtension::destructor"); + } + + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ServiceBindingExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ServiceBindingExtension.h new file mode 100644 index 0000000000..9d65a7441a --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/extension/ServiceBindingExtension.h @@ -0,0 +1,80 @@ +/* + * 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_extension_servicebindingextension_h +#define tuscany_sca_extension_servicebindingextension_h + +#include "tuscany/sca/export.h" +#include <string> +using std::string; + +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/ServiceBinding.h" + +#include "commonj/sdo/SDO.h" + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + class SCA_API ServiceBindingExtension + { + public: + /** + * Default constructor + */ + ServiceBindingExtension(); + + /** + * Destructor + */ + virtual ~ServiceBindingExtension(); + + /** + * return the name of the extension (e.g. "cpp" "php") + */ + virtual const string& getExtensionName() = 0; + + /** + * return the QName of schema elemant for this binding extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#binding.ws") + */ + virtual const string& getExtensionTypeQName() = 0; + + /** + * Get a reference binding from a DataObject representing + * an SCDL binding element + */ + virtual ServiceBinding* getServiceBinding(Composite* composite, Service* service, commonj::sdo::DataObjectPtr scdlBinding) = 0; + + }; + + + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_extension_servicebindingextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Binding.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Binding.cpp new file mode 100644 index 0000000000..af7aa2ff6f --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Binding.cpp @@ -0,0 +1,46 @@ +/* + * 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" + + +namespace tuscany +{ + namespace sca + { + + namespace model + { + + // Constructor + Binding::Binding(const string& uri) : uri(uri) + { + } + + // Destructor + Binding::~Binding() + { + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Binding.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Binding.h new file mode 100644 index 0000000000..b68529020d --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/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> +using std::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 string& uri); + + /** + * Destructor. + */ + SCA_API virtual ~Binding(); + + /** + * Returns the binding type + * @return The binding type. + */ + SCA_API virtual string getType() = 0; + + /** + * Returns the binding URI. + * @return The binding URI. + */ + SCA_API const string& getURI() const { return uri; }; + + private: + + /** + * The binding URI. + */ + string uri; + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_binding_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Component.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Component.cpp new file mode 100644 index 0000000000..905d8c3555 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Component.cpp @@ -0,0 +1,146 @@ +/* + * 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/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 commonj::sdo; +#include <iostream> +using namespace std; +namespace tuscany +{ + namespace sca + { + namespace model + { + // Constructor + Component::Component(Composite* composite, const std::string& componentName, ComponentType *componentType) + : name(componentName), composite(composite), type(componentType) + { + LOGENTRY(1, "Component::constructor"); + LOGINFO_1(3, "Component::constructor: Component name: %s", name.c_str()); + + // Initialize the component from its component type + componentType->initializeComponent(this); + + LOGEXIT(1, "Component::constructor"); + } + + Component::~Component() + { + } + + void Component::addService(Service* service) + { + services[service->getType()->getName()] = service; + } + + Service* Component::findService(const string& serviceName) + { + // 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) + { + references[reference->getType()->getName()] = reference; + } + + Reference* Component::findReference(const std::string& referenceName) + { + return references[referenceName]; + } + + DataObjectPtr Component::getProperties() + { + if (!properties) + { + properties = type->getPropertyDataFactory()->create("org/osoa/sca", "Properties"); + } + return properties; + } + + void Component::setProperty(const string& name, DataObjectPtr value) + { + //cout << "setting property: " << name.c_str() << " to: " << value <<endl; + DataObjectPtr props = getProperties(); + + // Get the property's type + try + { + const Property& propProperty = props->getProperty(name); + 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); + } + } + catch (SDOPropertyNotFoundException&) + { + // Configuration error: property is not defined + string message = "Undefined property: " + name; + throw SystemConfigurationException(message.c_str()); + } + + //cout << "properties set: " << props << endl; + + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Component.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Component.h new file mode 100644 index 0000000000..dc34b03a57 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Component.h @@ -0,0 +1,184 @@ +/* + * 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 "tuscany/sca/export.h" +#include <string> +using std::string; + +#include <map> + +#include "commonj/sdo/SDO.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 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 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 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 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 DataObjectPtr getProperties(); + + private: + + /** + * Name of the component. + */ + 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ComponentType.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ComponentType.cpp new file mode 100644 index 0000000000..a69364d7c4 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ComponentType.cpp @@ -0,0 +1,261 @@ +/* + * 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/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" + +#include <iostream> + +using namespace commonj::sdo; +using namespace std; + +namespace tuscany +{ + namespace sca + { + namespace model + { + + // Constructor + ComponentType::ComponentType(Composite* composite, const string& name) + : composite(composite), name(name) + { + LOGENTRY(1, "ComponentType::constructor"); + LOGEXIT(1, "ComponentType::constructor"); + } + + // Destructor + ComponentType::~ComponentType() + { + } + + void ComponentType::addServiceType(ServiceType* serviceType) + { + serviceTypes[serviceType->getName()] = serviceType; + } + + ServiceType* ComponentType::findServiceType(const string& serviceName) + { + // 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) + { + referenceTypes[referenceType->getName()] = referenceType; + } + + ReferenceType* ComponentType::findReferenceType(const string& referenceName) + { + return referenceTypes[referenceName]; + } + + void ComponentType::addPropertyType(const string& name, + const string& type, + bool many, + DataObjectPtr* defaultValue) + { + // 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 = Type::SDOTypeNamespaceURI; + if (typeName == "string") + { + typeName = "String"; + } + else if (typeName == "anyType") + { + typeName = "DataObject"; + } + else if (typeName == "int") + { + typeName = "Integer"; + } + 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&) + { + // cout << "setting default failed" <<endl; + } + } + } + + DataFactoryPtr ComponentType::getPropertyDataFactory() + { + 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) + { + 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ComponentType.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ComponentType.h new file mode 100644 index 0000000000..18e78ffedf --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ComponentType.h @@ -0,0 +1,181 @@ +/* + * 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> +using std::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 string& name); + + /** + * Destructor. + */ + SCA_API virtual ~ComponentType(); + + /** + * Returns the name of the component type + */ + SCA_API const 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 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 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 string& name, + const string& type, + bool many, + commonj::sdo::DataObjectPtr* defaultValue); + + /** + * 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 + */ + 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Composite.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Composite.cpp new file mode 100644 index 0000000000..7b7fbcbdda --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Composite.cpp @@ -0,0 +1,198 @@ +/* + * 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/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" + +namespace tuscany +{ + namespace sca + { + + namespace model + { + + // Constructor + Composite::Composite(const string& name, const string& root) + : ComponentType(0, name), root(root) + { + LOGENTRY(1, "Composite::constructor"); + LOGEXIT(1, "Composite::constructor"); + } + + // Destructor + Composite::~Composite() + { + } + + void Composite::addComponent(Component* component) + { + LOGENTRY(1, "Composite::addComponent"); + components[component->getName()] = component; + LOGEXIT(1, "Composite::addComponent"); + } + + Component* Composite::findComponent(const std::string& name) + { + LOGENTRY(1, "Composite::findComponent"); + Component* component = components[name]; + LOGEXIT(1, "Composite::findComponent"); + return component; + } + + Service* Composite::findComponentService(const std::string& name) + { + LOGENTRY(1, "Composite::findComponentService"); + + 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); + } + LOGEXIT(1, "Composite::findComponentService"); + return service; + } + + void Composite::addWire(const std::string& source, const std::string& target) + { + LOGENTRY(1, "Composite::addWire"); + Wire* wire=new Wire(source, target); + wires.push_back(wire); + LOGEXIT(1, "Composite::addWire"); + } + + void Composite::addInclude(Composite* composite) + { + LOGENTRY(1, "Composite::addInclude"); + includes.push_back(composite); + + for (COMPONENT_MAP::iterator iter = composite->components.begin(); + iter != composite->components.end(); + iter++) + { + components[iter->first] = iter->second; + } + LOGEXIT(1, "Composite::addInclude"); + } + + void Composite::resolveWires() + { + LOGENTRY(1, "Composite::resolveWires"); + + for (WIRES::iterator iter = wires.begin(); + iter != wires.end(); + iter++) + { + Wire* wire = *iter; + + // Locate the target + Service* service = findComponentService(wire->getTarget()); + if (!service) + { + LOGERROR_1(0, "Composite::resolveWires: Wire target %s not found", wire->getTarget().c_str()); + } + else + { + Component* component = findComponent(wire->getSourceComponent()); + if (component) + { + Reference* reference = component->findReference(wire->getSourceReference()); + if (reference) + { + + // Configure the binding on the reference from the binding on the target + // service + reference->getBinding()->configure(service->getBinding()); + } + else + { + LOGERROR_1(0, "Composite::resolveWires: Wire source reference %s not found", wire->getSourceReference().c_str()); + } + } + else + { + LOGERROR_1(0, "Composite::resolveWires: Wire source %s not found", wire->getSourceComponent().c_str()); + } + } + } + + LOGEXIT(1, "Composite::resolveWires"); + } + + void Composite::addWSDLDefinition(commonj::sdo::DataObjectPtr wsdlModel) + { + LOGENTRY(1, "Composite::addWSDLDefinition"); + WSDLDefinition* wsdlDefinition = new WSDLDefinition(wsdlModel); + wsdlDefinitions[wsdlDefinition->getNamespace()] = wsdlDefinition; + LOGEXIT(1, "Composite::addWSDLDefinition"); + + } + + WSDLDefinition* Composite::findWSDLDefinition(const std::string& wsdlNamespace ) + { + return wsdlDefinitions[wsdlNamespace]; + + } + + commonj::sdo::XSDHelperPtr Composite::getXSDHelper() + { + if (xsdHelper == 0) + { + xsdHelper = commonj::sdo::HelperProvider::getXSDHelper(); + } + + return xsdHelper; + } + + commonj::sdo::XMLHelperPtr Composite::getXMLHelper() + { + if (xmlHelper == 0) + { + xmlHelper = commonj::sdo::HelperProvider::getXMLHelper(getXSDHelper()->getDataFactory()); + } + + return xmlHelper; + } + + commonj::sdo::DataFactoryPtr Composite::getDataFactory() + { + return getXSDHelper()->getDataFactory(); + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Composite.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Composite.h new file mode 100644 index 0000000000..3e9fdfa832 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Composite.h @@ -0,0 +1,199 @@ +/* + * 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 "tuscany/sca/export.h" +#include <string> +using std::string; + +#include <map> +using std::map; +#include <vector> +using std::vector; + +#include "commonj/sdo/SDO.h" + +#include "tuscany/sca/model/ComponentType.h" + + +namespace tuscany +{ + namespace sca + { + + namespace model + { + class Component; + class ComponentType; + 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 string& name, const string& root); + + /** + * 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 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/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 string& source, const 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 string& componentName); + + /** + * 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 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 string& wsdlNamespace); + + /** + * 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. + */ + 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 map<string, Component*> COMPONENT_MAP; + COMPONENT_MAP components; + + /** + * Vector of all the composites included in this composite. + */ + typedef vector<Composite*> INCLUDES; + INCLUDES includes; + + /** + * Vector of all the wires in this composite. + */ + typedef vector<Wire*> WIRES; + WIRES wires; + + /** + * Map by namespace of all the wsdl definitions in this composite. + */ + typedef map<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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/CompositeReference.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/CompositeReference.cpp new file mode 100644 index 0000000000..e3ef4b05f4 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/CompositeReference.cpp @@ -0,0 +1,67 @@ +/* + * 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" + +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(1, "CompositeReference::constructor"); + LOGINFO_1(2, "CompositeReference::constructor: CompositeReference 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); + + LOGEXIT(1, "CompositeReference::constructor"); + } + + // Destructor + CompositeReference::~CompositeReference() + { + } + + } // End namespace model + + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/CompositeReference.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/CompositeReference.h new file mode 100644 index 0000000000..aa2ed12e7f --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/CompositeReference.h @@ -0,0 +1,82 @@ +/* + * 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 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; }; + + private: + + /** + * The service exposed by this composite reference. + */ + Service* service; + + }; + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_compositereferencetype_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/CompositeService.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/CompositeService.cpp new file mode 100644 index 0000000000..691091449e --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/CompositeService.cpp @@ -0,0 +1,69 @@ +/* + * 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" + +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(1, "CompositeService::constructor"); + LOGINFO_1(2, "CompositeService::constructor: CompositeService 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); + + LOGEXIT(1, "CompositeService::constructor"); + } + + // Destructor + CompositeService::~CompositeService() + { + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/CompositeService.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/CompositeService.h new file mode 100644 index 0000000000..c0c185676a --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/CompositeService.h @@ -0,0 +1,86 @@ +/* + * 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> +using std::string; +#include <vector> +using std::vector; + +#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 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Contract.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Contract.cpp new file mode 100644 index 0000000000..c9d8f017c7 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Contract.cpp @@ -0,0 +1,47 @@ +/* + * 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) + { + } + + // Destructor + Contract::~Contract() + { + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Contract.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Contract.h new file mode 100644 index 0000000000..da533f4887 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Contract.h @@ -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$ */ + +#ifndef tuscany_sca_model_contract_h +#define tuscany_sca_model_contract_h + +#include <string> +using std::string; + +#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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Interface.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Interface.cpp new file mode 100644 index 0000000000..bbc6c79bc6 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Interface.cpp @@ -0,0 +1,47 @@ +/* + * 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) + { + } + + Interface::~Interface() + { + } + + } // End namespace model + + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Interface.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Interface.h new file mode 100644 index 0000000000..f02476745e --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Interface.h @@ -0,0 +1,91 @@ +/* + * 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> + +using namespace std; + +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 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp new file mode 100644 index 0000000000..fe83807af4 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp @@ -0,0 +1,1815 @@ +/* + * 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/util/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 "commonj/sdo/TypeDefinitions.h" +#include "tuscany/sca/util/File.h" + + +using namespace commonj::sdo; + + +#if defined(WIN32) || defined (_WINDOWS) +#define PATH_SEPARATOR ";" +#else +#define PATH_SEPARATOR ":" +#endif + +namespace tuscany +{ + namespace sca + { + + namespace model + { + // =========== + // Constructor + // =========== + ModelLoader::ModelLoader(Composite* system) : system(system) + { + LOGENTRY(1, "ModelLoader::constructor"); + + runtime = SCARuntime::getInstance(); + + LOGEXIT(1, "ModelLoader::constructor"); + } + + // ========== + // Destructor + // ========== + ModelLoader::~ModelLoader() + { + } + + // ========================================================= + // 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(1, "ModelLoader::load"); + LOGINFO_1(2,"system root: %s", systemRoot.c_str()); + LOGINFO_1(2,"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(); + + LOGEXIT(1, "ModelLoader::load"); + } + + // ======================================================================== + // 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) + { + // Get all the composite files on the system root path + // These composites are included in the system composite + LOGENTRY(1, "ModelLoader::loadSystem"); + for (string path = systemRoot; path != ""; ) + { + string dir; + Utils::tokeniseString(PATH_SEPARATOR, path, dir, path); + if (dir != "") + { + LOGINFO_1(2, "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 + } + } + } + } + LOGEXIT(1, "ModelLoader::loadSystem"); + } + + // ===================================================================== + // 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) + { + // Get all the composite files on the composite search path + LOGENTRY(1, "ModelLoader::loadComposites"); + for (string path = searchPath; path != ""; ) + { + string dir; + Utils::tokeniseString(PATH_SEPARATOR, path, dir, path); + if (dir != "") + { + LOGINFO_1(2, "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); + } + + LOGEXIT(1, "ModelLoader::loadComposites"); + } + + // ==================================================================== + // 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(1, "ModelLoader::loadCompositeFile"); + LOGINFO_1(2, "composite filename: %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_1(0, "ModelLoader::loadCompositeFile: 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_1(0, "ModelLoader::loadCompositeFile: Exception caught: %s", ex.getMessageText()); + } + + LOGEXIT(1, "ModelLoader::loadCompositeFile"); + return composite; + } + + // =========== + // mapCompositePass1 + // =========== + Composite* ModelLoader::mapCompositePass1(const File& file, DataObjectPtr root) + { + LOGENTRY(1, "ModelLoader::mapCompositePass1"); + + const string& compositeRootDir = file.getDirectory(); + const string compositeName = root->getCString("name"); + LOGINFO_2(2, "ModelLoader::mapCompositePass1: Loading composite: %s, root Dir: %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 (int i = 0; i < compositeServiceList.size(); i++) + { + addCompositeService(composite, compositeServiceList[i]); + } + + // ----------------- + // Composite references + // ----------------- + DataObjectList& compositeReferenceList = root->getList("reference"); + for (int cri = 0; cri < compositeReferenceList.size(); cri++) + { + addCompositeReference(composite, compositeReferenceList[cri]); + } + + // ----- + // Wires + // ----- + DataObjectList& wireList = root->getList("wire"); + for (int l = 0; l < wireList.size(); l++) + { + string source = wireList[l]->getCString("source"); + string target = wireList[l]->getCString("target"); + composite->addWire(source, target); + } + + LOGEXIT(1, "ModelLoader::mapCompositePass1"); + return composite; + } + + // =========== + // mapCompositePass2 + // =========== + Composite* ModelLoader::mapCompositePass2(const string& compositeName, DataObjectPtr root) + { + LOGENTRY(1, "ModelLoader::mapCompositePass2"); + + LOGINFO_1(2, "ModelLoader::mapCompositePass2: Loading composite: %s", compositeName.c_str()); + + Composite* composite = compositeModels[compositeName]; + + // ---------------------------- + // Add components to the composite + // ---------------------------- + DataObjectList& componentList = root->getList("component"); + int i; + for (i=0; i < componentList.size(); i++) + { + addComponent(composite, componentList[i]); + } + + // Resolve all the wires inside the composite + composite->resolveWires(); + + LOGEXIT(1, "ModelLoader::mapCompositePass2"); + return composite; + } + + // ================================= + // addComponent: + // ================================= + void ModelLoader::addComponent(Composite* composite, DataObjectPtr componentDO) + { + // ------------------- + // Get the component implementation + // ------------------- + DataObjectPtr impl = componentDO->getDataObject("implementation"); + if (!impl) + { + string message = "No implementation for component: "; + message = message + componentDO->getCString("name"); + throw 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* composite = compositeModels[impl->getCString("name")]; + if (!composite) + { + string message = "Composite not found: "; + message = message + impl->getCString("name"); + throw SystemConfigurationException(message.c_str()); + } + componentType = composite; + } + 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 + LOGINFO_1(0, "ModelLoader::addComponent: 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_2(0, "ModelLoader::addComponent (%s): Exception caught: %s", + typeFileName.c_str(), ex.getMessageText()); + throw SystemConfigurationException(ex.getMessageText()); + } + } + } + else + { + LOGERROR_1(0, "ModelLoader::addComponent: Unsupported implementation type: %s", implTypeQname.c_str()); + + string message = "Implementation type not supported: "; + message = message + implTypeQname; + throw SystemConfigurationException(message.c_str()); + } + } + + // First check that references exist, some component types + // will create all used references automatically + DataObjectList& refs = componentDO->getList("reference"); + for (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; + throw SystemConfigurationException(message.c_str()); + } + } + + // Create the component + Component* component = new Component(composite, componentDO->getCString("name"), componentType); + composite->addComponent(component); + + // ---------- + // Properties + // ---------- + DataObjectList& props = componentDO->getList("property"); + for (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 (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; + throw 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) + { + DataObjectList& serviceTypes = componentTypeDO->getList("service"); + for (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) + { + DataObjectList& refs = componentTypeDO->getList("reference"); + for (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) + { + // ----------------- + // get the interface + // ----------------- + DataObjectPtr iface = obj->getDataObject("interface"); + if (!iface) + { + string message = "No interface for: "; + message = message + obj->getCString("name"); + throw 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_1(1, "ModelLoader::getInterface: Unsupported interface type: %s", typeQname.c_str()); + return 0; + } + } + + } + + // ============================================== + // addProperties: add properties to the component type + // ============================================== + void ModelLoader::addPropertyTypes(ComponentType* componentType, DataObjectPtr componentTypeDO) + { + DataObjectList& props = componentTypeDO->getList("property"); + for (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) + { + + //Utils::printDO(compositeServiceDO); + 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->addComponent(compositeService); + + DataObjectList& refs = compositeServiceDO->getList("reference"); + for (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"); + throw SystemConfigurationException(message.c_str()); + } + DataObjectPtr binding = bindings[0]; + + // Utils::printDO(binding); + + // 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_1(0, "ModelLoader::addCompositeService: Unsupported binding type: %s", bindingTypeQname.c_str()); + + string message = "Binding type not supported: "; + message = message + bindingTypeQname; + throw SystemConfigurationException(message.c_str()); + } + } + + + // ========================================================= + // addCompositeReference: add a CompositeReference to the composite + // ========================================================= + void ModelLoader::addCompositeReference(Composite* composite, DataObjectPtr compositeReferenceDO) + { + 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->addComponent(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"); + throw SystemConfigurationException(message.c_str()); + } + DataObjectPtr binding = bindings[0]; + + //Utils::printDO(binding); + + // 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_1(0, "ModelLoader::addCompositeReference: Unsupported binding type: %s", bindingTypeQname.c_str()); + + string message = "Binding type not supported: "; + message = message + bindingTypeQname; + throw 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(1, "ModelLoader::loadTypeMetadata"); + + // 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_1(0, "ModelLoader::loadTypeMetadata: Unable to load file: %s", filename.c_str()); + } + else + { + LOGINFO_2(2, "ModelLoader::loadTypeMetadata: Loading composite config for: %s, root Dir: %s", composite->getName().c_str(), compositeRootDir.c_str()); + + if(compositeConfigFile->getRootDataObject()->isSet("xsd")) + { + DataObjectList& xsds = compositeConfigFile->getRootDataObject()->getList("xsd/file"); + + for (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 (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()); + } + } + + LOGEXIT(1, "ModelLoader::loadTypeMetadata"); + } + + + /// + /// Use the types from an xsd or wsdl file + /// + void ModelLoader::loadXMLSchema(Composite* composite, const char *fileName) + { + LOGENTRY(1, "ModelLoader::loadXMLSchema"); + + // Load a xsd file -> set the types in the data factory associated with + // the composite + try { + composite->getXSDHelper()->defineFile(fileName); + //Utils::printTypes((*compositeIter)->getXSDHelper()->getDataFactory()); + + } catch (SDOTypeNotFoundException ex) + { + LOGERROR_1(0, "ModelLoader: Exception caught: %s", ex.getMessageText()); + throw ex; + } + LOGEXIT(1, "ModelLoader::loadXMLSchema"); + } + + /// + /// Load the web services definition from a wsdl + /// + void ModelLoader::loadWSDLDefinition(Composite* composite, const char *fileName) + { + LOGENTRY(1, "ModelLoader::loadWSDLDefinition"); + + 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_1(0, "ModelLoader: Unable to load or parse WSDL %s", fileName); + } + + } catch (SDOTypeNotFoundException ex) + { + LOGERROR_1(0, "ModelLoader: SDOTypeNotFoundException caught: %s", ex.getMessageText()); + throw ex; + } + catch (SDONullPointerException ex) + { + LOGERROR_1(0, "ModelLoader: SDONullPointerException caught: %s", ex.getMessageText()); + throw ex; + } + LOGEXIT(1, "ModelLoader::loadWSDLDefinition"); + + } + + ////////////////////////////////////////////////////////////////////////////// + // Methods used to load the model into memory + ////////////////////////////////////////////////////////////////////////////// + + /// + /// Get an XSDHelper that has the appropriate XSDs already loaded + /// + const XSDHelperPtr ModelLoader::getXSDHelper() + { + if (myXSDHelper == 0) + { + + // Create an xsd helper + myXSDHelper = HelperProvider::getXSDHelper(); + + try { + + // Load the Assembly model schema + string root = SCARuntime::getInstance()->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()); + + initializeWSDLModel(myXSDHelper); + + // 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 (SDOTypeNotFoundException ex) + { + LOGERROR_1(0, "ModelLoader: Exception caught: %s", ex.getMessageText()); + throw ex; + } + } + + //cout << myXSDHelper->getDataFactory(); + + return myXSDHelper; + } + + + /// + /// Get an XMLHelper to load files + /// + const XMLHelperPtr ModelLoader::getXMLHelper() + { + if (myXMLHelper == 0) { + + // Create an xml helper + myXMLHelper = HelperProvider::getXMLHelper(getXSDHelper()->getDataFactory()); + + } + + return myXMLHelper; + } + + void ModelLoader::initializeWSDLModel(XSDHelperPtr xsdHelper) + { + DataFactoryPtr dataFactory = xsdHelper->getDataFactory(); + + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "RootType", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tBinding", + false, true, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tBindingOperation", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tBindingOperationFault", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tBindingOperationMessage", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tDefinitions", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tDocumentation", + true, true, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tDocumented", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tExtensibilityElement", + false, false, true); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleAttributesDocumented", + false, true, true); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleDocumented", + false, true, true); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tFault", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tImport", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tMessage", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tOperation", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tParam", + false, false, false); + + + TypeDefinition tpart; + tpart.setUri("http://schemas.xmlsoap.org/wsdl/"); + tpart.setName("tPart"); + tpart.setParentType("http://schemas.xmlsoap.org/wsdl/", + "tExtensibleAttributesDocumented", false); + PropertyDefinition propdef; + propdef.setName("name"); + propdef.setLocalName("name"); + propdef.setType("commonj.sdo", "String"); + propdef.setIsContainment(true); + tpart.addPropertyDefinition(propdef); + propdef.setName("element"); + propdef.setLocalName("element"); + propdef.setIsQName(true); + tpart.addPropertyDefinition(propdef); + propdef.setName("type"); + propdef.setLocalName("type"); + tpart.addPropertyDefinition(propdef); + TypeDefinitions typedefs; + typedefs.addTypeDefinition(tpart); + xsdHelper->defineTypes(typedefs); + + //Utils::printTypes(dataFactory); + /*dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tPart", + false, false, false);*/ + + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tPort", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tPortType", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tService", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/", "tTypes", + false, false, false); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "RootType", + "definitions", + "http://schemas.xmlsoap.org/wsdl/", "tDefinitions", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "RootType", + "import", + "http://schemas.xmlsoap.org/wsdl/", "tImport", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "RootType", + "types", + "http://schemas.xmlsoap.org/wsdl/", "tTypes", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "RootType", + "message", + "http://schemas.xmlsoap.org/wsdl/", "tMessage", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "RootType", + "portType", + "http://schemas.xmlsoap.org/wsdl/", "tPortType", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "RootType", + "binding", + "http://schemas.xmlsoap.org/wsdl/", "tBinding", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "RootType", + "service", + "http://schemas.xmlsoap.org/wsdl/", "tService", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "RootType", + "input", + "http://schemas.xmlsoap.org/wsdl/", "tParam", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "RootType", + "output", + "http://schemas.xmlsoap.org/wsdl/", "tParam", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "RootType", + "fault", + "http://schemas.xmlsoap.org/wsdl/", "tFault", + true, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "RootType", + "output", + "http://schemas.xmlsoap.org/wsdl/", "tParam", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "RootType", + "input", + "http://schemas.xmlsoap.org/wsdl/", "tParam", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "RootType", + "fault", + "http://schemas.xmlsoap.org/wsdl/", "tFault", + true, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "RootType", + "arrayType", + "commonj.sdo", "String", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "RootType", + "required", + "commonj.sdo", "Boolean", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tBinding", + "operation", + "http://schemas.xmlsoap.org/wsdl/", "tBindingOperation", + true, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tBinding", + "name", + "commonj.sdo", "String", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tBinding", + "type", + "commonj.sdo", "URI", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/", "tBindingOperation", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleDocumented"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tBindingOperation", + "input", + "http://schemas.xmlsoap.org/wsdl/", "tBindingOperationMessage", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tBindingOperation", + "output", + "http://schemas.xmlsoap.org/wsdl/", "tBindingOperationMessage", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tBindingOperation", + "fault", + "http://schemas.xmlsoap.org/wsdl/", "tBindingOperationFault", + true, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tBindingOperation", + "name", + "commonj.sdo", "String", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/", "tBindingOperationFault", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleDocumented"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tBindingOperationFault", + "name", + "commonj.sdo", "String", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/", "tBindingOperationMessage", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleDocumented"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tBindingOperationMessage", + "name", + "commonj.sdo", "String", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/", "tDefinitions", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleDocumented"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tDefinitions", + "import", + "http://schemas.xmlsoap.org/wsdl/", "tImport", + true, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tDefinitions", + "types", + "http://schemas.xmlsoap.org/wsdl/", "tTypes", + true, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tDefinitions", + "message", + "http://schemas.xmlsoap.org/wsdl/", "tMessage", + true, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tDefinitions", + "portType", + "http://schemas.xmlsoap.org/wsdl/", "tPortType", + true, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tDefinitions", + "binding", + "http://schemas.xmlsoap.org/wsdl/", "tBinding", + true, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tDefinitions", + "service", + "http://schemas.xmlsoap.org/wsdl/", "tService", + true, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tDefinitions", + "targetNamespace", + "commonj.sdo", "URI", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tDefinitions", + "name", + "commonj.sdo", "String", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tDocumented", + "documentation", + "http://schemas.xmlsoap.org/wsdl/", "tDocumentation", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tExtensibilityElement", + "required", + "commonj.sdo", "Boolean", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleAttributesDocumented", + "http://schemas.xmlsoap.org/wsdl/", "tDocumented"); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleDocumented", + "http://schemas.xmlsoap.org/wsdl/", "tDocumented"); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/", "tFault", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleAttributesDocumented"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tFault", + "name", + "commonj.sdo", "String", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tFault", + "message", + "commonj.sdo", "URI", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/", "tImport", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleAttributesDocumented"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tImport", + "namespace", + "commonj.sdo", "URI", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tImport", + "location", + "commonj.sdo", "URI", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/", "tMessage", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleDocumented"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tMessage", + "part", + "http://schemas.xmlsoap.org/wsdl/", "tPart", + true, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tMessage", + "name", + "commonj.sdo", "String", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/", "tOperation", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleDocumented"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tOperation", + "input", + "http://schemas.xmlsoap.org/wsdl/", "tParam", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tOperation", + "output", + "http://schemas.xmlsoap.org/wsdl/", "tParam", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tOperation", + "fault", + "http://schemas.xmlsoap.org/wsdl/", "tFault", + true, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tOperation", + "name", + "commonj.sdo", "String", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tOperation", + "parameterOrder", + "commonj.sdo", "String", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/", "tParam", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleAttributesDocumented"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tParam", + "name", + "commonj.sdo", "String", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tParam", + "message", + "commonj.sdo", "URI", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/", "tPart", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleAttributesDocumented"); + /*dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tPart", + "name", + "commonj.sdo", "String", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tPart", + "element", + "commonj.sdo", "URI", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tPart", + "type", + "commonj.sdo", "URI", + false, false, true);*/ + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/", "tPort", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleDocumented"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tPort", + "name", + "commonj.sdo", "String", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tPort", + "binding", + "commonj.sdo", "URI", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/", "tPortType", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleAttributesDocumented"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tPortType", + "operation", + "http://schemas.xmlsoap.org/wsdl/", "tOperation", + true, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tPortType", + "name", + "commonj.sdo", "String", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/", "tService", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleDocumented"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tService", + "port", + "http://schemas.xmlsoap.org/wsdl/", "tPort", + true, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/", "tService", + "name", + "commonj.sdo", "String", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/", "tTypes", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibleDocumented"); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap/", "RootType", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap/", "encodingStyle", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tAddress", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tBinding", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tBody", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tFault", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tFaultRes", + false, false, true); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeader", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeaderFault", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tOperation", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tStyleChoice", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap/", "useChoice", + false, false, false); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "RootType", + "binding", + "http://schemas.xmlsoap.org/wsdl/soap/", "tBinding", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "RootType", + "operation", + "http://schemas.xmlsoap.org/wsdl/soap/", "tOperation", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "RootType", + "body", + "http://schemas.xmlsoap.org/wsdl/soap/", "tBody", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "RootType", + "encodingStyle", + "http://schemas.xmlsoap.org/wsdl/soap/", "encodingStyle", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "RootType", + "use", + "http://schemas.xmlsoap.org/wsdl/soap/", "useChoice", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "RootType", + "namespace", + "commonj.sdo", "URI", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "RootType", + "fault", + "http://schemas.xmlsoap.org/wsdl/soap/", "tFault", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "RootType", + "header", + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeader", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "RootType", + "message", + "commonj.sdo", "URI", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "RootType", + "part", + "commonj.sdo", "String", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "RootType", + "use", + "http://schemas.xmlsoap.org/wsdl/soap/", "useChoice", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "RootType", + "encodingStyle", + "http://schemas.xmlsoap.org/wsdl/soap/", "encodingStyle", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "RootType", + "namespace", + "commonj.sdo", "URI", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "RootType", + "headerfault", + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeaderFault", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "RootType", + "address", + "http://schemas.xmlsoap.org/wsdl/soap/", "tAddress", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tAddress", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibilityElement"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tAddress", + "location", + "commonj.sdo", "URI", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tBinding", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibilityElement"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tBinding", + "transport", + "commonj.sdo", "URI", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tBinding", + "style", + "http://schemas.xmlsoap.org/wsdl/soap/", "tStyleChoice", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tBody", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibilityElement"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tBody", + "parts", + "commonj.sdo", "String", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tBody", + "encodingStyle", + "http://schemas.xmlsoap.org/wsdl/soap/", "encodingStyle", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tBody", + "use", + "http://schemas.xmlsoap.org/wsdl/soap/", "useChoice", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tBody", + "namespace", + "commonj.sdo", "URI", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tFault", + "http://schemas.xmlsoap.org/wsdl/soap/", "tFaultRes"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tFault", + "name", + "commonj.sdo", "String", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tFaultRes", + "http://schemas.xmlsoap.org/wsdl/soap/", "tBody"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tFaultRes", + "required", + "commonj.sdo", "Boolean", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tFaultRes", + "parts", + "commonj.sdo", "String", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tFaultRes", + "encodingStyle", + "http://schemas.xmlsoap.org/wsdl/soap/", "encodingStyle", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tFaultRes", + "use", + "http://schemas.xmlsoap.org/wsdl/soap/", "useChoice", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tFaultRes", + "namespace", + "commonj.sdo", "URI", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeader", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibilityElement"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeader", + "headerfault", + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeaderFault", + true, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeader", + "message", + "commonj.sdo", "URI", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeader", + "part", + "commonj.sdo", "String", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeader", + "use", + "http://schemas.xmlsoap.org/wsdl/soap/", "useChoice", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeader", + "encodingStyle", + "http://schemas.xmlsoap.org/wsdl/soap/", "encodingStyle", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeader", + "namespace", + "commonj.sdo", "URI", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeaderFault", + "message", + "commonj.sdo", "URI", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeaderFault", + "part", + "commonj.sdo", "String", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeaderFault", + "use", + "http://schemas.xmlsoap.org/wsdl/soap/", "useChoice", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeaderFault", + "encodingStyle", + "http://schemas.xmlsoap.org/wsdl/soap/", "encodingStyle", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tHeaderFault", + "namespace", + "commonj.sdo", "URI", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tOperation", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibilityElement"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tOperation", + "soapAction", + "commonj.sdo", "URI", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tOperation", + "style", + "http://schemas.xmlsoap.org/wsdl/soap/", "tStyleChoice", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap/", "tStyleChoice", + "commonj.sdo", "String"); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap/", "useChoice", + "commonj.sdo", "String"); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/http/", "RootType", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/http/", "addressType", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/http/", "bindingType", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/http/", "operationType", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/http/", "urlEncoded", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/http/", "urlReplacement", + false, false, false); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/http/", "RootType", + "address", + "http://schemas.xmlsoap.org/wsdl/http/", "addressType", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/http/", "RootType", + "binding", + "http://schemas.xmlsoap.org/wsdl/http/", "bindingType", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/http/", "RootType", + "operation", + "http://schemas.xmlsoap.org/wsdl/http/", "operationType", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/http/", "RootType", + "urlEncoded", + "http://schemas.xmlsoap.org/wsdl/http/", "urlEncoded", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/http/", "RootType", + "urlReplacement", + "http://schemas.xmlsoap.org/wsdl/http/", "urlReplacement", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/http/", "addressType", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibilityElement"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/http/", "addressType", + "location", + "commonj.sdo", "URI", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/http/", "bindingType", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibilityElement"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/http/", "bindingType", + "verb", + "commonj.sdo", "String", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/http/", "operationType", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibilityElement"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/http/", "operationType", + "location", + "commonj.sdo", "URI", + false, false, true); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/mime/", "RootType", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/mime/", "contentType", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/mime/", "multipartRelatedType", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/mime/", "tMimeXml", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/mime/", "tPart", + false, true, false); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/mime/", "RootType", + "content", + "http://schemas.xmlsoap.org/wsdl/mime/", "contentType", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/mime/", "RootType", + "multipartRelated", + "http://schemas.xmlsoap.org/wsdl/mime/", "multipartRelatedType", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/mime/", "RootType", + "mimeXml", + "http://schemas.xmlsoap.org/wsdl/mime/", "tMimeXml", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/mime/", "contentType", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibilityElement"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/mime/", "contentType", + "type", + "commonj.sdo", "String", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/mime/", "contentType", + "part", + "commonj.sdo", "String", + false, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/mime/", "multipartRelatedType", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibilityElement"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/mime/", "multipartRelatedType", + "part", + "http://schemas.xmlsoap.org/wsdl/mime/", "tPart", + true, false, true); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/mime/", "tMimeXml", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibilityElement"); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/mime/", "tMimeXml", + "part", + "commonj.sdo", "String", + false, false, true); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/wsdl/mime/", "tPart", + "name", + "commonj.sdo", "String", + false, false, true); + + + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "RootType", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tAddress", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tBinding", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tBody", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tExtensibilityElementOpenAttrs", + false, true, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tFault", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tFaultRes", + false, false, true); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tHeader", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tHeaderFault", + false, true, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tOperation", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tParts", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tStyleChoice", + false, false, false); + dataFactory->addType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "useChoice", + false, false, false); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tAddress", + "http://schemas.xmlsoap.org/wsdl/soap12/", "tExtensibilityElementOpenAttrs"); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tBinding", + "http://schemas.xmlsoap.org/wsdl/soap12/", "tExtensibilityElementOpenAttrs"); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tBody", + "http://schemas.xmlsoap.org/wsdl/soap12/", "tExtensibilityElementOpenAttrs"); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tExtensibilityElementOpenAttrs", + "http://schemas.xmlsoap.org/wsdl/", "tExtensibilityElement"); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tFault", + "http://schemas.xmlsoap.org/wsdl/soap12/", "tFaultRes"); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tFaultRes", + "http://schemas.xmlsoap.org/wsdl/soap12/", "tBody"); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tHeader", + "http://schemas.xmlsoap.org/wsdl/soap12/", "tExtensibilityElementOpenAttrs"); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tOperation", + "http://schemas.xmlsoap.org/wsdl/soap12/", "tExtensibilityElementOpenAttrs"); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "tStyleChoice", + "commonj.sdo", "String"); + dataFactory->setBaseType( + "http://schemas.xmlsoap.org/wsdl/soap12/", "useChoice", + "commonj.sdo", "String"); + } + + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ModelLoader.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ModelLoader.h new file mode 100644 index 0000000000..d0374e61d6 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ModelLoader.h @@ -0,0 +1,129 @@ +/* + * 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 "tuscany/sca/export.h" +#include "commonj/sdo/SDO.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" + +#include <map> +using std::map; + +using commonj::sdo::DataObjectPtr; +using commonj::sdo::XSDHelperPtr; +using namespace tuscany::sca; + + +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(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 string& systemRoot, const string& systemPath); + + private: + void loadSystem(const string& systemRoot); + + void loadComposites(const string& searchPath); + Composite* loadCompositeFile(const File& file); + Composite* mapCompositePass1(const File& file, DataObjectPtr rootDO); + Composite* mapCompositePass2(const string& compositeName, DataObjectPtr rootDO); + + void addComponent(Composite* composite, DataObjectPtr componentDO); + void addCompositeService(Composite* composite, DataObjectPtr compositeServiceDO); + void addCompositeReference(Composite* composite, DataObjectPtr referenceServiceDO); + + void addServiceTypes(Composite* composite, ComponentType* componentType, DataObjectPtr componentTypeDO); + void addReferenceTypes(Composite* composite, ComponentType* componentType, DataObjectPtr componentTypeDO); + void addPropertyTypes(ComponentType* componentType, DataObjectPtr componentTypeDO); + + void loadTypeMetadata(const string &compositeRootDir, Composite* composite); + + void loadXMLSchema(Composite* composite, const char *fileName); + void loadWSDLDefinition(Composite* composite, const char *fileName); + void initializeWSDLModel(XSDHelperPtr xsdHelper); + + Interface* getInterface(Composite* composite, 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 map<string, Composite*> COMPOSITE_MODELS; + COMPOSITE_MODELS compositeModels; + + typedef map<string, DataObjectPtr> COMPOSITE_DATAOBJECTS; + COMPOSITE_DATAOBJECTS compositeDataObjects; + + typedef map<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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Reference.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Reference.cpp new file mode 100644 index 0000000000..98084c6261 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Reference.cpp @@ -0,0 +1,72 @@ +/* + * 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/Exceptions.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/ReferenceType.h" + +namespace tuscany +{ + namespace sca + { + namespace model + { + + // Constructor + Reference::Reference(Component* component, ReferenceType* referenceType) + : component(component), type(referenceType), binding(0) + { + } + + // Destructor + Reference::~Reference() + { + } + + void Reference::setBinding(ReferenceBinding* binding) + { + this->binding = binding; + } + + ReferenceBinding* Reference::getBinding() const + { + return binding; + } + + void Reference::addTarget(Service* target) + { + if (type->getMultiplicity() == ReferenceType::ONE_ONE || type->getMultiplicity() == ReferenceType::ZERO_ONE) + { + if (targets.size() > 0) + { + // throw exception + string message = "Duplicate wire for reference: " + type->getName(); + throw SystemConfigurationException(message.c_str()); + } + } + + targets.push_back(target); + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Reference.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Reference.h new file mode 100644 index 0000000000..b58ca54b4a --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Reference.h @@ -0,0 +1,129 @@ +/* + * 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 <string> +using std::string; +#include <vector> +using std::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 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ReferenceBinding.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ReferenceBinding.cpp new file mode 100644 index 0000000000..e18f8f3461 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ReferenceBinding.cpp @@ -0,0 +1,47 @@ +/* + * 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" + + +namespace tuscany +{ + namespace sca + { + + namespace model + { + + // Constructor + ReferenceBinding::ReferenceBinding(Reference *reference, const string& uri) : + Binding(uri), reference(reference) + { + } + + // Destructor + ReferenceBinding::~ReferenceBinding() + { + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ReferenceBinding.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ReferenceBinding.h new file mode 100644 index 0000000000..259d088a26 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ReferenceBinding.h @@ -0,0 +1,95 @@ +/* + * 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> +using std::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 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; + + /** + * Returns the reference. + * @return The reference. + */ + SCA_API Reference* getReference() const { return reference; }; + + private: + + /** + * The reference configured with the binding. + */ + Reference* reference; + + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_referencebinding_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ReferenceType.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ReferenceType.cpp new file mode 100644 index 0000000000..cc9b40ca5b --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ReferenceType.cpp @@ -0,0 +1,82 @@ +/* + * 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/Exceptions.h" +#include "tuscany/sca/model/ReferenceType.h" + +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) + { + } + + ReferenceType::~ReferenceType() + { + } + + ReferenceType::Multiplicity ReferenceType::getMultiplicityFromString(const string& multip) + { + 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ReferenceType.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ReferenceType.h new file mode 100644 index 0000000000..a9d6adc0eb --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ReferenceType.h @@ -0,0 +1,139 @@ +/* + * 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> +using std::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 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 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 string& multip); + + private: + + /** + * The component type on which this reference is defined. + */ + ComponentType *componentType; + + /** + * The name of the reference type. + */ + 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Service.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Service.cpp new file mode 100644 index 0000000000..83a2858248 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Service.cpp @@ -0,0 +1,56 @@ +/* + * 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/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) + { + } + + // Destructor + Service::~Service() + { + } + + 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Service.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Service.h new file mode 100644 index 0000000000..bd632b7a3b --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Service.h @@ -0,0 +1,103 @@ +/* + * 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 + +#include <string> +using std::string; + +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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ServiceBinding.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ServiceBinding.cpp new file mode 100644 index 0000000000..b8f1aabb2c --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ServiceBinding.cpp @@ -0,0 +1,47 @@ +/* + * 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" + + +namespace tuscany +{ + namespace sca + { + + namespace model + { + + // Constructor + ServiceBinding::ServiceBinding(Service* service, const string& uri) : + Binding(uri), service(service) + { + } + + // Destructor + ServiceBinding::~ServiceBinding() + { + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ServiceBinding.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ServiceBinding.h new file mode 100644 index 0000000000..feaa989505 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/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> +using std::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 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ServiceType.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ServiceType.cpp new file mode 100644 index 0000000000..40ecca2ceb --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ServiceType.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/model/ServiceType.h" + +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) + { + } + + // Destructor + ServiceType::~ServiceType() + { + } + + 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ServiceType.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ServiceType.h new file mode 100644 index 0000000000..7b6dd4b97f --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/ServiceType.h @@ -0,0 +1,109 @@ +/* + * 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> +using std::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 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 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. + */ + 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLDefinition.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLDefinition.cpp new file mode 100644 index 0000000000..ac7bf0306b --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLDefinition.cpp @@ -0,0 +1,448 @@ +/* + * 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/model/WSDLDefinition.h" +#include "tuscany/sca/model/WSDLOperation.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/util/Exceptions.h" + +using namespace tuscany::sca; + +using namespace commonj::sdo; + +namespace tuscany +{ + namespace sca + { + namespace model + { + + + // Constructor + WSDLDefinition::WSDLDefinition(DataObjectPtr wsdlModel) + : wsdlModel(wsdlModel) + { + LOGENTRY(1, "WSDLDefinition::constructor"); + + // Trace + //Utils::printDO(wsdlModel); + + LOGEXIT(1, "WSDLDefinition::constructor"); + } + + WSDLDefinition::~WSDLDefinition() + { + } + + + /// + /// The namespace of the service and other definitions defined in this wsdl definition + string WSDLDefinition::getNamespace() + { + return wsdlModel->getCString("targetNamespace"); + } + + /// + /// Find the operation defined in this wsdl + /// + const WSDLOperation& WSDLDefinition::findOperation(const string& serviceName, + const string& portName, + const string& operationName) + { + string message; + + string operationKey = serviceName+"#"+portName+"#"+operationName; + OperationMap::iterator iter = operationMap.find(operationKey); + if (iter != operationMap.end()) + { + return iter->second; + } + + // Find the service + DataObjectPtr service = findService(serviceName); + if (!service) + { + // Service not found + message = "Unable to find service "; + message = message + serviceName; + message = message + " in the WSDL definition"; + throw SystemConfigurationException(message.c_str()); + } + else + { + + + // Found the service + DataObjectList& portList = service->getList("port"); + for (int j=0; j<portList.size();j++) + { + string portListName(portList[j]->getCString("name")); + if (portListName.compare(portName) == 0) + { + // found port + // Add address at this point + string targetAddress(portList[j]->getCString("address/location")); + + // find operation by traversing the binding, portType then operation + string wsBindingName(portList[j]->getCString("binding")); + + DataObjectPtr wsBinding = findBinding(wsBindingName); + if (!wsBinding) + { + message = "Unable to find binding "; + message = message + wsBindingName; + message = message + " in the WSDL definition"; + throw SystemConfigurationException(message.c_str()); + } + + + string soapAction = ""; + bool documentStyle = true; + bool wrappedStyle = true; + bool useEncoded = false; + WSDLOperation::soapVersion soapVer = WSDLOperation::SOAP11; + + // Find the binding operation + DataObjectList& bindingOperationList = wsBinding->getList("operation"); + for (int i=0; i<bindingOperationList.size(); i++) + { + string name(bindingOperationList[i]->getCString("name")); + + if (name.compare(operationName) == 0) + { + DataObjectPtr op = bindingOperationList[i]->getDataObject("operation"); + string opType = op->getType().getURI(); + if (opType == "http://schemas.xmlsoap.org/wsdl/soap12/") + { + soapVer = WSDLOperation::SOAP12; + } + + // Get the soapAction + soapAction = bindingOperationList[i]->getCString("operation/soapAction"); + + // Get the style + string style = bindingOperationList[i]->getCString("operation/style"); + if (style == "") + { + style = wsBinding->getCString("binding/style"); + } + if (style != "document") + { + documentStyle = false; + wrappedStyle = false; + } + + // get the use + string use = bindingOperationList[i]->getCString("input/body/use"); + if (use == "encoded") + { + useEncoded = true; + } + } + } + + + // TODO - get the style from the binding or operation???? + + // Found the binding, get the portType + string wsPortTypeName(wsBinding->getCString("type")); + DataObjectPtr wsPortType = findPortType(wsPortTypeName); + if (!wsPortType) + { + message = "Unable to find PortType "; + message = message + wsPortTypeName; + message = message + " in the WSDL definition"; + throw SystemConfigurationException(message.c_str()); + } + + //Utils::printDO(wsPortType); + + // Found the portType, find the operation + DataObjectList& operationList = wsPortType->getList("operation"); + for (int k=0; k< operationList.size(); k++) + { + string opName(operationList[k]->getCString("name")); + if( opName.compare(operationName) == 0) + { + // Found the operation + + // Find the type of the request message + string inputMessageType = string(operationList[k]->getCString("input/message")); + + DataObjectPtr wsMessageIn = findMessage(inputMessageType); + if (!wsMessageIn) + { + message = "Unable to find message "; + message = message + inputMessageType; + message = message + " in the WSDL definition"; + throw SystemConfigurationException(message.c_str()); + } + + string requestType(wsMessageIn->getList("part")[0]->getCString("element")); + + // Find the type of the response message + string outputMessageType = string(operationList[k]->getCString("output/message")); + + DataObjectPtr wsMessageOut = findMessage(outputMessageType); + if (!wsMessageOut) + { + message = "Unable to find message "; + message = message + outputMessageType; + message = message + " in the WSDL definition"; + throw SystemConfigurationException(message.c_str()); + } + + string responseType(wsMessageOut->getList("part")[0]->getCString("element")); + + WSDLOperation& wsdlOp = operationMap[operationKey]; + wsdlOp.setOperationName(operationName); + wsdlOp.setSoapAction(soapAction); + wsdlOp.setEndpoint(targetAddress); + wsdlOp.setSoapVersion(soapVer); + wsdlOp.setDocumentStyle(documentStyle); + wsdlOp.setWrappedStyle(wrappedStyle); + wsdlOp.setEncoded(useEncoded); + wsdlOp.setInputType(requestType); + wsdlOp.setOutputType(responseType); + return wsdlOp; + } + + } + + message = "Unable to find Operation "; + message = message + operationName; + message = message + " in the WSDL definition"; + throw SystemConfigurationException(message.c_str()); + } + } + // cannot find the port + message = "Unable to find port "; + message = message + portName; + message = message + " in the WSDL definition"; + throw SystemConfigurationException(message.c_str()); + } + + } + + /// + /// Find the operation defined in this wsdl + /// + const WSDLOperation& WSDLDefinition::findOperation(const string& portTypeName, + const string& operationName) + { + string operationKey = portTypeName+"#"+operationName; + OperationMap::iterator iter = operationMap.find(operationKey); + if (iter != operationMap.end()) + { + return iter->second; + } + + string soapAction = getNamespace() + "#" + operationName; + bool documentStyle = true; + bool wrappedStyle = true; + bool useEncoded = false; + WSDLOperation::soapVersion soapVer = WSDLOperation::SOAP11; + + // Get the portType + DataObjectPtr wsPortType = findPortType(portTypeName); + if (!wsPortType) + { + string message = "Unable to find PortType "; + message = message + portTypeName; + message = message + " in the WSDL definition"; + throw SystemConfigurationException(message.c_str()); + } + + //Utils::printDO(wsPortType); + + // Found the portType, find the operation + DataObjectList& operationList = wsPortType->getList("operation"); + for (int k=0; k< operationList.size(); k++) + { + string opName(operationList[k]->getCString("name")); + if( opName.compare(operationName) == 0) + { + // Found the operation + + // Find the type of the request message + string inputMessageType = string(operationList[k]->getCString("input/message")); + + DataObjectPtr wsMessageIn = findMessage(inputMessageType); + if (!wsMessageIn) + { + string message = "Unable to find message "; + message = message + inputMessageType; + message = message + " in the WSDL definition"; + throw SystemConfigurationException(message.c_str()); + } + + string requestType(wsMessageIn->getList("part")[0]->getCString("element")); + + // Find the type of the response message + string outputMessageType = string(operationList[k]->getCString("output/message")); + + DataObjectPtr wsMessageOut = findMessage(outputMessageType); + if (!wsMessageOut) + { + string message = "Unable to find message "; + message = message + outputMessageType; + message = message + " in the WSDL definition"; + throw SystemConfigurationException(message.c_str()); + } + + string responseType(wsMessageOut->getList("part")[0]->getCString("element")); + + WSDLOperation& wsdlOp = operationMap[operationKey]; + wsdlOp.setOperationName(operationName); + wsdlOp.setSoapAction(soapAction); + wsdlOp.setEndpoint(""); + wsdlOp.setSoapVersion(soapVer); + wsdlOp.setDocumentStyle(documentStyle); + wsdlOp.setWrappedStyle(wrappedStyle); + wsdlOp.setEncoded(useEncoded); + wsdlOp.setInputType(requestType); + wsdlOp.setOutputType(responseType); + return wsdlOp; + } + } + + string message = "Unable to find Operation "; + message = message + operationName; + message = message + " in the WSDL definition"; + throw SystemConfigurationException(message.c_str()); + + } + + /// + /// Find a service + /// + DataObjectPtr WSDLDefinition::findService(const string& serviceName) + { + DataObjectPtr service = 0; + + + // Find the binding + DataObjectList& serviceList = wsdlModel->getList("service"); + for (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) + { + DataObjectPtr binding = 0; + string uri; + string name; + + + //Utils::tokeniseQName(bindingName, uri, name); + Utils::rTokeniseString(":", bindingName, uri, name); + + + // Find the binding + DataObjectList& bindingList = wsdlModel->getList("binding"); + for (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) + { + DataObjectPtr portType = 0; + string uri; + string name; + + + // Utils::tokeniseQName(portTypeName, uri, name); + Utils::rTokeniseString(":", portTypeName, uri, name); + + + // Find the binding + DataObjectList& portTypeList = wsdlModel->getList("portType"); + for (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) + { + DataObjectPtr message = 0; + string uri; + string name; + + + // Utils::tokeniseQName(messageName, uri, name); + Utils::rTokeniseString(":", messageName, uri, name); + + + // Find the binding + DataObjectList& messageList = wsdlModel->getList("message"); + for (int i=0; i<messageList.size(); i++) + { + string nameMessage(messageList[i]->getCString("name")); + + if (nameMessage.compare(name) == 0) + { + return messageList[i]; + } + } + + return message; + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLDefinition.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLDefinition.h new file mode 100644 index 0000000000..1f07294dcb --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLDefinition.h @@ -0,0 +1,143 @@ +/* + * 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 "tuscany/sca/model/WSDLOperation.h" + +#include "tuscany/sca/export.h" +#include <string> +using std::string; + +#include "commonj/sdo/SDO.h" +using commonj::sdo::DataObjectPtr; + +#include <map> +using std::map; + +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(DataObjectPtr wsdlModel); + + /** + * Destructor. + */ + SCA_API virtual ~WSDLDefinition(); + + + /** + * Returns the target namespace of the WSDL definitions. + * @return The target namespace. + */ + SCA_API string getNamespace(void); + + /** + * 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 string& serviceName, + const string& portName, + const 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 string& portTypeName, + const string& operationName); + + 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. + */ + DataObjectPtr findService(const 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. + */ + DataObjectPtr findBinding(const 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. + */ + DataObjectPtr findPortType(const 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. + */ + DataObjectPtr findMessage(const string& messageName); + + + /** + * The data object representation of the WSDL document. + */ + DataObjectPtr wsdlModel; + + typedef map<string, WSDLOperation> OperationMap; + OperationMap operationMap; + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_wsdldefinition_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLInterface.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLInterface.cpp new file mode 100644 index 0000000000..1b7aed525c --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLInterface.cpp @@ -0,0 +1,102 @@ +/* + * 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" + + +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) + { + parse(qname); + } + + void WSDLInterface::parse(const string& qname) + { + // 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() + { + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLInterface.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLInterface.h new file mode 100644 index 0000000000..e59453e3f2 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLInterface.h @@ -0,0 +1,100 @@ +/* + * 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 "tuscany/sca/model/Interface.h" + +#include <string> +using std::string; + +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 string& qname, bool remotable, bool conversational); + + /** + * Destructor. + */ + virtual ~WSDLInterface(); + + /** + * Returns the WSDL namespace + */ + string getNamespaceURI() const { return namespaceURI; } + + /** + * Returns the interface name + */ + 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 string& getInterfaceTypeQName() { return typeQName; }; + + /** + * The QName of the schema type for this interface type. + */ + SCA_API static const string typeQName; + + private: + + /** + * Parse the WSDL qname + */ + void parse(const string& qname); + + /** + * WSDL namespace. + */ + string namespaceURI; + + /** + * Name of the WSDL interface. + */ + string name; + + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_wsdlinterface_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLOperation.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLOperation.cpp new file mode 100644 index 0000000000..264286caf3 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLOperation.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/model/WSDLOperation.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" + +namespace tuscany +{ + namespace sca + { + namespace model + { + + + // Constructor + WSDLOperation::WSDLOperation() + { + LOGENTRY(1, "WSDLOperation::constructor"); + LOGEXIT(1, "WSDLOperation::constructor"); + } + + WSDLOperation::~WSDLOperation() + { + } + + + void WSDLOperation::setInputType(const string& inputType) + { + Utils::tokeniseQName(inputType, inputTypeUri, inputTypeName); + } + + void WSDLOperation::setOutputType(const string& outputType) + { + Utils::tokeniseQName(outputType, outputTypeUri, outputTypeName); + } + + } // End namespace model + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLOperation.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLOperation.h new file mode 100644 index 0000000000..371c67a6da --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/WSDLOperation.h @@ -0,0 +1,147 @@ +/* + * 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 "tuscany/sca/export.h" +#include <string> +using std::string; + + +#include "commonj/sdo/SDO.h" +using commonj::sdo::DataObjectPtr; + +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. + * @param operation The name of the operation. + * @param soapAction The soapAction associated with this operation + * in the SOAP binding of the operation. + * @param endpoint The endpoint address of the operation. + * @param responseName The name of the response message. + */ + 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 string& getOperationName() const {return operationName;} + SCA_API void setOperationName(const string& opName) {operationName = opName;} + + /** + * The soap action string for this operation. + * @return The soap action. + */ + SCA_API const string& getSoapAction() const {return soapAction;} + SCA_API void setSoapAction(const string& soapAct) {soapAction = soapAct;} + + /** + * Return the endpoint address for the target web service. + * @return The endpoint address. + */ + SCA_API const string& getEndpoint() const {return endpoint;} + SCA_API void setEndpoint(const 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 setEncoded(bool enc) {encoded = enc;} + SCA_API bool isEncoded() const {return encoded;} + + + SCA_API void setInputType(const string& inputType); + SCA_API const string& getInputTypeUri() const {return inputTypeUri;} + SCA_API const string& getInputTypeName() const {return inputTypeName;} + SCA_API void setOutputType(const string& outputType); + SCA_API const string& getOutputTypeUri() const {return outputTypeUri;} + SCA_API const string& getOutputTypeName() const {return outputTypeName;} + + private: + /** + * The name of the operation for use when serializing an + * outgoing message. + */ + string operationName; + + /** + * The soap action string for this operation. + */ + string soapAction; + + /** + * The endpoint address of the target web service. + */ + string endpoint; + + bool documentStyle; + bool wrappedStyle; + bool encoded; + soapVersion soapVer; + + string inputTypeUri; + string inputTypeName; + + string outputTypeUri; + string outputTypeName; + + DataObjectPtr inputMessage; + DataObjectPtr outputMessage; + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_wsdloperation_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Wire.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Wire.cpp new file mode 100644 index 0000000000..77caae53a2 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Wire.cpp @@ -0,0 +1,48 @@ +/* + * 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" + +namespace tuscany +{ + namespace sca + { + namespace model + { + + // Constructor + Wire::Wire(const std::string& source, const std::string& targ) + { + Utils::tokeniseUri(source, sourceComponent, sourceReference); + target = targ; + } + + Wire::~Wire() + { + } + + } // End namespace model + + + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Wire.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Wire.h new file mode 100644 index 0000000000..707ac5da0e --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/model/Wire.h @@ -0,0 +1,95 @@ +/* + * 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> +using std::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 string& source, const 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 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 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 string& getTarget() { return target; } + + private: + /** + * The source component of the wire. + */ + string sourceComponent; + + /** + * The source reference of the wire. + */ + string sourceReference; + + /** + * The target uri of the wire. + */ + string target; + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_model_wire_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/DefaultLogWriter.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/DefaultLogWriter.cpp new file mode 100644 index 0000000000..7b0b535523 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/DefaultLogWriter.cpp @@ -0,0 +1,45 @@ +/* + * 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/DefaultLogWriter.h" +#include <iostream> +using namespace std; + +namespace tuscany +{ + namespace sca + { + DefaultLogWriter::~DefaultLogWriter() + { + } + + void DefaultLogWriter::log(int level, const char* msg) + { + for (int i=0; i < level; i++) + { + cout << " "; + } + cout << msg <<endl; + } + + } // End namespace sca +} // End namespace tuscany + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/DefaultLogWriter.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/DefaultLogWriter.h new file mode 100644 index 0000000000..2c797010d0 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/DefaultLogWriter.h @@ -0,0 +1,48 @@ +/* + * 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_util_defaultlogwriter_h +#define tuscany_sca_util_defaultlogwriter_h + +#include "tuscany/sca/util/LogWriter.h" + +namespace tuscany +{ + namespace sca + { + /** + * Log writer to write out to standard out. + */ + class DefaultLogWriter : public LogWriter + { + public: + virtual ~DefaultLogWriter(); + + /** + * Will write to the console. + * See LogWriter#log. + */ + virtual void log(int level, const char* msg); + }; + + } // End namespace sca +} // End namespace tuscany +#endif // tuscany_sca_util_defaultlogwriter_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Exceptions.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Exceptions.cpp new file mode 100644 index 0000000000..d8f86e0147 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Exceptions.cpp @@ -0,0 +1,213 @@ +/* + * 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/Exceptions.h" +#include "tuscany/sca/util/Logging.h" +using namespace std; + +namespace tuscany +{ + namespace sca + { + + // ======================================================================== + // Constructor + // ======================================================================== + TuscanyRuntimeException :: TuscanyRuntimeException(const char* name, + severity_level sev, + const char* msg_text) + : severity(sev), location_set(0) + { + class_name = new char[strlen(name) + 1]; + strcpy(class_name,name); + message_text = new char[strlen(msg_text)+1]; + strcpy(message_text,msg_text); + LOGERROR_2(1, "%s raised: %s", class_name, message_text); + + } // end TuscanyRuntimeException constuctor + + // ======================================================================== + // Constructor + // ======================================================================== + TuscanyRuntimeException :: TuscanyRuntimeException(const TuscanyRuntimeException& c) + : + severity(c.getSeverity()), location_set(c.location_set) + + { + class_name = new char[strlen(c.getEClassName()) + 1]; + strcpy(class_name, c.getEClassName()); + message_text = new char[strlen(c.getMessageText())+1]; + strcpy(message_text,c.getMessageText()); + for (int i=0;i<c.location_set;i++) + { + locations[i].file = new char[strlen(c.locations[i].file) + 1]; + strcpy(locations[i].file,c.locations[i].file); + locations[i].line = c.locations[i].line; + locations[i].function = new char[strlen(c.locations[i].function) + 1]; + strcpy(locations[i].function, c.locations[i].function); + } + LOGERROR_2(1, "%s raised: %s", class_name, message_text); + } + + // ======================================================================== + // Destructor + // ======================================================================== + TuscanyRuntimeException :: ~TuscanyRuntimeException() + { + if (class_name) delete class_name; + if (message_text) delete message_text; + for (int i=0;i<location_set;i++) + { + if (locations[i].file) delete locations[i].file; + if (locations[i].function) delete locations[i].function; + } + + } // end TuscanyRuntimeException destructor + + // ======================================================================== + // Return class name of this exception + // ======================================================================== + const char* TuscanyRuntimeException :: getEClassName() const + { + return class_name; + } // end getClassName() + + // ======================================================================== + // Return severity + // ======================================================================== + TuscanyRuntimeException::severity_level TuscanyRuntimeException :: getSeverity() const + { + return severity; + } // end getSeverity() + + // ======================================================================== + // Return message text associated with exception + // ======================================================================== + const char* TuscanyRuntimeException :: getMessageText() const + { + return message_text; + } // end getMessageText() + + // ======================================================================== + // Return file name where exception was raised + // ======================================================================== + const char* TuscanyRuntimeException :: getFileName() const + { + return locations[0].file; + } // end getFileName() + + // ======================================================================== + // Return line number where exception was raised + // ======================================================================== + unsigned long TuscanyRuntimeException :: getLineNumber() const + { + return locations[0].line; + } // end getLineNumber() + + // ======================================================================== + // Return function name where exception was raised + // ======================================================================== + const char* TuscanyRuntimeException :: getFunctionName() const + { + return locations[0].function; + } // end getFunctionName() + + + // ======================================================================== + // set severity of exception + // ======================================================================== + void TuscanyRuntimeException :: setSeverity(severity_level sev) + { + severity = sev; + } // end setSeverity(severity_level sev) const + + // ======================================================================== + // set message text associated with exception + // ======================================================================== + void TuscanyRuntimeException :: setMessageText(const char* msg_text) + { + if (message_text != 0) delete message_text; + message_text = new char[strlen(msg_text) + 1]; + strcpy(message_text,msg_text); + } // end setMessageText(const string &msg_text) const + + // ======================================================================== + // set location of most recent throw/handling of the exception + // ======================================================================== + void TuscanyRuntimeException :: setLocation(const char* file, + unsigned long line, + const char* function) + { + if (location_set < num_locations) + { + locations[location_set].file = new char[strlen(file) + 1]; + strcpy(locations[location_set].file,file); + locations[location_set].line = line; + locations[location_set].function = new char[strlen(function) + 1]; + strcpy(locations[location_set].function,function); + + location_set++; + } + } // end setLocation() + + + // ======================================================================== + // print self + // ======================================================================== + ostream& TuscanyRuntimeException :: PrintSelf(ostream &os) const + { + + os << "Exception object :" << endl; + os << " class: " << class_name << endl; + os << " description: " << message_text << endl; + if (location_set != 0) + { + os << " file name: " << locations[0].file << endl; + char lineNumber[100]; + sprintf(lineNumber, "%lu",locations[0].line); + os << " line number: " << lineNumber << endl; + os << " function: " << locations[0].function << endl; + os << " location history:" << endl; + + int i=1; + while (i < location_set) + { + os << " " << i << ")" << endl; + os << " file: " << locations[i].file << endl; + os << " line: " << locations[i].line << endl; + os << " function: " << locations[i].function << endl; + i++; + } + } + return os; + } // end ostream operator << + + // ======================================================================== + // ostream operator << + // ======================================================================== + SCA_API ostream& operator<< (ostream &os, const TuscanyRuntimeException &except) + { + return except.PrintSelf(os); + } // end ostream operator << + + + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Exceptions.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Exceptions.h new file mode 100644 index 0000000000..16188ed550 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Exceptions.h @@ -0,0 +1,190 @@ +/* + * 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_util_exceptions_h +#define tuscany_sca_util_exceptions_h + + +#include "tuscany/sca/export.h" + +#include <ostream> + + +namespace tuscany +{ + namespace sca + { + /** + * Top level exception to represent all the exceptions that may be + * thrown by an SCA runtime implementation. + */ + class SCA_API TuscanyRuntimeException + { + public: + /** + * Represents the possible severity levels for an exception. + */ + enum severity_level + { + Normal, + Warning, + Error, + Severe + }; + + /** + * Constructor. + * @param name Class name of the exception. + * @param sev Severity level. + * @param msg_text Detailed description of the exception. + */ + TuscanyRuntimeException( + const char *name="TuscanyRuntimeException", + severity_level sev=Severe, + const char* msg_text=""); + + TuscanyRuntimeException(const TuscanyRuntimeException& c); + + // Destructor + virtual ~TuscanyRuntimeException(); + + /** + * Return class name of this exception. + */ + const char* getEClassName() const; + + /** + * Return severity. + */ + severity_level getSeverity() const; + + /** + * Return message text associated with exception. + */ + const char* getMessageText() const; + + /* + * Return file name where the exception was raised. + */ + const char* getFileName() const; + + /** + * Return line number where the exception was raised. + */ + unsigned long getLineNumber() const; + + /** + * Return function name where the exception was raised. + */ + const char* getFunctionName() const; + + /** + * Set the exception severity. + */ + void setSeverity(severity_level sev); + + /** + * Set the message text associated with exception. + */ + void setMessageText(const char* msg_text); + + /** + * Set the location where the exception was raised. + * @param file Name of the file. + * @param line Line number in the file. + * @param function Name of the function. + */ + void setLocation(const char* file, + unsigned long line, + const char* function=""); + + /** + * Append exception details to ostream. + */ + virtual std::ostream& PrintSelf(std::ostream &os) const; + + /** + * Operator to send exceptions details to a stream. + */ + SCA_API friend std::ostream& operator<< (std::ostream &os, const TuscanyRuntimeException &except); + protected: + + private: + /** + * Class name of the exception. + */ + char* class_name; + + /** + * Severity level of the exception. + */ + severity_level severity; + + /** + * Description of the exception. + */ + char* message_text; // Description of exception + + /** + * Location where the exception was thrown or handled and thrown. + */ + class location + { + public: + char* file; // File name (from __FILE__) + unsigned long line; // Line number (from __LINE__) + char* function; // Function name + }; + + + enum {num_locations=5}; + /** + * Array of locations where the exception has been handled and thrown. + */ + location locations[num_locations]; + + /** + * The current location (index into TuscanyRuntimeException#location). + */ + int location_set; + + + }; // End TuscanyRuntimeException class definition + + + /** + * Indicates a problem in the consistency of the SCA model provided to the + * Tuscany runtime. + */ + class SCA_API SystemConfigurationException: public TuscanyRuntimeException + { + public: + SystemConfigurationException(const char* msg) + : TuscanyRuntimeException("SystemConfigurationException", Severe, + msg) + { + } + private: + }; + + } // End namespace sca +} // End namespace tuscany +#endif // tuscany_sca_util_exceptions_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/File.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/File.cpp new file mode 100644 index 0000000000..20066a09e0 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/File.cpp @@ -0,0 +1,224 @@ +/* + * 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$ */ + +#if defined(WIN32) || defined (_WINDOWS) +#pragma warning(disable: 4786) +#endif + +#include "tuscany/sca/util/File.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/util/Exceptions.h" +#include <iostream> + +#include <string> +#include <iostream> +using namespace std; + +#if defined(WIN32) || defined (_WINDOWS) +#include <windows.h> +#else +#include <unistd.h> +#include <sys/stat.h> +#include <dirent.h> +#endif + +namespace tuscany +{ + namespace sca + { + File::File(const string& dir, const string& file) + : directory(dir), fileName(file) + { + } + File::~File() + { + } + + + Files::Files(const string& rootDir, const string& pattern, bool subdirectories) + : rootDirectory(rootDir) + { + findFiles(rootDirectory, pattern, subdirectories); + } + + Files::~Files() + { + } + + unsigned int Files::size() + { + return files.size(); + } + + const File& Files::operator[] (unsigned int index) + { + if (size() <= index) + { + throw SystemConfigurationException("Files::operator[] index out of bounds"); + } + + FILES::iterator iter = files.begin(); + for (unsigned int i=0; i<index; i++) + { + iter++; + } + + return *iter; + } + + + void Files::findFiles(const string& rootDir, const string& pattern, bool subdirectories) + { + +#if defined(WIN32) || defined (_WINDOWS) + char currentDir[ _MAX_FNAME]; + + + GetCurrentDirectory(_MAX_FNAME, currentDir); + + // Set current directory, from which to search. + if (!SetCurrentDirectory(rootDir.c_str())) + { + cout << "Unable to set current directory to: " << rootDir.c_str() << endl; + return; + } + char fullDirname[ _MAX_FNAME]; + GetCurrentDirectory(_MAX_FNAME, fullDirname); + + // First, look for all files in this directory that meet the pattern + char search[ _MAX_FNAME]; + strcpy(search, pattern.c_str()); + + // Find the first file in the directory + WIN32_FIND_DATA data; + HANDLE searchHandle = FindFirstFile(search, &data); + + int more = TRUE; + if (searchHandle != INVALID_HANDLE_VALUE) + { + // Found some matching files, so call the function with the details of each one + while (more) + { + // Skip over directories + if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + // Add the file to our list + files.push_back(File(fullDirname, data.cFileName)); + } + + more = FindNextFile(searchHandle, &data); + } + } + + + if (!subdirectories) + return; + + // Now recurse down all the directories + // Find the first file in the directory + searchHandle = FindFirstFile( "*.*", &data); + more = TRUE; + + if (searchHandle != INVALID_HANDLE_VALUE) + { + // Found some files in the directory. + while (more) + { + // If directory + if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + { + // Skip over '.' and '..' + if ((strcmp(data.cFileName, ".")) && (strcmp("..", data.cFileName))) + { + // Recurse + findFiles(data.cFileName, pattern, subdirectories); + } + } + + more = FindNextFile(searchHandle, &data); + } + } + SetCurrentDirectory(currentDir); +#else + // Linux + //char fullDirname[MAX_PATH]; + //getcwd(fullDirname, MAX_PATH); + + DIR* root = opendir(rootDir.c_str()); + if (!root) + { + cout << "Unable to open directory: " << rootDir.c_str() << endl; + return; + } + + bool exactMatch = true; + string token1, token2; + if (pattern.find('*') != string::npos) + { + exactMatch = false; + Utils::tokeniseString("*", pattern, token1, token2); + } + + struct dirent *entry=0; + while ((entry = readdir(root))) + { + string entryName = rootDir + "/" + entry->d_name; + struct stat statbuf; + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) + continue; + if (stat(entryName.c_str(), &statbuf) != 0) + { + perror("stat"); + } + else + { + if (S_ISDIR(statbuf.st_mode)) + { + if (subdirectories) + { + findFiles(entryName, pattern, subdirectories); + } + } + else if (S_ISREG(statbuf.st_mode)) + { + string filename = entry->d_name; + + if ((exactMatch && filename == pattern) || + (!exactMatch && + ((filename.find(token1) == 0) + && (filename.length() >= token2.length()) + && (filename.rfind(token2) == (filename.length() - token2.length())) ))) + { + // Add the file to our list + files.push_back(File(rootDir, filename)); + } + } + } + } + closedir(root); +#endif + } + + + } // End namespace sca +} // End namespace tuscany + + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/File.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/File.h new file mode 100644 index 0000000000..a0aef07cf3 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/File.h @@ -0,0 +1,135 @@ +/* + * 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_util_file_h +#define tuscany_sca_util_file_h + +#include <string> +using std::string; +#include <vector> +using std::vector; + +namespace tuscany +{ + namespace sca + { + /** + * File access methods. Provides platform independent + * access to files. + */ + class File + { + public: + /** + * Constructor. + * @param directory Name of the directory in which this file is located. + * Either / or \ can be used interchangeably for separating directory elements. + * @param fileName Name of the file in the dirctory. + */ + File(const string& directory, const string& fileName); + + /** + * Destructor. + */ + virtual ~File(); + + /** + * Return the directory in which this file is located. + * @return Name of the directory. + */ + const string& getDirectory() const {return directory;} + + /** + * Name of the file. + * @return Name of the file. + */ + const string& getFileName() const {return fileName;} + private: + /** + * Name of the directory. + */ + string directory; + + /** + * Name of the file. + */ + string fileName; + }; + + /** + * Collection of File to provide platform independent access + * to files and directories. + */ + class Files + { + public: + /** + * Constructor which will search a given directory with a pattern and return a + * new instance of this collection class. + * @param rootDirectory The directory in which to search. + * @param pattern A pattern for matching file names. Can include * and ?. + * @param subdirectories Whether subdirectories should be searched too. + */ + Files(const string& rootDirectory, const string& pattern, bool subdirectories = false); + + /** + * Destructor. + */ + virtual ~Files(); + + /** + * Return the number of files found. + * @return The number of files found. + */ + unsigned int size(); + + /** + * Return a File at this position in the collection. + * @param index The index into the collection. + * @return The File at this index in the collection. + */ + const File& operator[] (unsigned int index); + + private: + /** + * Search the given directory and pattern for matching files. + * @param rootDirectory The directory in which to search. + * @param pattern A pattern for matching file names. Can include * and ?. + * @param subdirectories Whether subdirectories should be searched too. + */ + void findFiles(const string& rootDirectory, const string& pattern, bool subdirectories); + + /** + * The top level directory to search. + */ + string rootDirectory; + + typedef vector<File> FILES; + + /** + * Vector of File. + */ + FILES files; + }; + + } // End namespace sca +} // End namespace tuscany +#endif // tuscany_sca_util_file_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/FileLogWriter.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/FileLogWriter.cpp new file mode 100644 index 0000000000..109d398e1a --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/FileLogWriter.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/FileLogWriter.h" +#include <iostream> +using namespace std; + +namespace tuscany +{ + namespace sca + { + FileLogWriter::FileLogWriter(const char* logfile) + { + logFile.open(logfile, ios_base::app); + } + + FileLogWriter::~FileLogWriter() + { + logFile.close(); + } + + void FileLogWriter::log(int level, const char* msg) + { + for (int i=0; i < level; i++) + { + logFile << " "; + } + logFile << msg <<endl; + } + + } // End namespace sca +} // End namespace tuscany + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/FileLogWriter.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/FileLogWriter.h new file mode 100644 index 0000000000..50d25ee932 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/FileLogWriter.h @@ -0,0 +1,55 @@ +/* + * 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_util_filelogwriter_h +#define tuscany_sca_util_filelogwriter_h + +#include "tuscany/sca/util/LogWriter.h" +#include <iostream> +#include <fstream> +using std::ofstream; + +namespace tuscany +{ + namespace sca + { + /** + * Log writer to write out to standard out. + */ + class FileLogWriter : public LogWriter + { + public: + FileLogWriter(const char* logfile); + + virtual ~FileLogWriter(); + + /** + * Will write to the console. + * See LogWriter#log. + */ + virtual void log(int level, const char* msg); + private: + ofstream logFile; + }; + + } // End namespace sca +} // End namespace tuscany +#endif // tuscany_sca_util_defaultlogwriter_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Library.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Library.cpp new file mode 100644 index 0000000000..a9ff01b293 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Library.cpp @@ -0,0 +1,160 @@ +/* + * 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$ */ + +#if defined(WIN32) || defined (_WINDOWS) +#pragma warning(disable: 4786) +#endif + +#include "tuscany/sca/util/Library.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/util/Exceptions.h" +#include "tuscany/sca/util/Logging.h" + +namespace tuscany +{ + namespace sca + { + Library::Library() + : hDLL(NULL) + { + } + + Library::Library(const string& libraryName) + : name(libraryName), hDLL(NULL) + { + LOGINFO_1(3, "Library::construcor : %s", name.c_str()); + load(); + } + + Library::Library(const Library& lib) + : name(lib.name), hDLL(NULL) + { + LOGINFO_1(3, "Library::copy constructor : %s", name.c_str()); + if (lib.hDLL) + { + load(); + } + } + + Library& Library::operator=(const Library& lib) + { + LOGINFO_1(3, "Library::operator= : %s", name.c_str()); + if (&lib != this) + { + unload(); + name = lib.name; + load(); + } + return *this; + } + + Library::~Library() + { + LOGINFO_1(3, "Library::destructor: %s", name.c_str()); + unload(); + } + + + void Library::load() + { + LOGINFO_1(3, "Library::load : %s", name.c_str()); + string msg; +#if defined(WIN32) || defined (_WINDOWS) + int l = name.length(); + string dllName; + if (l>=4 && name.substr(l-4, 4)==".dll") + { + dllName = name; + } + else + { + dllName = name+".dll"; + } + hDLL = LoadLibrary(dllName.c_str()); + if (hDLL == NULL) + { + msg = "Unable to load library: " + dllName; + } +#else + int l = name.length(); + string soName; + if (l>=3 && name.substr(l-3, 3)==".so") + { + soName = name; + } + else + { + int s = name.rfind("/"); + if (s == name.length()) + { + soName = name + ".so"; + } + else + { + s++; + soName = name.substr(0, s) + "lib" + name.substr(s, name.length()-s) + ".so"; + } + } + hDLL = dlopen(soName.c_str(), RTLD_NOW); + if (hDLL == NULL) + { + msg = "Unable to load library: " + soName + ": " + dlerror(); + } +#endif + if (hDLL == NULL) + { + LOGERROR(1, msg.c_str()); + throw SystemConfigurationException(msg.c_str()); + } + } + + void Library::unload() + { + if (hDLL != NULL) + { + LOGINFO_1(3, "Library::unload : %s", name.c_str()); +#if defined(WIN32) || defined (_WINDOWS) + FreeLibrary(hDLL); +#else + dlclose(hDLL); +#endif + hDLL = NULL; + } + } + + void* Library::getSymbol(const string& symbol) + { + LOGINFO_1(3, "Library::getSymbol : %s", symbol.c_str()); + if (!hDLL) + { + return 0; + } +#if defined(WIN32) || defined (_WINDOWS) + return GetProcAddress(hDLL, symbol.c_str()); +#else + return dlsym(hDLL, symbol.c_str()); +#endif + } + + } // End namespace sca +} // End namespace tuscany + + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Library.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Library.h new file mode 100644 index 0000000000..48b2ad4430 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Library.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_util_library_h +#define tuscany_sca_util_library_h +#include "tuscany/sca/export.h" + +#if defined(WIN32) || defined (_WINDOWS) +#include <windows.h> +#else +#include <unistd.h> +#include <dlfcn.h> +#endif + +#include <string> +using std::string; + +namespace tuscany +{ + namespace sca + { + /** + * Information about shared libraries and methods to + * access these shared libraries. + */ + class SCA_API Library + { + public: + Library(); + + /** + * Constructor. Will load the library. + * @param libraryName Fully qualified name of the library. + */ + Library(const string& libraryName); + + /** + * Destructor. Will unload the library. + */ + virtual ~Library(); + + Library(const Library& lib); + Library& operator=(const Library& lib); + + /** + * Find an externalized symbol in the library. + * @param symbol The name of the symbol to be found. + * @return The pointer to the symbol if found, otherwise 0. + */ + void* getSymbol(const string& symbol); + private: + /** + * Name of the library. + */ + string name; + + /** + * Handle to the loaded library. + */ +#if defined(WIN32) || defined (_WINDOWS) + HINSTANCE hDLL; +#else + void* hDLL; +#endif + + /** + * Load the library. + */ + void load(); + + /** + * Unload the library, if successfully loaded. + */ + void unload(); + + }; + + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_util_library_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/LogWriter.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/LogWriter.cpp new file mode 100644 index 0000000000..7613e14c4a --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/LogWriter.cpp @@ -0,0 +1,34 @@ +/* + * 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/LogWriter.h" + +namespace tuscany +{ + namespace sca + { + LogWriter::~LogWriter() + { + } + + } // End namespace sca +} // End namespace tuscany + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/LogWriter.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/LogWriter.h new file mode 100644 index 0000000000..430ce1a785 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/LogWriter.h @@ -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$ */ + +#ifndef tuscany_sca_util_logwriter_h +#define tuscany_sca_util_logwriter_h + +#include "tuscany/sca/export.h" + +namespace tuscany +{ + namespace sca + { + /** + * Abstract class for extending logging to other destinations. + */ + class SCA_API LogWriter + { + public: + virtual ~LogWriter(); + + /** + * Log a message. + * @param level The level of logging for this message. + * @param msg The message to log. + */ + virtual void log(int level, const char* msg) = 0; + }; + + } // End namespace sca +} // End namespace tuscany +#endif // tuscany_sca_util_logwriter_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Logger.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Logger.cpp new file mode 100644 index 0000000000..cdaa3e562b --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Logger.cpp @@ -0,0 +1,109 @@ +/* + * 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 <stdarg.h> + +#include "tuscany/sca/util/Logger.h" +#include "tuscany/sca/util/DefaultLogWriter.h" +#include "tuscany/sca/util/FileLogWriter.h" + +using namespace std; + +namespace tuscany +{ + namespace sca + { + LogWriter* Logger::logWriter = getLogWriter(); + + LogWriter* Logger::getLogWriter() + { + if (logWriter == 0) + { + setLogWriter(0); + } + return logWriter; + } + + void Logger::setLogWriter(LogWriter* writer) + { + if (logWriter != writer + && logWriter != 0) + { + delete logWriter; + } + + if (writer == 0) + { + char* loggingVar = 0; + loggingVar = getenv("TUSCANY_SCACPP_LOG"); + if (loggingVar == 0) + logWriter = new DefaultLogWriter; + else + logWriter = new FileLogWriter(loggingVar); + } + else + { + logWriter = writer; + } + } + + int Logger::loggingLevel = setLogging(); + + int Logger::setLogging() + { + char* loggingVar = 0; + loggingVar = getenv("TUSCANY_SCACPP_LOGGING"); + if (loggingVar == 0) + return 0; + else + return atoi(loggingVar); + } + + void Logger::setLogging(int level) + { + loggingLevel = level; + } + + void Logger::log(int level, const char* msg) + { + if (level <= loggingLevel) + { + logWriter->log(level, msg); + } + } + + void Logger::logArgs(int level, const char* msg, ...) + { + if (level <= loggingLevel) + { + va_list variableArguments; + va_start(variableArguments, msg); + char messageBuffer[1024]; + vsprintf(messageBuffer, msg, variableArguments); + logWriter->log(level, messageBuffer); + va_end(variableArguments); + } + } + + } // End namespace sca +} // End namespace tuscany + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Logger.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Logger.h new file mode 100644 index 0000000000..b0b09adc50 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Logger.h @@ -0,0 +1,91 @@ +/* + * 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_util_logger_h +#define tuscany_sca_util_logger_h + +#include "tuscany/sca/export.h" +#include "tuscany/sca/util/LogWriter.h" +namespace tuscany +{ + namespace sca + { + /** + * Provide a logging interface. + */ + class Logger { + + public: + /** + * Set the log writer to use. + * @param writer The writer to use for all subsequent logging. + */ + SCA_API static void setLogWriter(LogWriter* writer); + + /** + * Set or reset the logging level. Any message with a higher logging + * level than this value will be filtered (i.e. not shown). + * @param level The level of logging to use for all subsequent logging. + */ + SCA_API static void setLogging(int level); + + /** + * Log a message. + * @param level The log level of this message. + * @param msg The message to be logged. + */ + SCA_API static void log(int level, const char* msg); + + /** + * Log a message with variable arguments. + * @param level The log level of this message. + * @param msg The message to be logged. Must include template + * characters as described in printf. + * @param ... Variable arguments. + */ + SCA_API static void logArgs(int level, const char* msg, ...); + + /** + * The currently set logging level + */ + SCA_API static int loggingLevel; + + private: + /** + * The current log writer. + */ + static LogWriter* logWriter; + + /** + * Get the current log writer. + * @return The current log writer. + */ + static LogWriter* getLogWriter(); + + /** + * Retrieves the logging level set as an environment variable. + */ + static int setLogging(); + }; + + } // End namespace sca +} // End namespace tuscany +#endif // tuscany_sca_util_logger_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Logging.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Logging.h new file mode 100644 index 0000000000..047c653229 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Logging.h @@ -0,0 +1,67 @@ +/* + * 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_util_logging_h +#define tuscany_sca_util_logging_h + +#include "tuscany/sca/util/Logger.h" + +#define LOGENTRY(level, methodName) \ +if (tuscany::sca::Logger::loggingLevel >= level) \ +tuscany::sca::Logger::log(level, "Entering: " methodName); + +#define LOGEXIT(level, methodName) \ +if (tuscany::sca::Logger::loggingLevel >= level) \ +tuscany::sca::Logger::log(level, "Exiting: " methodName); + +#define LOGINFO(level, message) \ +if (tuscany::sca::Logger::loggingLevel >= level) \ +tuscany::sca::Logger::log(level, message); + +#define LOGINFO_1(level, message, arg1) \ +if (tuscany::sca::Logger::loggingLevel >= level) \ +tuscany::sca::Logger::logArgs(level, message, arg1); + +#define LOGINFO_2(level, message, arg1, arg2) \ +if (tuscany::sca::Logger::loggingLevel >= level) \ +tuscany::sca::Logger::logArgs(level, message, arg1, arg2); + +#define LOGINFO_3(level, message, arg1, arg2, arg3) \ +if (tuscany::sca::Logger::loggingLevel >= level) \ +tuscany::sca::Logger::logArgs(level, message, arg1, arg2, arg3); + +#define LOGERROR(level, message) \ +if (tuscany::sca::Logger::loggingLevel >= level) \ +tuscany::sca::Logger::log(level, message); + +#define LOGERROR_1(level, message, arg1) \ +if (tuscany::sca::Logger::loggingLevel >= level) \ +tuscany::sca::Logger::logArgs(level, message, arg1); + +#define LOGERROR_2(level, message, arg1, arg2) \ +if (tuscany::sca::Logger::loggingLevel >= level) \ +tuscany::sca::Logger::logArgs(level, message, arg1, arg2); + +#define LOGERROR_3(level, message, arg1, arg2, arg3) \ +if (tuscany::sca::Logger::loggingLevel >= level) \ +tuscany::sca::Logger::logArgs(level, message, arg1, arg2, arg3); + +#endif // tuscany_sca_util_logging_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Utils.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Utils.cpp new file mode 100644 index 0000000000..447f498eff --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Utils.cpp @@ -0,0 +1,562 @@ +/* + * 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$ */ + +#if defined(WIN32) || defined (_WINDOWS) +#pragma warning(disable: 4786) +#endif + +#include "tuscany/sca/util/Utils.h" + +using namespace std; +using namespace commonj::sdo; +namespace tuscany +{ + namespace sca + { + void Utils::tokeniseUri(const string& uri, string& token1, string& token2) + { + tokeniseString("/", uri, token1, token2); + } + + void Utils::tokeniseQName(const string& qname, string& uri, string& name) + { + tokeniseString("#", qname, uri, name); + if (name == "") + { + name = uri; + uri = ""; + } + } + + void Utils::tokeniseString( + const string& separator, + const string& str, + string& token1, + string& token2) + { + string::size_type sep = str.find(separator); + if (sep != string::npos) + { + token1 = str.substr(0, sep); + if ( (sep+1) < str.length()) + { + token2 = str.substr(sep+1); + } + else + { + token2 = ""; + } + } + else + { + token1 = str; + token2 = ""; + } + } + + void Utils::rTokeniseString( + const string& separator, + const string& str, + string& token1, + string& token2) + { + string::size_type sep = str.rfind(separator); + if (sep != string::npos) + { + token1 = str.substr(0, sep); + if ( (sep+1) < str.length()) + { + token2 = str.substr(sep+1); + } + else + { + token2 = ""; + } + } + else + { + token1 = ""; + token2 = str; + } + } + + void Utils::breakpoint() { + // dummy method used to set breakpoints + } + + ////////////////////////////////////////////////////////////////////////// + // Print a DatObject tree + ////////////////////////////////////////////////////////////////////////// + void Utils::tabs(int inc) + { + for (int ind=0; ind <inc; ind++) + { + cout << " "; + } + } + + const bool Utils::compareProperties(DataObjectPtr dataObject1, const Property& prop1, DataObjectPtr dataObject2, const Property& prop2, string& diff) + { + if(strcmp(prop1.getName(),prop2.getName()) != 0) + { + diff.append("Differing names for Properties:\n"); + diff.append(prop1.getName()); + diff.append("\n"); + diff.append(prop2.getName()); + return false; + } + + const Type& propertyType1 = prop1.getType(); + const Type& propertyType2 = prop2.getType(); + + if(strcmp(propertyType1.getName(), propertyType2.getName()) != 0 || + strcmp(propertyType1.getURI(),propertyType2.getURI()) != 0 ) + { + diff.append("Differing types for Properties:\n"); + diff.append(propertyType1.getName()); + diff.append("#"); + diff.append(propertyType1.getURI()); + diff.append("\n"); + diff.append(propertyType2.getName()); + diff.append("#"); + diff.append(propertyType2.getURI()); + return false; + } + if (dataObject1->isSet(prop1) != dataObject2->isSet(prop2)) + { + diff.append("Property "); + diff.append(prop1.getName()); + diff.append(" is set on one DataObject but not the other"); + return false; + } + + if (dataObject1->isSet(prop1)) + { + + if (prop1.isMany() != prop2.isMany()) + { + diff.append("Property "); + diff.append(prop1.getName()); + diff.append(" is many on one DataObject but not the other"); + return false; + } + if (propertyType1.isDataType() != propertyType2.isDataType()) + { + diff.append("Property "); + diff.append(prop1.getName()); + diff.append(" is dataType on one DataObject but not the other"); + return false; + } + + ////////////////////////////////////////////////////////////////////// + // For a many-valued property get the list of values + ////////////////////////////////////////////////////////////////////// + if (prop1.isMany()) + { + DataObjectList& dol1 = dataObject1->getList(prop1); + DataObjectList& dol2 = dataObject2->getList(prop2); + if (dol1.size() != dol2.size()) + { + diff.append("Property "); + diff.append(prop1.getName()); + diff.append(" is many but has differing number of elements"); + return false; + } + + for (int j = 0; j <dol1.size(); j++) + { + + if (propertyType1.isDataType()) + { + if( strcmp(dol1.getCString(j), dol2.getCString(j)) != 0) + { + diff.append("Differing value for Property "); + diff.append(prop1.getName()); + diff.append("["); + diff += ((int)j); + diff.append("]:\n"); + diff.append(dol1.getCString(j)); + diff.append("\n"); + diff.append(dol2.getCString(j)); + return false; + } + } + else + { + if(!compareDataObjects(dol1[j], dol2[j], diff)) + { + return false; + } + } + } + } // end IsMany + + + ////////////////////////////////////////////////////////////////////// + // For a primitive data type compare the values + ////////////////////////////////////////////////////////////////////// + else if (propertyType1.isDataType()) + { + if( strcmp(dataObject1->getCString(prop1), dataObject2->getCString(prop2)) != 0) + { + diff.append("Differing value for Property "); + diff.append(prop1.getName()); + diff.append(":\n"); + diff.append(dataObject1->getCString(prop1)); + diff.append("\n"); + diff.append(dataObject2->getCString(prop2)); + return false; + } + } + + ////////////////////////////////////////////////////////////////////// + // For a dataobject compare the DOs + ////////////////////////////////////////////////////////////////////// + else + { + if(!compareDataObjects(dataObject1->getDataObject(prop1), dataObject2->getDataObject(prop2), diff)) + { + return false; + } + } + } + return true; + } + + const bool Utils::compareDataObjects(DataObjectPtr dataObject1, DataObjectPtr dataObject2, string& diff) + { + if (!dataObject1 || !dataObject2) + { + diff.append("Cannot compare null DataObjects"); + return false; + } + + const Type& dataObject1Type = dataObject1->getType(); + const Type& dataObject2Type = dataObject2->getType(); + + if( strcmp(dataObject1Type.getURI(), dataObject2Type.getURI()) != 0 || + strcmp(dataObject1Type.getName(), dataObject2Type.getName()) != 0 ) + { + diff.append("DataObject Types differ:\n"); + diff.append(dataObject1Type.getURI()); + diff.append("#"); + diff.append(dataObject1Type.getName()); + diff.append("\n"); + diff.append(dataObject2Type.getURI()); + diff.append("#"); + diff.append(dataObject2Type.getName()); + return false; + } + + ////////////////////////////////////////////////////////////////////////// + // Iterate over all the properties + ////////////////////////////////////////////////////////////////////////// + PropertyList pl1 = dataObject1->getInstanceProperties(); + PropertyList pl2 = dataObject2->getInstanceProperties(); + if (pl1.size() != pl2.size()) + { + diff.append("Differing number of properties"); + return false; + } + + if (pl1.size() != 0) + { + for (int i = 0; i < pl1.size(); i++) + { + if(!compareProperties(dataObject1, pl1[i], dataObject2, pl2[i], diff)) + { + return false; + } + } + } + else + { + if(dataObject1->getType().isOpenType() != dataObject2->getType().isOpenType() && + dataObject1->getType().isDataObjectType() != dataObject2->getType().isDataObjectType()) + { + diff.append("DataObject is open & DO type on one but not the other"); + return false; + } + + // Compare elements under an open DataObject + if(dataObject1->getType().isOpenType() && dataObject1->getType().isDataObjectType()) + { + SequencePtr sequence1 = dataObject1->getSequence(); + SequencePtr sequence2 = dataObject2->getSequence(); + + if (sequence1 != NULL && sequence2 != NULL) + { + if (sequence1->size() != sequence1->size()) + { + diff.append("Open DataObjects have differing number of elements"); + return false; + } + + for (int i = 0; i < sequence1->size(); i++) + { + if (sequence1->isText(i) != sequence2->isText(i)) + { + diff.append("Open DataObjects have differing element types at position "); + diff += ((int) i); + return false; + } + if (sequence1->isText(i)) + { + if( strcmp(sequence1->getCStringValue(i), sequence2->getCStringValue(i)) != 0) + { + diff.append("Differing value for element at position "); + diff += ((int) i); + diff.append(":\n"); + diff.append(sequence1->getCStringValue(i)); + diff.append("\n"); + diff.append(sequence2->getCStringValue(i)); + return false; + } + } + else + { + const Property& p1 = sequence1->getProperty(i); + const Property& p2 = sequence2->getProperty(i); + + if(!compareProperties(dataObject1, p1, dataObject2, p2, diff)) + { + return false; + } + } + } + } + } + } + + return true; + } + + void Utils::printDO(DataObjectPtr dataObject, int increment) + { + int inc=increment; + if (!dataObject) + return; + const Type& dataObjectType = dataObject->getType(); + tabs(inc); + cout << "DataObject type: " << dataObjectType.getURI()<< "#" << dataObjectType.getName() << endl; + inc++; + + ////////////////////////////////////////////////////////////////////////// + // Iterate over all the properties + ////////////////////////////////////////////////////////////////////////// + PropertyList pl = dataObject->getInstanceProperties(); + if (pl.size() != 0) + { + for (int i = 0; i < pl.size(); i++) + { + tabs(inc); + cout << "Property: " << pl[i].getName() << endl; + + const Type& propertyType = pl[i].getType(); + + tabs(inc); + cout << "Property Type: " << propertyType.getURI()<< "#" << propertyType.getName() << endl; + + if (dataObject->isSet(pl[i])) + { + + ////////////////////////////////////////////////////////////////////// + // For a many-valued property get the list of values + ////////////////////////////////////////////////////////////////////// + if (pl[i].isMany()) + { + inc++; + DataObjectList& dol = dataObject->getList(pl[i]); + for (int j = 0; j <dol.size(); j++) + { + tabs(inc); + cout << "Value " << j <<endl; + inc++; + + if (propertyType.isDataType()) + { + tabs(inc); + cout<< "Property Value: " << dol.getCString(j) <<endl ; + } + else + printDO(dol[j], inc); + inc--; + } + inc--; + } // end IsMany + + + ////////////////////////////////////////////////////////////////////// + // For a primitive data type print the value + ////////////////////////////////////////////////////////////////////// + else if (propertyType.isDataType()) + { + tabs(inc); + cout<< "Property Value: " << dataObject->getCString(pl[i]) <<endl ; + } + + ////////////////////////////////////////////////////////////////////// + // For a dataobject print the do + ////////////////////////////////////////////////////////////////////// + else + { + inc++; + printDO(dataObject->getDataObject(pl[i]), inc); + inc--; + } + } + else + { + tabs(inc); + cout<< "Property Value: not set" <<endl ; + } + + } + } + else + { + // Print elements under an open DataObject + if(dataObject->getType().isOpenType() && dataObject->getType().isDataObjectType()) + { + SequencePtr sequence = dataObject->getSequence(); + if (sequence != NULL) + { + for (int i = 0; i < sequence->size(); i++) + { + if (sequence->isText(i)) + { + tabs(inc); + cout<< "Text Value: " << sequence->getCStringValue(i) <<endl ; + } + else { + const Property& p = sequence->getProperty(i); + + tabs(inc); + cout << "Property: " << p.getName() << endl; + + const Type& propertyType = p.getType(); + + tabs(inc); + cout << "Property Type: " << propertyType.getURI()<< "#" << propertyType.getName() << endl; + + if (dataObject->isSet(p)) + { + + ////////////////////////////////////////////////////////////////////// + // For a many-valued property get the list of values + ////////////////////////////////////////////////////////////////////// + if (p.isMany()) + { + inc++; + DataObjectList& dol = dataObject->getList(p); + for (int j = 0; j <dol.size(); j++) + { + tabs(inc); + cout << "Value " << j <<endl; + inc++; + + if (propertyType.isDataType()) + { + tabs(inc); + cout<< "Property Value: " << dol.getCString(j) <<endl ; + } + else + printDO(dol[j], inc); + inc--; + } + inc--; + } // end IsMany + + + ////////////////////////////////////////////////////////////////////// + // For a primitive data type print the value + ////////////////////////////////////////////////////////////////////// + else if (propertyType.isDataType()) + { + tabs(inc); + cout<< "Property Value: " << dataObject->getCString(p) <<endl ; + } + + ////////////////////////////////////////////////////////////////////// + // For a dataobject print the do + ////////////////////////////////////////////////////////////////////// + else + { + inc++; + printDO(dataObject->getDataObject(p), inc); + inc--; + } + } + else + { + tabs(inc); + cout<< "Property Value: not set" <<endl ; + } + } + } + } + } + } + inc--; + } + + void Utils::printTypes(DataFactoryPtr df) + { + ////////////////////////////////////////////////////////////////////////// + // Retrieve the DataFactory from the mediator + // get the list of Types in the DataFactory and list them + ////////////////////////////////////////////////////////////////////////// + TypeList tl = df->getTypes(); + for (int i = 0; i < tl.size(); i++) + { + cout << "Type: " << tl[i].getURI()<< "#" << tl[i].getName() << endl; + PropertyList pl = tl[i].getProperties(); + for (int j = 0; j < pl.size(); j++) + { + cout << "\tProperty: " << pl[j].getName() + << " type: " <<pl[j].getType().getURI()<<"#"<<pl[j].getType().getName()<< endl; + + } + } + + } + + void Utils::printType(const Type& type, int increment) + { + int inc = increment; + tabs(inc); + cout << "Type: " << type.getURI()<< "#" << type.getName() << endl; + inc++; + PropertyList pl = type.getProperties(); + for (int j = 0; j < pl.size(); j++) + { + tabs(inc); + cout << "\tProperty: " << pl[j].getName() + << " type: " <<pl[j].getType().getURI()<<"#"<<pl[j].getType().getName()<< endl; + inc++; + printType(pl[j].getType(), inc); + inc--; + } + } + + } // End namespace sca +} // End namespace tuscany + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Utils.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Utils.h new file mode 100644 index 0000000000..4d20d952c8 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/src/tuscany/sca/util/Utils.h @@ -0,0 +1,69 @@ +/* + * 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_util_utils_h +#define tuscany_sca_util_utils_h +#include <string> +using std::string; +#include "commonj/sdo/SDO.h" + +#include "tuscany/sca/export.h" + +namespace tuscany +{ + namespace sca + { + /** + * Utility methods to parse strings and provide debugging information. + */ + class SCA_API Utils { + + public: + static void tokeniseUri(const string& uri, string& token1, string& token2); + static void tokeniseQName(const string& sdoname, string& uri, string& name); + static void tokeniseString( + const string& separator, + const string& str, + string& token1, + string& token2); + + static void rTokeniseString( + const string& separator, + const string& str, + string& token1, + string& token2); + + static void breakpoint(); + + static void printDO(commonj::sdo::DataObjectPtr dataObject, int increment=0); + static void printTypes(commonj::sdo::DataFactoryPtr df); + static void printType(const commonj::sdo::Type& type, int increment=0); + + static const bool compareDataObjects(commonj::sdo::DataObjectPtr dataObject1, commonj::sdo::DataObjectPtr dataObject2, string& diff); + static const bool compareProperties(commonj::sdo::DataObjectPtr dataObject1, const commonj::sdo::Property& prop1, commonj::sdo::DataObjectPtr dataObject2, const commonj::sdo::Property& prop2, string& diff); + + private: + static void tabs(int increment=0); + }; + + } // End namespace sca +} // End namespace tuscany +#endif // tuscany_sca_util_utils_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/test/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/test/Makefile.am new file mode 100644 index 0000000000..7aec56841b --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/core/test/Makefile.am @@ -0,0 +1,19 @@ +# 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. + +SUBDIRS = + |