diff options
author | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
---|---|---|
committer | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
commit | bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch) | |
tree | 38a92061c0793434c4be189f1d70c3458b6bc41d /tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions |
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
155 files changed, 15718 insertions, 0 deletions
diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/Makefile.am new file mode 100644 index 0000000000..d3499698ce --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/Makefile.am @@ -0,0 +1,44 @@ +# 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. + +if WANT_ALL + CPP_EXTENSION = cpp + PYTHON_EXTENSION = python + RUBY_EXTENSION = ruby + PHP_EXTENSION = php + WSBINDING_EXTENSION = ws + SCABINDING_EXTENSION = sca +endif +if WANT_CPP + CPP_EXTENSION = cpp +endif +if WANT_PYTHON + PYTHON_EXTENSION = python +endif +if WANT_RUBY + RUBY_EXTENSION = ruby +endif +if WANT_PHP + PHP_EXTENSION = php +endif +if WANT_WSBINDING + WSBINDING_EXTENSION = ws +endif +if WANT_SCABINDING + SCABINDING_EXTENSION = sca +endif +SUBDIRS = ${CPP_EXTENSION} ${WSBINDING_EXTENSION} ${SCABINDING_EXTENSION} ${PYTHON_EXTENSION} ${RUBY_EXTENSION} ${PHP_EXTENSION} diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/Makefile.am new file mode 100644 index 0000000000..7fac33118a --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/Makefile.am @@ -0,0 +1,24 @@ +# 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 + +datadir=$(prefix)/extensions/cpp + +nobase_data_DATA = xsd/*.xsd + +EXTRA_DIST = xsd
\ No newline at end of file diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/deploy.bat b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/deploy.bat new file mode 100644 index 0000000000..e87f3b4dd6 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/deploy.bat @@ -0,0 +1,74 @@ +@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 extdir=%deploydir%\extensions +set cppextdir=%extdir%\cpp +set srcdir=%rootdir%\runtime\extensions\cpp\src + +if . == .%2 ( +echo input directory not specified +goto usage +) +set inpath=%2 +echo %inpath% + + +if not exist %deploydir% mkdir %deploydir% +if not exist %extdir% mkdir %extdir% +if not exist %cppextdir% mkdir %cppextdir% +if not exist %cppextdir%\bin mkdir %cppextdir%\bin +if not exist %cppextdir%\lib mkdir %cppextdir%\lib +if not exist %cppextdir%\include mkdir %cppextdir%\include +if not exist %cppextdir%\include\osoa mkdir %cppextdir%\include\osoa +if not exist %cppextdir%\include\osoa\sca mkdir %cppextdir%\include\osoa\sca +if not exist %cppextdir%\include\tuscany mkdir %cppextdir%\include\tuscany +if not exist %cppextdir%\include\tuscany\sca mkdir %cppextdir%\include\tuscany\sca +if not exist %cppextdir%\include\tuscany\sca\cpp mkdir %cppextdir%\include\tuscany\sca\cpp +if not exist %cppextdir%\include\tuscany\sca\cpp\model mkdir %cppextdir%\include\tuscany\sca\cpp\model +if not exist %cppextdir%\xsd mkdir %cppextdir%\xsd + +del %cppextdir%\bin\tuscany_sca_cpp.* +del %cppextdir%\lib\*.lib + +copy %srcdir%\osoa\sca\*.h %cppextdir%\include\osoa\sca +copy %srcdir%\tuscany\sca\cpp\*.h %cppextdir%\include\tuscany\sca\cpp +copy %srcdir%\tuscany\sca\cpp\model\*.h %cppextdir%\include\tuscany\sca\cpp\model + +copy %srcdir%\..\xsd\*.* %cppextdir%\xsd + +copy %inpath%\tuscany_sca_cpp.lib %cppextdir%\lib +copy %inpath%\tuscany_sca_cpp.dll %cppextdir%\bin + +if exist %inpath%\tuscany_sca_cpp.pdb copy %inpath%\tuscany_sca_cpp.pdb %cppextdir%\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/extensions/cpp/src/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/Makefile.am new file mode 100644 index 0000000000..c579dd2598 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/Makefile.am @@ -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. + +libdir=$(prefix)/extensions/cpp/lib +lib_LTLIBRARIES = libtuscany_sca_cpp.la +includedir=$(prefix)/extensions/cpp/include +nobase_include_HEADERS = \ +osoa/sca/*.h \ +tuscany/sca/cpp/*.h \ +tuscany/sca/cpp/model/*.h + +libtuscany_sca_cpp_la_SOURCES = \ +osoa/sca/ComponentContext.cpp \ +osoa/sca/CompositeContext.cpp \ +tuscany/sca/cpp/ComponentContextImpl.cpp \ +tuscany/sca/cpp/CompositeContextImpl.cpp \ +tuscany/sca/cpp/CPPExtension.cpp \ +tuscany/sca/cpp/CPPImplementationExtension.cpp \ +tuscany/sca/cpp/CPPInterfaceExtension.cpp \ +tuscany/sca/cpp/CPPServiceProxy.cpp \ +tuscany/sca/cpp/CPPServiceWrapper.cpp \ +tuscany/sca/cpp/model/CPPImplementation.cpp \ +tuscany/sca/cpp/model/CPPInterface.cpp \ +tuscany/sca/cpp/model/CPPReferenceBinding.cpp \ +tuscany/sca/cpp/model/CPPServiceBinding.cpp + +libtuscany_sca_cpp_la_LIBADD = -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo \ + -L$(top_builddir)/runtime/core/src -ltuscany_sca + +INCLUDES = -Imodel -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/extensions/cpp/src/osoa/sca/ComponentContext.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/ComponentContext.cpp new file mode 100644 index 0000000000..bd0a6c39db --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/ComponentContext.cpp @@ -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$ */ + +#include "osoa/sca/ComponentContext.h" +#include "tuscany/sca/util/Logging.h" +#include "osoa/sca/ServiceRuntimeException.h" +#include "tuscany/sca/cpp/ComponentContextImpl.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "commonj/sdo/SDO.h" +using commonj::sdo::DataFactoryPtr; + +using namespace tuscany::sca; +using namespace tuscany::sca::cpp; + +namespace osoa +{ + namespace sca + { + + // ======================================================= + // getCurrent: create a context from the current component + // ======================================================= + ComponentContext ComponentContext::getCurrent() + { + LOGENTRY(1, "ComponentContext::getCurrent"); + Component* component = tuscany::sca::SCARuntime::getInstance()->getCurrentComponent(); + if (!component) + { + throw ComponentContextException("No current component"); + } + ComponentContext* cci = new ComponentContextImpl(component); + LOGEXIT(1, "ComponentContext::constructor"); + return ComponentContext(cci); + } + + // =========== + // Constructor + // =========== + ComponentContext::ComponentContext(ComponentContext* implementation) + : impl(implementation) + { + LOGENTRY(1, "ComponentContext::constructor"); + LOGEXIT(1, "ComponentContext::constructor"); + } + + // ========== + // Destructor + // ========== + ComponentContext::~ComponentContext() + { + LOGENTRY(1, "ComponentContext::destructor"); + delete impl; + LOGEXIT(1, "ComponentContext::destructor"); + } + + // =================================== + // Copy constructor: create a new impl + // =================================== + ComponentContext::ComponentContext(const ComponentContext& ctx) + { + Component* component = ((ComponentContextImpl*)impl)->getComponent(); + impl = new ComponentContextImpl(component); + } + + // ============================= + // operator= : create a new impl + // ============================= + ComponentContext& ComponentContext::operator=(const ComponentContext& ctx) + { + if (this != &ctx) + { + Component* component = ((ComponentContextImpl*)impl)->getComponent(); + impl = new ComponentContextImpl(component); + } + return *this; + } + + // ========== + // getService + // ========== + void* ComponentContext::getService(const std::string& referenceName) + { + LOGENTRY(1, "ComponentContext::getService"); + void* service = impl->getService(referenceName); + LOGEXIT(1, "ComponentContext::getService"); + return service; + } + + // =========== + // getServices + // =========== + std::list<void*> ComponentContext::getServices(const std::string& referenceName) + { + return impl->getServices(referenceName); + } + + // ============ + // getProperties + // ============= + DataObjectPtr ComponentContext::getProperties() + { + LOGENTRY(1, "ComponentContext::getProperties"); + DataObjectPtr properties = impl->getProperties(); + LOGEXIT(1, "ComponentContext::getProperties"); + return properties; + } + + // ============ + // getDataFactory + // ============= + DataFactoryPtr ComponentContext::getDataFactory() + { + LOGENTRY(1, "ComponentContext::getDataFactory"); + DataFactoryPtr dataFactory = impl->getDataFactory(); + LOGEXIT(1, "ComponentContext::getDataFactory"); + return dataFactory; + } + + + } // End namespace sca +} // End namespace osoa diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/ComponentContext.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/ComponentContext.h new file mode 100644 index 0000000000..fae62062b2 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/ComponentContext.h @@ -0,0 +1,114 @@ +/* + * 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 osoa_sca_componentcontext_h +#define osoa_sca_componentcontext_h + +#include "osoa/sca/export.h" +#include "commonj/sdo/SDO.h" +#include <string> +#include <list> +namespace osoa +{ + namespace sca + { + + /** + * An SCA component implementation uses the ComponentContext class to + * retrieve information about the configured SCA component. + */ + class SCA_CPP_API ComponentContext + { + + public: + /** + * Return a new ComponentContext for the current Component. + */ + static ComponentContext getCurrent(); + + /** + * Resolve a reference name into a single configured service. + * If the component's reference is wired to more than one service + * then theis method will return an exception. + * @param referenceName The reference to be resolved. This must match + * the name of a reference configured in the component type file for + * this component. + */ + virtual void* getService(const std::string& referenceName); + + /** + * Resolve a reference name into a list of configured services. + * @param referenceName The reference to be resolved. This must match + * the name of a reference configured in the component type file for + * this component. + */ + virtual std::list<void*> getServices(const std::string& referenceName); + + /** + * Get the configured properties for the component. + * @return A data object representing all the properties that + * are configured for this component. + */ + virtual commonj::sdo::DataObjectPtr getProperties(); + + /** + * Get an SDO data factory which will allow the component to + * create data objects for all the types configured for this + * component. + * @return A data factory to be used by the component to create + * new data objects. + */ + virtual commonj::sdo::DataFactoryPtr getDataFactory(); + + /** + * Destructor + */ + virtual ~ComponentContext(); + + /** + * Constructor + */ + ComponentContext(const ComponentContext&); + + /** + * Copy operator + */ + ComponentContext& operator=(const ComponentContext&); + + /** + * Constructor to create an interface class from the contained + * implementation. + * @param implementation the actual implementation class + */ + ComponentContext(ComponentContext* implementation); + + private: + + /** + * Pointer to the class which provides the actual implementation. + */ + ComponentContext* impl; + + }; + } // End namespace sca +} // End namespace osoa + +#endif // osoa_sca_componentcontext_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/CompositeContext.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/CompositeContext.cpp new file mode 100644 index 0000000000..43e5e6806e --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/CompositeContext.cpp @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "osoa/sca/CompositeContext.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/cpp/CompositeContextImpl.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "commonj/sdo/SDO.h" + +using commonj::sdo::DataFactoryPtr; +using namespace tuscany::sca; +using namespace tuscany::sca::cpp; + + +namespace osoa +{ + namespace sca + { + // =========== + // Constructor + // =========== + CompositeContext::CompositeContext(CompositeContext* implementation) + : impl(implementation) + { + } + + // =================================== + // Copy constructor: create a new impl + // =================================== + CompositeContext::CompositeContext(const CompositeContext& ctx) + { + impl = new CompositeContextImpl( + tuscany::sca::SCARuntime::getInstance()->getDefaultComponent()); + } + + // ============================= + // operator= : create a new impl + // ============================= + CompositeContext& CompositeContext::operator=(const CompositeContext& ctx) + { + if (this != &ctx) + { + impl = new CompositeContextImpl( + tuscany::sca::SCARuntime::getInstance()->getDefaultComponent()); + } + return *this; + } + + // ========== + // Destructor + // ========== + CompositeContext::~CompositeContext() + { + LOGENTRY(1, "CompositeContext::destructor"); + delete impl; + LOGEXIT(1, "CompositeContext::destructor"); + } + + // ==================================================== + // getCurrent: create a context from the current composite + // ==================================================== + CompositeContext CompositeContext::getCurrent() + { + LOGENTRY(1, "CompositeContext::getCurrent"); + CompositeContext* cci = new CompositeContextImpl( + tuscany::sca::SCARuntime::getInstance()->getDefaultComponent()); + LOGEXIT(1, "CompositeContext::getCurrent"); + return CompositeContext(cci); + } + + // ============= + // locateService + // ============= + void* CompositeContext::locateService(const std::string& serviceName) + { + LOGENTRY(1, "CompositeContext::locateService"); + void* sp = impl->locateService(serviceName); + LOGEXIT(1, "CompositeContext::locateService"); + return sp; + } + + // ============= + // getDataFactory + // ============= + DataFactoryPtr CompositeContext::getDataFactory() + { + LOGENTRY(1, "CompositeContext::getDataFactory"); + DataFactoryPtr df = impl->getDataFactory(); + LOGEXIT(1, "CompositeContext::getDataFactory"); + return df; + } + + + } // End namespace sca +} // End namespace osoa diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/CompositeContext.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/CompositeContext.h new file mode 100644 index 0000000000..ac13ed875e --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/CompositeContext.h @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef osoa_sca_compositecontext_h +#define osoa_sca_compositecontext_h + +#include "osoa/sca/export.h" +#include "commonj/sdo/SDO.h" + +namespace osoa +{ + namespace sca + { + /** + * An SCA component implementation, or a non-SCA client, uses the + * CompositeContext class to retrieve information about the configured + * SCA composite. + */ + class SCA_CPP_API CompositeContext + { + + public: + /** + * Return a new CompositeContext for the current Component. + */ + static CompositeContext getCurrent(); + + /** + * Resolve a service name into a single component service. + * @param serviceName The name of the service in the form + * "component name"/"service name". The service name is + * optional in the component has one service. + * @return A pointer to an object which can be cast to the + * business interface of the target service. + */ + virtual void* locateService(const std::string& serviceName); + + /** + * Get an SDO data factory which will allow the component to + * create data objects for all the types configured for this + * component. + * @return A data factory to be used by the component to create + * new data objects. + */ + virtual commonj::sdo::DataFactoryPtr getDataFactory(); + + /** + * Destructor. + */ + virtual ~CompositeContext(); + + /** + * Constructor + */ + CompositeContext(const CompositeContext&); + + /** + * Copy operator + */ + CompositeContext& operator=(const CompositeContext&); + + /** + * Constructor to create an interface class from the contained + * implementation. + * @param implementation The actual implementation class. + */ + CompositeContext(CompositeContext* implementation); + + private: + + /** + * Pointer to the class which provides the actual implementation. + */ + CompositeContext* impl; + + }; + } // End namespace sca +} // End namespace osoa + +#endif // osoa_sca_compositecontext_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/ServiceRuntimeException.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/ServiceRuntimeException.h new file mode 100644 index 0000000000..7bf8800242 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/ServiceRuntimeException.h @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef osoa_sca_serviceruntimeexception_h +#define osoa_sca_serviceruntimeexception_h + +#include "osoa/sca/export.h" + +#include "tuscany/sca/util/Exceptions.h" +using tuscany::sca::TuscanyRuntimeException; +namespace osoa +{ + namespace sca + { + /** + * Top level exception to represent all the exceptions that may be + * thrown by an SCA runtime implementation. + */ + class SCA_CPP_API ServiceRuntimeException : public TuscanyRuntimeException + { + public: + ServiceRuntimeException( + const char *name="ServiceRuntimeException", + severity_level sev=Severe, + const char* msg_text="") + : TuscanyRuntimeException(name, sev, msg_text) + { + } + }; // End ServiceRuntimeException class definition + + + /** + * A remotable service is currently unavailable. It is possible that a retry + * may resolve this exception. + */ + class SCA_CPP_API ServiceUnavailableException: public ServiceRuntimeException + { + public: + ServiceUnavailableException(const char* serviceName) + : ServiceRuntimeException("ServiceUnavailableException", Warning, + serviceName) + { + } + private: + }; // End ServiceUnavailableException class definition + + + /** + * The target of a wire cannot be found, or the reference has not been + * configured. + */ + class SCA_CPP_API ServiceNotFoundException: public ServiceRuntimeException + { + public: + ServiceNotFoundException(const char* msg) + : ServiceRuntimeException("ServiceNotFoundException", Error, + msg) + { + } + private: + }; // End ServiceNotFoundException class definition + + + /** + * There is no current component (for example, if a non-SCA component + * tries to get the current ComponentContext). + */ + class SCA_CPP_API ComponentContextException: public ServiceRuntimeException + { + public: + ComponentContextException(const char* msg) + : ServiceRuntimeException("ComponentContextException", Error, + msg) + { + } + private: + }; // End ComponentContextException class definition + + + } // End namespace sca +} // End namespace osoa + +#endif // osoa_sca_serviceruntimeexception_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/export.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/export.h new file mode 100644 index 0000000000..8a69913be4 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/export.h @@ -0,0 +1,42 @@ +/* + * 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 osoa_sca_export_h +#define osoa_sca_export_h + +#if defined(WIN32) || defined (_WINDOWS) +#pragma warning(disable: 4786) + +#ifdef TUSCANY_SCA_CPP_EXPORTS +#define SCA_CPP_API __declspec(dllexport) +#else +#define SCA_CPP_API __declspec(dllimport) +#endif + +#else +#include <sys/time.h> +#include <inttypes.h> +#include <stdlib.h> +#define SCA_CPP_API +#endif + +#endif // osoa_sca_export_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/sca.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/sca.h new file mode 100644 index 0000000000..6cce9453d7 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/osoa/sca/sca.h @@ -0,0 +1,31 @@ +/* + * 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 osoa_sca_sca_h +#define osoa_sca_sca_h + +#include "osoa/sca/export.h" +#include "osoa/sca/CompositeContext.h" +#include "osoa/sca/ComponentContext.h" +#include "osoa/sca/ServiceRuntimeException.h" + +#endif // osoa_sca_sca_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPExtension.cpp new file mode 100644 index 0000000000..b418a52425 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPExtension.cpp @@ -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. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/cpp/CPPExtension.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/cpp/CPPImplementationExtension.h" +#include "tuscany/sca/cpp/CPPInterfaceExtension.h" + + +extern "C" +{ + #if defined(WIN32) || defined(_WINDOWS) + __declspec(dllexport) + #endif + void tuscany_sca_extension_initialize() + { + tuscany::sca::cpp::CPPExtension::initialize(); + } +} + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + // =================================================================== + // Constructor for the CPPExtension class. + // =================================================================== + CPPExtension::CPPExtension() + { + LOGENTRY(1, "CPPExtension::constructor"); + LOGEXIT(1, "CPPExtension::constructor"); + } + + // =================================================================== + // Destructor for the CPPExtension class. + // =================================================================== + CPPExtension::~CPPExtension() + { + LOGENTRY(1, "CPPExtension::destructor");; + LOGEXIT(1, "CPPExtension::destructor"); + } + + void CPPExtension::initialize() + { + LOGENTRY(1, "CPPExtension::initialize");; + SCARuntime::getInstance()->registerImplementationExtension(new CPPImplementationExtension()); + SCARuntime::getInstance()->registerInterfaceExtension(new CPPInterfaceExtension()); + LOGEXIT(1, "CPPExtension::initialize");; + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPExtension.h new file mode 100644 index 0000000000..d6c872629d --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPExtension.h @@ -0,0 +1,57 @@ +/* + * 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_cpp_cppextension_h +#define tuscany_sca_cpp_cppextension_h + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + class CPPExtension + { + public: + /** + * Default constructor + */ + CPPExtension(); + + /** + * Destructor + */ + virtual ~CPPExtension(); + + static void initialize(); + + private: + + }; + + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_cppextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPImplementationExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPImplementationExtension.cpp new file mode 100644 index 0000000000..5ddf4b1113 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPImplementationExtension.cpp @@ -0,0 +1,105 @@ +/* + * 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/cpp/CPPImplementationExtension.h" +#include "tuscany/sca/cpp/model/CPPImplementation.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" + + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + // =================================================================== + // Constructor for the CPPImplementationExtension class. + // =================================================================== + CPPImplementationExtension::CPPImplementationExtension() + { + LOGENTRY(1, "CPPImplementationExtension::constructor"); + LOGEXIT(1, "CPPImplementationExtension::constructor"); + } + + // =================================================================== + // Destructor for the CPPImplementationExtension class. + // =================================================================== + CPPImplementationExtension::~CPPImplementationExtension() + { + LOGENTRY(1, "CPPImplementationExtension::destructor");; + LOGEXIT(1, "CPPImplementationExtension::destructor"); + } + + const string CPPImplementationExtension::extensionName("cpp"); + const string CPPImplementationExtension::typeQName("http://www.osoa.org/xmlns/sca/1.0#CPPImplementation"); + + // =================================================================== + // loadModelElement - load the info from implementation.cpp + // =================================================================== + ComponentType* CPPImplementationExtension::getImplementation(Composite *composite, DataObjectPtr scdlImplementation) + { + string implType = scdlImplementation->getType().getName(); + if (implType == "CPPImplementation") + { + string library = scdlImplementation->getCString("library"); + string header = scdlImplementation->getCString("header"); + string className = scdlImplementation->getCString("class"); + string scopeName = scdlImplementation->getCString("scope"); + + CPPImplementation::Scope scope; + if (scopeName == "composite") + { + scope = CPPImplementation::COMPOSITE; + } + else + { + scope = CPPImplementation::STATELESS; + } + + string headerPath; + string headerStub; + + // Separate any path element + Utils::rTokeniseString("/", header, headerPath, headerStub); + if (headerPath != "") + { + headerPath += "/"; + } + + // Determine the header stub name + string tmp; + Utils::rTokeniseString(".h", headerStub, headerStub, tmp); + + CPPImplementation* cppImpl = new CPPImplementation( + composite, library, header, headerPath, headerStub, className, scope); + + return cppImpl; + } + else + { + return NULL; + } + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPImplementationExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPImplementationExtension.h new file mode 100644 index 0000000000..8548a208e9 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPImplementationExtension.h @@ -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$ */ + +#ifndef tuscany_sca_cpp_cppimplementationextension_h +#define tuscany_sca_cpp_cppimplementationextension_h + +#include "tuscany/sca/extension/ImplementationExtension.h" + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + class CPPImplementationExtension : public ImplementationExtension + { + public: + /** + * Default constructor + */ + CPPImplementationExtension(); + + /** + * Destructor + */ + virtual ~CPPImplementationExtension(); + + /** + * return the name of the extension + */ + virtual const string& getExtensionName() {return extensionName;} + + /** + * return the QName of schema type for this implementation extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#implementation.cpp") + */ + virtual const string& getExtensionTypeQName() {return typeQName;} + + virtual ComponentType* getImplementation(Composite* composite, DataObjectPtr scdlImplementation); + + private: + static const string extensionName; + static const string typeQName; + + }; + + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_cppimplementationextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPInterfaceExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPInterfaceExtension.cpp new file mode 100644 index 0000000000..d470949746 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPInterfaceExtension.cpp @@ -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. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/cpp/CPPInterfaceExtension.h" +#include "tuscany/sca/cpp/model/CPPInterface.h" +#include "tuscany/sca/util/Logging.h" + + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + // =================================================================== + // Constructor for the CPPInterfaceExtension class. + // =================================================================== + CPPInterfaceExtension::CPPInterfaceExtension() + { + LOGENTRY(1, "CPPInterfaceExtension::constructor"); + LOGEXIT(1, "CPPInterfaceExtension::constructor"); + } + + // =================================================================== + // Destructor for the CPPInterfaceExtension class. + // =================================================================== + CPPInterfaceExtension::~CPPInterfaceExtension() + { + LOGENTRY(1, "CPPInterfaceExtension::destructor");; + LOGEXIT(1, "CPPInterfaceExtension::destructor"); + } + + const string CPPInterfaceExtension::extensionName("cpp"); + const string CPPInterfaceExtension::typeQName("http://www.osoa.org/xmlns/sca/1.0#CPPInterface"); + + // =================================================================== + // loadModelElement - load the info from interface.cpp + // =================================================================== + tuscany::sca::model::Interface* CPPInterfaceExtension::getInterface(Composite* composite, DataObjectPtr scdlInterface) + { + // Determine the type + string ifType = scdlInterface->getType().getName(); + if (ifType == "CPPInterface") + { + string header = scdlInterface->getCString("header"); + string className = scdlInterface->getCString("class"); + bool remotable = scdlInterface->getBoolean("remotable"); + + return new CPPInterface(header, className, remotable, false); + } + return 0; + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPInterfaceExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPInterfaceExtension.h new file mode 100644 index 0000000000..62c3b9854b --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPInterfaceExtension.h @@ -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$ */ + +#ifndef tuscany_sca_cpp_cppinterfaceextension_h +#define tuscany_sca_cpp_cppinterfaceextension_h + +#include "tuscany/sca/extension/InterfaceExtension.h" + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + class CPPInterfaceExtension : public InterfaceExtension + { + public: + /** + * Default constructor + */ + CPPInterfaceExtension(); + + /** + * Destructor + */ + virtual ~CPPInterfaceExtension(); + + /** + * return the name of the extension + */ + virtual const string& getExtensionName() {return extensionName;} + + /** + * return the QName of schema type for this interface extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#interface.cpp") + */ + virtual const string& getExtensionTypeQName() {return typeQName;} + + virtual tuscany::sca::model::Interface* getInterface(Composite* composite, DataObjectPtr scdlInterface); + + private: + static const string extensionName; + static const string typeQName; + + }; + + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_cppinterfaceextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceProxy.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceProxy.cpp new file mode 100644 index 0000000000..56511fc9e6 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceProxy.cpp @@ -0,0 +1,193 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/cpp/CPPServiceProxy.h" +#include "tuscany/sca/util/Logging.h" +#include "osoa/sca/ServiceRuntimeException.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/ComponentType.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/ServiceBinding.h" +#include "tuscany/sca/cpp/model/CPPImplementation.h" +#include "tuscany/sca/cpp/model/CPPReferenceBinding.h" + +using namespace osoa::sca; + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + // ============================ + // Constructor: Create a proxy + // ============================ + CPPServiceProxy::CPPServiceProxy(Reference* reference) + : ServiceProxy(reference) + { + LOGENTRY(1,"CPPServiceProxy::constructor"); + + // ---------------------- + // Get the component + // ---------------------- + Component* component = reference->getComponent(); + string name = reference->getType()->getName(); + + // Get the service wrapper + CPPReferenceBinding* referenceBinding = (CPPReferenceBinding*)reference->getBinding(); + + ServiceWrapper* serviceWrapper = referenceBinding->getTargetServiceBinding()->getServiceWrapper(); + + createProxy(component, name, serviceWrapper); + + LOGEXIT(1,"CPPServiceProxy::constructor"); + } + + // ============================ + // Constructor: Create a proxy + // ============================ + CPPServiceProxy::CPPServiceProxy(Service* service) + : ServiceProxy(0) + { + LOGENTRY(1,"CPPServiceProxy::constructor"); + + // ---------------------- + // Get the component + // ---------------------- + Component* component = service->getComponent(); + string name = service->getType()->getName(); + + // Get the service wrapper + ServiceWrapper* serviceWrapper = service->getBinding()->getServiceWrapper(); + + createProxy(component, name, serviceWrapper); + + LOGEXIT(1,"CPPServiceProxy::constructor"); + } + + void CPPServiceProxy::createProxy(Component* component, const string& name, ServiceWrapper* serviceWrapper) + { + LOGENTRY(1,"CPPServiceProxy::createProxy"); + + ComponentType* componentType = component->getType(); + if (!componentType) + { + string msg = "Component " + component->getName() + " has no implementation defined"; + throw ServiceNotFoundException(msg.c_str()); + } + + // If we got here we have a CPP implementation + CPPImplementation* impl = (CPPImplementation *)componentType; + + // ---------------------------------------------------- + // Get implementation dll name and service factory name + // ---------------------------------------------------- + string library = impl->getLibrary(); + string headerStub = impl->getHeaderStub(); + + string fullLibraryName = component->getComposite()->getRoot() + "/" + library; + string proxyFactoryName = headerStub + "_" + name + "_Proxy_Factory"; + string proxyDestructorName = headerStub + "_" + name + "_Proxy_Destructor"; + typedef void* (* PROXYFACTORY) (ServiceWrapper*); + + // ------------ + // Load the dll + // ------------ + proxyLibrary = Library(fullLibraryName); + + // ------------------------- + // Locate the factory method + // ------------------------- + PROXYFACTORY proxyFactory = (PROXYFACTORY)proxyLibrary.getSymbol(proxyFactoryName); + if (!proxyFactory) + { + LOGERROR_2(1, "CPPServiceProxy::createProxy: Unable to locate %s in library %s", + proxyFactoryName.c_str(), fullLibraryName.c_str()); + string msg = "Unable to locate " + proxyFactoryName + " in library " + fullLibraryName; + throw ServiceNotFoundException(msg.c_str()); + } + + // ----------------------------------- + // Now create an instance of the proxy + // ----------------------------------- + void* proxy = proxyFactory(serviceWrapper); + if (!proxy) + { + LOGERROR_2(1, "CPPServiceProxy::createProxy: Factory method %s in library %s returned null", + proxyFactoryName.c_str(), fullLibraryName.c_str()); + string msg = "Factory method " + proxyFactoryName + " in library " + fullLibraryName + " returned null"; + throw ServiceNotFoundException(msg.c_str()); + } + else + { + proxies.push_back(proxy); + } + + // ------------------------- + // Get the destructor method + // ------------------------- + destructor = (PROXYDESTRUCTOR)proxyLibrary.getSymbol(proxyDestructorName); + + LOGEXIT(1,"CPPServiceProxy::createProxy"); + } + + // ========== + // Destructor + // ========== + CPPServiceProxy::~CPPServiceProxy() + { + LOGENTRY(1,"CPPServiceProxy::destructor"); + + // Delete the proxies + if (destructor != NULL && proxies.size() != 0) + { + destructor(*proxies.begin()); + } + LOGEXIT(1,"CPPServiceProxy::destructor"); + } + + CPPServiceProxy::PROXIES CPPServiceProxy::getProxies() + { + return proxies; + } + + void* CPPServiceProxy::getProxy() + { + if (proxies.size() != 0) + { + return *proxies.begin(); + } + else + { + return NULL; + } + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceProxy.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceProxy.h new file mode 100644 index 0000000000..77a20d08b8 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceProxy.h @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + + +#ifndef tuscany_sca_cpp_cppserviceproxy_h +#define tuscany_sca_cpp_cppserviceproxy_h + +#include "osoa/sca/export.h" +#include "tuscany/sca/core/ServiceProxy.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/util/Library.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/Service.h" + +using namespace tuscany::sca::model; + + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + /** + * 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 CPPServiceProxy : public 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. + */ + CPPServiceProxy(Reference* reference); + + /** + * Create a new service proxy for a service. The proxy will contain a pointer to + * the target ServiceWrapper. + * @param reference The service on the target component. + * @param target The wrapper of the target service. + */ + CPPServiceProxy(Service* service); + + /** + * Destructor. + */ + virtual ~CPPServiceProxy(); + + /** + * Return an instance of the proxy created for this particular component and reference. + * @return The proxy. + */ + virtual void* getProxy(); + + /** + * Return the proxies created for this particular component and reference. + * @return The proxies. + */ + typedef std::list<void*> PROXIES; + virtual PROXIES getProxies(); + + private: + + /** + * Create the proxy + */ + void createProxy(Component* component, const string& name, ServiceWrapper* serviceWrapper); + + /** + * Holds the instances of the code generated proxies. + */ + PROXIES proxies; + + /** + * A function pointer to the destructor of the proxy. + */ + typedef void (* PROXYDESTRUCTOR) (void*); + PROXYDESTRUCTOR destructor; + + /** + * The library which contains the code for the proxy. + */ + Library proxyLibrary; + + }; + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_cppserviceproxy_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.cpp new file mode 100644 index 0000000000..3d7df2d44d --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.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/cpp/CPPServiceWrapper.h" + +#include "osoa/sca/ServiceRuntimeException.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/util/Library.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/cpp/model/CPPImplementation.h" +#include "tuscany/sca/model/Interface.h" + +using namespace osoa::sca; + + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + // =================== + // Static data members + // =================== + void* CPPServiceWrapper::staticImpl = 0; + + // =========== + // Constructor + // =========== + CPPServiceWrapper::CPPServiceWrapper(Service* service) + : ServiceWrapper(service) + { + LOGENTRY(1,"CPPServiceWrapper::constructor"); + + component = service->getComponent(); + interf = service->getType()->getInterface(); + implementation = (CPPImplementation*)component->getType(); + + LOGEXIT(1,"CPPServiceWrapper::constructor"); + + } + + // ========== + // Destructor + // ========== + CPPServiceWrapper::~CPPServiceWrapper() + { + LOGENTRY(1,"CPPServiceWrapper::destructor"); + LOGEXIT(1,"CPPServiceWrapper::destructor"); + } + + + // ====================================================================== + // getImplementation: get an implementation for this scope + // ====================================================================== + void* CPPServiceWrapper::getImplementation() + { + if (implementation->getScope() == CPPImplementation::COMPOSITE) + { + if (!staticImpl) + { + staticImpl = newImplementation(); + } + return staticImpl; + } + else // (scope == CPPInterface::STATELESS) + { + return newImplementation(); + } + } + + // ====================================================================== + // releaseImplementation: release the implementation for this scope + // ====================================================================== + void CPPServiceWrapper::releaseImplementation() + { + if (implementation->getScope() == CPPImplementation::STATELESS) + { + deleteImplementation(); + } + } + + // ====================================================================== + // invoke: wrapper call to service with setting the component context + // ====================================================================== + void CPPServiceWrapper::invoke(Operation& operation) + { + LOGENTRY(1,"CPPServiceWrapper::invoke"); + + SCARuntime* runtime = SCARuntime::getInstance(); + runtime->setCurrentComponent(component); + + try + { + invokeService(operation); + } + catch (...) + { + runtime->unsetCurrentComponent(); + throw; + } + runtime->unsetCurrentComponent(); + LOGEXIT(1,"CPPServiceWrapper::invoke"); + + } + + void CPPServiceWrapper::setLibrary(Library* lib) + { + wrapperLibrary = lib; + } + + // ====================================================================== + // getServiceWrapper: create a wrapper for the target ComponentService + // ====================================================================== + CPPServiceWrapper* CPPServiceWrapper::getServiceWrapper(Service* service) + { + CPPServiceWrapper* serviceWrapper = 0; + + // ----------------------------------------------- + // Get the implementation for the target component + // ----------------------------------------------- + Component* component = service->getComponent(); + CPPImplementation* impl = (CPPImplementation*)component->getType(); + if (!impl) + { + string msg = "Component " + component->getName() + " has no implementation defined"; + throw ServiceNotFoundException(msg.c_str()); + } + + // ---------------------------------------------------- + // Get implementation dll name and wrapper factory name + // ---------------------------------------------------- + string libraryName = impl->getLibrary(); + string wrapperFactoryName = impl->getHeaderStub() + + "_" + service->getType()->getName() + "_Wrapper_Factory"; + + // ------------ + // Load the dll + // ------------ + string fullLibraryName = component->getComposite()->getRoot() + "/" + libraryName; + typedef CPPServiceWrapper* (* WRAPPERFACTORY) (Service*); + Library* wrapperLib = new Library(fullLibraryName); + + // ------------------------- + // Locate the factory method + // ------------------------- + WRAPPERFACTORY wrapperFactory = (WRAPPERFACTORY)wrapperLib->getSymbol(wrapperFactoryName); + if (!wrapperFactory) + { + LOGERROR_2(1, "CPPServiceWrapper::getServiceWrapper: Unable to locate %s in library %s", + wrapperFactoryName.c_str(), fullLibraryName.c_str()); + string msg = "Unable to locate " + wrapperFactoryName + " in library " + fullLibraryName; + throw ServiceNotFoundException(msg.c_str()); + } + + // ------------------------------------- + // Now create an instance of the wrapper + // ------------------------------------- + serviceWrapper = wrapperFactory(service); + if (!serviceWrapper) + { + LOGERROR_2(1, "CPPServiceWrapper::getServiceWrapper: Factory method %s in library %s returned null", + wrapperFactoryName.c_str(), fullLibraryName.c_str()); + string msg = "Factory method " + wrapperFactoryName + " in library " + fullLibraryName + " returned null"; + throw ServiceNotFoundException(msg.c_str()); + } + serviceWrapper->setLibrary(wrapperLib); + + return serviceWrapper; + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.h new file mode 100644 index 0000000000..eeeb9cdb82 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.h @@ -0,0 +1,162 @@ +/* + * 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_cpp_cppservicewrapper_h +#define tuscany_sca_cpp_cppservicewrapper_h + +#include "osoa/sca/export.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/core/Operation.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Interface.h" +#include "tuscany/sca/cpp/model/CPPImplementation.h" +#include "tuscany/sca/util/Library.h" + +using namespace tuscany::sca::model; + + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + /** + * Wraps the service on a component implementation. + * This abstract class is extended by generated code which provides + * the implementation of some of the methods. + * An instance of this class wraps the actual component implementation which + * has been written by a developer of an SCA application. + */ + class SCA_CPP_API CPPServiceWrapper : public ServiceWrapper + { + public: + /** + * Factory method to create a new CPPServiceWrapper for a given target + * service. This method will provide all the loading of dlls required to + * create the target component. + * @param target The service on the component for which this wrapper is to be + * created. + * @return A wrapper that references the given target. + */ + static CPPServiceWrapper* getServiceWrapper(Service* service); + + /** + * Constructor. + * @param target The component service to which this wrapper refers. + */ + CPPServiceWrapper(Service* service); + + /** + * Destructor. + */ + virtual ~CPPServiceWrapper(); + + /** + * All business method calls to the target component go through the invoke method. + * @param operation The details of the method, paramaters and return value for the + * business method to be called on the target component. + */ + virtual void invoke(Operation& operation); + + /** + * Return the loaded shared library for the target component. + */ + Library* getLibrary() const { return wrapperLibrary; } + + protected: + + /** + * Delegated method to invoke the correct method on the target component. + * Implemented by the subtype. + */ + virtual void invokeService(Operation& operation) = 0; + + /** + * Delegated method to create a new component implementation. + * Implemented by the subtype. + * @return A pointer to an instance of the component implementation class. + */ + virtual void* newImplementation() = 0; + + /** + * Delegated method to delete the current instance of the component + * implementation. + * Implemented by the subtype. + */ + virtual void deleteImplementation() = 0; + + /** + * Return the current instance of the component implementation. + * @return A pointer to an instance of the component implementation class. + */ + virtual void* getImplementation(); + + /** + * Indicates that the current instance of the component implementation + * has been finished with. + * Will call CPPServiceWrapper#deleteImplementation if the + * implementation is stateless (so that a new instance is returned + * for each call). + */ + virtual void releaseImplementation(); + + private: + /** + * Holds an implementation instance if the scope is set to composite. + */ + static void* staticImpl; + + /** + * The component to which this wrapper refers. + */ + Component* component; + + /** + * A pointer to the interface which the service exposes. + */ + Interface* interf; + + /** + * The component implementation + */ + CPPImplementation* implementation; + + /** + * Pointer to the loaded library which contains the component + * implementation. + */ + Library* wrapperLibrary; + + /** + * Set the loaded library which contains the component + * implementation. + * @param lib The library. + */ + void setLibrary(Library* lib); + }; + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_cppservicewrapper_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/ComponentContextImpl.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/ComponentContextImpl.cpp new file mode 100644 index 0000000000..76d6bbc5f6 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/ComponentContextImpl.cpp @@ -0,0 +1,163 @@ +/* + * 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 "osoa/sca/ServiceRuntimeException.h" +#include "tuscany/sca/cpp/ComponentContextImpl.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/ReferenceBinding.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/model/ServiceBinding.h" + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + // =========== + // Constructor + // =========== + ComponentContextImpl::ComponentContextImpl(Component* comp) + : ComponentContext(0), component(comp) + { + LOGENTRY(1, "ComponentContextImpl::constructor"); + LOGEXIT(1, "ComponentContextImpl::constructor"); + } + + // ========== + // Destructor + // ========== + ComponentContextImpl::~ComponentContextImpl() + { + } + + + // ========================================================================== + // getServices: return a list of Proxies for services wired to this reference + // ========================================================================== + std::list<void*> ComponentContextImpl::getServices(const std::string& referenceName) + { + LOGENTRY(1, "ComponentContextImpl::getServices"); + + // -------------------------------------------------------------- + // locate reference in the current component and determine target + // -------------------------------------------------------------- + Reference* reference = component->findReference(referenceName); + if (!reference) + { + string message = "Reference not defined: "; + message = message + referenceName; + throw ServiceNotFoundException(message.c_str()); + } + + // Get a service proxy from the binding configured on the reference + CPPServiceProxy* serviceProxy = (CPPServiceProxy*)reference->getBinding()->getServiceProxy(); + if (serviceProxy == NULL) + { + string message = "Reference "; + message = message + referenceName + " not wired"; + throw ServiceNotFoundException(message.c_str()); + } + + return serviceProxy->getProxies(); + + } // End getServices() + + + // =================================================================== + // getService: return a Proxy for the services wired to this reference + // =================================================================== + void* ComponentContextImpl::getService(const std::string& referenceName) + { + LOGENTRY(1, "ComponentContextImpl::getService"); + + // -------------------------------------------------------------- + // locate reference in the current component and determine target + // -------------------------------------------------------------- + Reference* reference = component->findReference(referenceName); + if (!reference) + { + string message = "Reference not defined: "; + message = message + referenceName; + throw ServiceNotFoundException(message.c_str()); + } + + // -------------------- + // Validate the request + // -------------------- + switch (reference->getType()->getMultiplicity()) + { + case ReferenceType::ZERO_MANY: + case ReferenceType::ONE_MANY: + { + string message = "getService() called for reference with multiplicity >1 :"; + message = message + referenceName; + throw ServiceNotFoundException(message.c_str()); + } + default: + { + } + } // end switch + + // Get a service proxy from the binding configured on the reference + CPPServiceProxy* serviceProxy = (CPPServiceProxy*)reference->getBinding()->getServiceProxy(); + if (serviceProxy == NULL) + { + string message = "Reference "; + message = message + referenceName + " not wired"; + throw ServiceNotFoundException(message.c_str()); + } + + void* service = serviceProxy->getProxy(); + return service; + + } // End getService() + + // ============================================== + // getProperties: return the component properties + // ============================================== + DataObjectPtr ComponentContextImpl::getProperties() + { + LOGENTRY(1, "ComponentContextImpl::getProperties"); + DataObjectPtr properties = component->getProperties(); + + LOGEXIT(1, "ComponentContextImpl::getProperties"); + return properties; + } + + // ============================================== + // getDataFactory: return the data factory for the composite in which + // this component resides + // ============================================== + commonj::sdo::DataFactoryPtr ComponentContextImpl::getDataFactory() + { + LOGENTRY(1, "ComponentContextImpl::getProperties"); + commonj::sdo::DataFactoryPtr dataFactory = component->getComposite()->getDataFactory(); + + LOGEXIT(1, "ComponentContextImpl::getDataFactory"); + return dataFactory; + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/ComponentContextImpl.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/ComponentContextImpl.h new file mode 100644 index 0000000000..6d9b76feeb --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/ComponentContextImpl.h @@ -0,0 +1,123 @@ +/* + * 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_cpp_componentcontextimpl_h +#define tuscany_sca_cpp_componentcontextimpl_h + +#include <vector> +using std::vector; + +#include "osoa/sca/ComponentContext.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/cpp/CPPServiceProxy.h" + +using namespace osoa::sca; + + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + /** + * Contains the actual implementation of a ComponentContext interface. + */ + class ComponentContextImpl : public ComponentContext + { + + public: + /** + * Constructor that takes a Component which represents the runtime + * model for this context. + */ + ComponentContextImpl(Component* component); + + /** + * Default constructor. + */ + virtual ~ComponentContextImpl(); + + /** + * See ComponentContext. + */ + virtual void* getService(const std::string& referenceName); + + /** + * See ComponentContext. + */ + virtual std::list<void*> getServices(const std::string& referenceName); + + /** + * See ComponentContext. + */ + virtual DataObjectPtr getProperties(); + + /** + * See ComponentContext. + */ + virtual commonj::sdo::DataFactoryPtr getDataFactory(); + + /** + * Returns the contained Component. + * @return The Component to which this context refers. + */ + virtual Component* getComponent() {return component;} + + private: + ComponentContextImpl(const ComponentContextImpl&); + ComponentContextImpl& operator=(const ComponentContextImpl&); + + /** + * Pointer to the runtime model Component to which this + * context refers. + */ + Component* component; + + /** + * Helper method to return a proxy to a service. + * @param serviceReference The source reference. + * @param target The target to which this source reference is wired. + * @return A pointer to an object which can be cast to the business + * class representing the target. + */ + void* getServiceProxy( + Reference* serviceReference, + Service* target); + + /** + * Helper method to return a wrapper for a target service. + * @param target The target for which this wrapper is to be created. + * @return The service wrapper. + */ + ServiceWrapper* getServiceWrapper(Service* target); + + }; + + } // End namespaca cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_componentcontextimpl_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CompositeContextImpl.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CompositeContextImpl.cpp new file mode 100644 index 0000000000..009e0ed765 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CompositeContextImpl.cpp @@ -0,0 +1,106 @@ +/* + * 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 "osoa/sca/ServiceRuntimeException.h" +#include "tuscany/sca/cpp/CompositeContextImpl.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/ServiceBinding.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/core/ServiceProxy.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/cpp/CPPServiceProxy.h" +#include "commonj/sdo/SDO.h" + +using namespace tuscany::sca::model; +using namespace osoa::sca; +using namespace commonj::sdo; + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + // =========== + // Constructor + // =========== + CompositeContextImpl::CompositeContextImpl(Component* component) + : CompositeContext(0), component(component), composite((Composite*)component->getType()) + { + } + + // ========== + // Destructor + // ========== + CompositeContextImpl::~CompositeContextImpl() + { + } + + // =========================================================================== + // locateService: return a proxy connected to a wrapper for the target service + // =========================================================================== + void* CompositeContextImpl::locateService(const std::string& serviceName) + { + LOGENTRY(1, "CompositeContextImpl::locateService"); + + // ---------------------------- + // Locate the component service + // ---------------------------- + Service* service = composite->findComponentService(serviceName); + string msg; + if (!service) + { + msg = "Service not found: "; + msg = msg + serviceName; + throw ServiceNotFoundException(msg.c_str()); + } + + // ---------------------------- + // Get a Proxy for this service + // ---------------------------- + + // The locate service API is used from CPP clients so we are using + // our default service proxy here + CPPServiceProxy* serviceProxy = new CPPServiceProxy(service); + LOGEXIT(1, "CompositeContextImpl::locateService"); + return serviceProxy->getProxy(); + + } + + // ============================================== + // getDataFactory: return the data factory for the current composite + // ============================================== + DataFactoryPtr CompositeContextImpl::getDataFactory() + { + LOGENTRY(1, "CompositeContextImpl::getDataFactory"); + DataFactoryPtr dataFactory = composite->getDataFactory(); + + LOGEXIT(1, "CompositeContextImpl::getDataFactory"); + return dataFactory; + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CompositeContextImpl.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CompositeContextImpl.h new file mode 100644 index 0000000000..c11af16848 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/CompositeContextImpl.h @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_cpp_compositecontextimpl_h +#define tuscany_sca_cpp_compositecontextimpl_h + +#include <vector> +using std::vector; + +#include "osoa/sca/CompositeContext.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/cpp/CPPServiceProxy.h" + +using namespace osoa::sca; + +namespace tuscany +{ + namespace sca + { + + namespace cpp + { + + /** + * Contains the actual implementation of a CompositeContext interface. + */ + class CompositeContextImpl : public CompositeContext + { + + public: + /** + * Constructor that takes a Composite which represents the runtime + * model for this context. + */ + CompositeContextImpl(Component* component); + + /** + * See CompositeContext#locateService. + */ + virtual void* locateService(const std::string& serviceName); + + /** + * See CompositeContext. + */ + virtual commonj::sdo::DataFactoryPtr getDataFactory(); + + /** + * Destructor. + */ + virtual ~CompositeContextImpl(); + + private: + CompositeContextImpl(const CompositeContextImpl&); + CompositeContextImpl& operator=(const CompositeContextImpl&); + + /** + * Pointer to the runtime model Composite object to which this + * context refers. + */ + Composite* composite; + + /** + * Pointer to the runtime model Component object to which this + * context refers. + */ + Component* component; + + }; + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_compositecontextimpl_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.cpp new file mode 100644 index 0000000000..4fb7c7cfd5 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.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/cpp/model/CPPImplementation.h" +#include "tuscany/sca/cpp/model/CPPServiceBinding.h" +#include "tuscany/sca/cpp/model/CPPReferenceBinding.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 "tuscany/sca/util/Utils.h" + +namespace tuscany +{ + namespace sca + { + + namespace cpp + { + + // Constructor + CPPImplementation::CPPImplementation(Composite* composite, const string& library, const string& header, + const string&headerPath, const string& headerStub, const string& className, Scope scope) + : ComponentType(composite, headerPath + headerStub), + library(library), header(header), headerPath(headerPath), + headerStub(headerStub), className(className), scope(scope) + { + } + + CPPImplementation::~CPPImplementation() + { + } + + void CPPImplementation::initializeComponent(Component* component) + { + ComponentType::initializeComponent(component); + + // Create CPP bindings for all the services + const Component::SERVICE_MAP& services = component->getServices(); + Component::SERVICE_MAP::const_iterator iter = services.begin(); + for (int i=0; i< services.size(); i++) + { + Service *service = iter->second; + CPPServiceBinding* binding = new CPPServiceBinding(service); + service->setBinding(binding); + iter++; + } + + // Create CPP bindings for all the references + const Component::REFERENCE_MAP& references = component->getReferences(); + Component::REFERENCE_MAP::const_iterator refiter = references.begin(); + for (int ri=0; ri< references.size(); ri++) + { + Reference *reference = refiter->second; + CPPReferenceBinding* binding = new CPPReferenceBinding(reference); + reference->setBinding(binding); + refiter++; + } + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.h new file mode 100644 index 0000000000..20636df884 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.h @@ -0,0 +1,150 @@ +/* + * 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_cpp_model_cppimplementation_h +#define tuscany_sca_cpp_model_cppimplementation_h +#include "tuscany/sca/model/ComponentType.h" + +#include <map> +using std::map; +#include <string> +using std::string; + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + /** + * Holds information about an SCA implementation written in C++ + */ + class CPPImplementation : public ComponentType + { + + public: + /** + * Scope of the component implementation. + */ + enum Scope + { + COMPOSITE, + STATELESS + }; + + /** + * Constructor. + * @param dllName Name of the shared library. + * @param header Name of the header file that contains the class declaring the + * implementation class. + * @param className Name of the class in the header file (could be a blank string + * if this is not specified). + */ + CPPImplementation(Composite* composite, const string& library, const string& header, const string&headerPath, + const string& headerStub, const string& className, Scope scope); + + /** + * Destructor + */ + virtual ~CPPImplementation(); + + /** + * Initialize a component of this type. + * @param component The component to initialize. + */ + virtual void initializeComponent(Component* component); + + /** + * Returns the name of the shared library. + * @return The name of the shared library. + */ + const string& getLibrary() const { return library; } + + /** + * Get the name of the header file. + * @return Name of the header file. + */ + const string& getHeader() const { return header; } + + /** + * Get the header file name without the extension. + * @return The name of the header file without any extension. + */ + const string& getHeaderStub() const { return headerStub; } + + /** + * Get the header path. + * @return The pathe element of the header. + */ + const string& getHeaderPath() const { return headerPath; } + + /** + * Get the name of the class. + * @return The class name if specified. + */ + const string& getClass() const { return className; } + + /** + * Returns the implementation scope + */ + Scope getScope() { return scope; } + + private: + + /** + * Name of the shared library. + */ + string library; + + /** + * Name of the header file describing the interface. + */ + string header; + + /** + * Name of the header file without the extension. + */ + string headerStub; + + /** + * Path element of the header. + */ + string headerPath; + + /** + * Name of the class in the header file declaring the implementation. + * May be an empty string if not set in the SCDL file. + */ + string className; + + /** + * Scope of the implementation + */ + Scope scope; + }; + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_model_cppimplementation_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPInterface.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPInterface.cpp new file mode 100644 index 0000000000..a728880e32 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPInterface.cpp @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/cpp/model/CPPInterface.h" + + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + const string CPPInterface::typeQName("http://www.osoa.org/xmlns/sca/1.0#CPPInterface"); + + // Constructor + CPPInterface::CPPInterface( + const string& header, + const string& className, + bool remotable, + bool conversational) + : Interface(remotable, conversational), header(header), className(className) + { + string::size_type dot = header.rfind(".h"); // this will also find .hpp + if (dot != string::npos) + { + headerStub = header.substr(0, dot); + } + else + { + headerStub = header; + } + + } + + CPPInterface::~CPPInterface() + { + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPInterface.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPInterface.h new file mode 100644 index 0000000000..d50d2f9485 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPInterface.h @@ -0,0 +1,121 @@ +/* + * 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_cpp_model_cppinterface_h +#define tuscany_sca_cpp_model_cppinterface_h + +#include "tuscany/sca/model/Interface.h" + +#include <map> +using std::map; +#include <string> +using std::string; + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + /** + * Holds information about an interface described using a C++ + * header file. + */ + class CPPInterface : public Interface + { + + public: + /** + * Constuctor. + * @param header Name of the header file containing the class that + * describes the interface. + * @param className Name of the class in the header file that + * describes the interface. + * @param scope The scope of the interface (stateless or composite). + * @param remotable True if the interface is remotable. + */ + CPPInterface( + const string& header, + const string& className, + bool remotable, + bool conversational); + + /** + * Destructor. + */ + virtual ~CPPInterface(); + + /** + * Get the name of the header file. + * @return The name of the header file containing the definition of the + * interface. + */ + const string& getHeader() { return header; } + + /** + * Return the name of the header file without the extension. + * @return Header file name without any extension. + */ + const string& getHeaderStub() { return headerStub; } + + /** + * Get the name of the class. + * @return The name of the class defining the interface. + */ + const string& getClass() { return className; } + + /** + * 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; }; + + private: + + /** + * Name of the header file containing the definition of the interface. + */ + string header; + + /** + * Name of the header file without the extension. + */ + string headerStub; + + /** + * Name of the class in the header file. + */ + string className; + + /** + * The QName of the schema type for this interface type. + */ + static const string typeQName; + }; + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_model_cppinterface_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.cpp new file mode 100644 index 0000000000..3c87560445 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.cpp @@ -0,0 +1,59 @@ +/* + * 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/cpp/model/CPPReferenceBinding.h" +#include "tuscany/sca/cpp/CPPServiceProxy.h" + + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + // Constructor + CPPReferenceBinding::CPPReferenceBinding(Reference* reference) + : ReferenceBinding(reference, ""), serviceProxy(NULL), targetServiceBinding(NULL) + { + } + + // Destructor + CPPReferenceBinding::~CPPReferenceBinding() + { + } + + ServiceProxy* CPPReferenceBinding::getServiceProxy() + { + return serviceProxy; + } + + void CPPReferenceBinding::configure(ServiceBinding* binding) + { + targetServiceBinding = binding; + + serviceProxy = new CPPServiceProxy(getReference()); + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.h new file mode 100644 index 0000000000..81ba88940d --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.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_cpp_model_cppreferencebinding_h +#define tuscany_sca_cpp_model_cppreferencebinding_h + +#include "tuscany/sca/model/ReferenceBinding.h" + + +#include <string> +using std::string; + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + /** + * Information about a CPP service binding for service or a reference. + */ + class CPPReferenceBinding : public ReferenceBinding + { + public: + + /** + * Constructor. + * @param uri The uri of the binding. + * @param port The definition of the port to which the entrypoint + * or external service is to be bound. This is of the form + * "namespace"#endpoint("service"/"port") + */ + CPPReferenceBinding(Reference* reference); + + /** + * Destructor. + */ + virtual ~CPPReferenceBinding(); + + /** + * Returns the type of binding. + */ + virtual string getType() { return "http://www.osoa.org/xmlns/sca/1.0#CPPImplementationBinding"; }; + + /** + * Create a proxy representing the reference to the + * client component. + */ + virtual ServiceProxy* getServiceProxy(); + + /** + * Configure this binding from a service binding. + */ + virtual void configure(ServiceBinding* serviceBinding); + + /** + * Returns the target service binding. + */ + ServiceBinding* getTargetServiceBinding() const { return targetServiceBinding; }; + + private: + + /** + * The proxy representing the reference to the client + * component. + */ + ServiceProxy* serviceProxy; + + /** + * The service binding of the target + */ + ServiceBinding* targetServiceBinding; + }; + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_model_cppreferencebinding_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPServiceBinding.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPServiceBinding.cpp new file mode 100644 index 0000000000..641d9452f8 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPServiceBinding.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/util/Logging.h" +#include "tuscany/sca/cpp/model/CPPServiceBinding.h" +#include "tuscany/sca/cpp/CPPServiceWrapper.h" + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + // Constructor + CPPServiceBinding::CPPServiceBinding(Service* service) + : ServiceBinding(service, "") + { + serviceWrapper = CPPServiceWrapper::getServiceWrapper(service); + } + + // Destructor + CPPServiceBinding::~CPPServiceBinding() + { + } + + ServiceWrapper* CPPServiceBinding::getServiceWrapper() + { + return (ServiceWrapper*)serviceWrapper; + } + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPServiceBinding.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPServiceBinding.h new file mode 100644 index 0000000000..f7db3065b3 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPServiceBinding.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_cpp_model_cppservicebinding_h +#define tuscany_sca_cpp_model_cppservicebinding_h + +#include "tuscany/sca/model/ServiceBinding.h" +using namespace tuscany::sca::model; +#include <string> +using std::string; + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + /** + * Information about a CPP service binding for service or a reference. + */ + class CPPServiceBinding : public ServiceBinding + { + public: + + /** + * Constructor. + * @param uri The uri of the binding. + * @param port The definition of the port to which the entrypoint + * or external service is to be bound. This is of the form + * "namespace"#endpoint("service"/"port") + */ + CPPServiceBinding(Service* service); + + /** + * Destructor. + */ + virtual ~CPPServiceBinding(); + + /** + * Returns the type of binding. + */ + virtual string getType() { return "http://www.osoa.org/xmlns/sca/1.0#CPPImplementationBinding"; }; + + /** + * Create a wrapper for the service configured by this + * binding. + */ + virtual ServiceWrapper* getServiceWrapper(); + + private: + + /** + * The wrapper for the service configured by this binding. + */ + ServiceWrapper* serviceWrapper; + + }; + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_model_cppservicebinding_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/xsd/sca-implementation-cpp.xsd b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/xsd/sca-implementation-cpp.xsd new file mode 100644 index 0000000000..7292f747b8 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/xsd/sca-implementation-cpp.xsd @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.osoa.org/xmlns/sca/1.0" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + elementFormDefault="qualified"> + + <element name="implementation.cpp" type="sca:CPPImplementation" substitutionGroup="sca:implementation"/> + <complexType name="CPPImplementation"> + <complexContent> + <extension base="sca:Implementation"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> + </sequence> + <attribute name="library" type="NCName" use="required"/> + <attribute name="path" type="NCName" use="optional"/> + <attribute name="header" type="NCName" use="required"/> + <attribute name="class" type="Name" use="optional"/> + <attribute name="scope" type="sca:CPPImplementationScope" use="optional" /> + <anyAttribute namespace="##any" processContents="lax"/> + </extension> + </complexContent> + </complexType> + + <simpleType name="CPPImplementationScope"> + <restriction base="string"> + <enumeration value="stateless" /> + <enumeration value="composite" /> + </restriction> + </simpleType> +</schema> diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/xsd/sca-interface-cpp.xsd b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/xsd/sca-interface-cpp.xsd new file mode 100644 index 0000000000..585bac0dc4 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/cpp/xsd/sca-interface-cpp.xsd @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.osoa.org/xmlns/sca/1.0" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + elementFormDefault="qualified"> + + <element name="interface.cpp" type="sca:CPPInterface" substitutionGroup="sca:interface"/> + <complexType name="CPPInterface"> + <complexContent> + <extension base="sca:Interface"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> + </sequence> + <attribute name="header" type="NCName" use="required" /> + <attribute name="class" type="Name" use="optional" /> + <attribute name="callbackHeader" type="NCName" use="optional" /> + <attribute name="callbackClass" type="Name" use="optional" /> + <attribute name="remotable" type="boolean" use="optional" /> + <anyAttribute namespace="##any" processContents="lax" /> + </extension> + </complexContent> + </complexType> + +</schema> diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/Makefile.am new file mode 100644 index 0000000000..b8c2a91db2 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/Makefile.am @@ -0,0 +1,24 @@ +# 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 + +datadir=$(prefix)/extensions/php + +nobase_data_DATA = xsd/*.xsd + +EXTRA_DIST = xsd
\ No newline at end of file diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/Makefile.am new file mode 100644 index 0000000000..a8c2762484 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/Makefile.am @@ -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. + +libdir=$(prefix)/extensions/php/lib +lib_LTLIBRARIES = libtuscany_sca_php.la + +noinst_HEADERS = \ +tuscany/sca/php/*.h \ +tuscany/sca/php/model/*.h + +libtuscany_sca_php_la_SOURCES = \ +tuscany/sca/php/PHPExtension.cpp \ +tuscany/sca/php/PHPImplementationExtension.cpp \ +tuscany/sca/php/PHPServiceWrapper.cpp \ +tuscany/sca/php/model/PHPImplementation.cpp \ +tuscany/sca/php/model/PHPServiceBinding.cpp + +libtuscany_sca_php_la_LIBADD = -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo \ + -L$(top_builddir)/runtime/core/src -ltuscany_sca \ + -L${PHP_LIB} -lphp5 + +INCLUDES = -Imodel -I$(top_builddir)/runtime/core/src \ + -I${TUSCANY_SDOCPP}/include \ + -I${PHP_INCLUDE} \ + -I${PHP_INCLUDE}/main \ + -I${PHP_INCLUDE}/Zend \ + -I${PHP_INCLUDE}/TSRM \ + -I${PHP_INCLUDE}/sapi/embed + +AM_CPPFLAGS = $(CPPFLAGS) -D_DEBUG +
\ No newline at end of file diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/osoa/sca/ServiceRuntimeException.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/osoa/sca/ServiceRuntimeException.h new file mode 100644 index 0000000000..d31679b994 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/osoa/sca/ServiceRuntimeException.h @@ -0,0 +1,115 @@ +/* + * 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 osoa_sca_serviceruntimeexception_h +#define osoa_sca_serviceruntimeexception_h + +#include "osoa/sca/export.h" + +#include "tuscany/sca/util/Exceptions.h" +using tuscany::sca::TuscanyRuntimeException; +namespace osoa +{ + namespace sca + { + /** + * Top level exception to represent all the exceptions that may be + * thrown by an SCA runtime implementation. + */ + class SCA_PHP_API ServiceRuntimeException : public TuscanyRuntimeException + { + public: + ServiceRuntimeException( + const char *name="ServiceRuntimeException", + severity_level sev=Severe, + const char* msg_text="") + : TuscanyRuntimeException(name, sev, msg_text) + { + } + }; // End ServiceRuntimeException class definition + + + /** + * A remotable service is currently unavailable. It is possible that a retry + * may resolve this exception. + */ + class SCA_PHP_API ServiceUnavailableException: public ServiceRuntimeException + { + public: + ServiceUnavailableException(const char* serviceName) + : ServiceRuntimeException("ServiceUnavailableException", Warning, + serviceName) + { + } + private: + }; // End ServiceUnavailableException class definition + + + /** + * The target of a wire cannot be found, or the reference has not been + * configured. + */ + class SCA_PHP_API ServiceNotFoundException: public ServiceRuntimeException + { + public: + ServiceNotFoundException(const char* msg) + : ServiceRuntimeException("ServiceNotFoundException", Error, + msg) + { + } + private: + }; // End ServiceNotFoundException class definition + + + /** + * There is no current component (for example, if a non-SCA component + * tries to get the current ComponentContext). + */ + class SCA_PHP_API ComponentContextException: public ServiceRuntimeException + { + public: + ComponentContextException(const char* msg) + : ServiceRuntimeException("ComponentContextException", Error, + msg) + { + } + private: + }; // End ComponentContextException class definition + + /** + * There is an error whilst trying to invoke a component. + */ + class SCA_PHP_API ComponentInvocationException: public ServiceRuntimeException + { + public: + ComponentInvocationException(const char* msg) + : ServiceRuntimeException("ComponentInvocationException", Error, + msg) + { + } + private: + }; // End ComponentInvocationException class definition + + + } // End namespace sca +} // End namespace osoa + +#endif // osoa_sca_serviceruntimeexception_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/osoa/sca/export.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/osoa/sca/export.h new file mode 100644 index 0000000000..99794a3352 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/osoa/sca/export.h @@ -0,0 +1,42 @@ +/* + * 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 osoa_sca_export_h +#define osoa_sca_export_h +#include "tuscany/sca/export.h" + +#if defined(WIN32) || defined (_WINDOWS) +#pragma warning(disable: 4786) + +#ifdef TUSCANY_SCA_PHP_EXPORTS +#define SCA_PHP_API __declspec(dllexport) +#else +#define SCA_PHP_API __declspec(dllimport) +#endif + +#else +#include <sys/time.h> +#include <inttypes.h> +#include <stdlib.h> +#define SCA_PHP_API +#endif + +#endif // osoa_sca_export_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPExtension.cpp new file mode 100644 index 0000000000..f8768738e9 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPExtension.cpp @@ -0,0 +1,73 @@ +/* + * 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/php/PHPExtension.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/php/PHPImplementationExtension.h" + + +extern "C" +{ + #if defined(WIN32) || defined(_WINDOWS) + __declspec(dllexport) + #endif + void tuscany_sca_extension_initialize() + { + tuscany::sca::php::PHPExtension::initialize(); + } +} + +namespace tuscany +{ + namespace sca + { + namespace php + { + // =================================================================== + // Constructor for the PHPExtension class. + // =================================================================== + PHPExtension::PHPExtension() + { + LOGENTRY(1, "PHPExtension::constructor"); + LOGEXIT(1, "PHPExtension::constructor"); + } + + // =================================================================== + // Destructor for the PHPExtension class. + // =================================================================== + PHPExtension::~PHPExtension() + { + LOGENTRY(1, "PHPExtension::destructor");; + LOGEXIT(1, "PHPExtension::destructor"); + } + + void PHPExtension::initialize() + { + LOGENTRY(1, "PHPExtension::initialize");; + SCARuntime::getInstance()->registerImplementationExtension(new PHPImplementationExtension()); + //SCARuntime::getInstance()->registerInterfaceExtension(new PHPInterfaceExtension()); + LOGEXIT(1, "PHPExtension::initialize");; + } + + } // End namespace php + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPExtension.h new file mode 100644 index 0000000000..971ed93c86 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPExtension.h @@ -0,0 +1,57 @@ +/* + * 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_php_phpextension_h +#define tuscany_sca_php_phpextension_h + +namespace tuscany +{ + namespace sca + { + namespace php + { + + class PHPExtension + { + public: + /** + * Default constructor + */ + PHPExtension(); + + /** + * Destructor + */ + virtual ~PHPExtension(); + + static void initialize(); + + private: + + }; + + + } // End namespace php + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_php_phpextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPImplementationExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPImplementationExtension.cpp new file mode 100644 index 0000000000..7f204b0ce9 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPImplementationExtension.cpp @@ -0,0 +1,78 @@ +/* + * 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/php/PHPImplementationExtension.h" +#include "tuscany/sca/php/model/PHPImplementation.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" + + +namespace tuscany +{ + namespace sca + { + namespace php + { + // =================================================================== + // Constructor for the PHPImplementationExtension class. + // =================================================================== + PHPImplementationExtension::PHPImplementationExtension() + { + LOGENTRY(1, "PHPImplementationExtension::constructor"); + LOGEXIT(1, "PHPImplementationExtension::constructor"); + } + + // =================================================================== + // Destructor for the PHPImplementationExtension class. + // =================================================================== + PHPImplementationExtension::~PHPImplementationExtension() + { + LOGENTRY(1, "PHPImplementationExtension::destructor");; + LOGEXIT(1, "PHPImplementationExtension::destructor"); + } + + const string PHPImplementationExtension::extensionName("php"); + const string PHPImplementationExtension::typeQName("http://www.osoa.org/xmlns/sca/1.0#PHPImplementation"); + + // =================================================================== + // loadModelElement - load the info from implementation.php + // =================================================================== + ComponentType* PHPImplementationExtension::getImplementation(Composite *composite, DataObjectPtr scdlImplementation) + { + string implType = scdlImplementation->getType().getName(); + if (implType == "PHPImplementation") + { + string module = scdlImplementation->getCString("module"); + string className = scdlImplementation->getCString("class"); + + PHPImplementation* phpImpl = new PHPImplementation(composite, module, className); + + return phpImpl; + } + else + { + return NULL; + } + } + + } // End namespace php + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPImplementationExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPImplementationExtension.h new file mode 100644 index 0000000000..9aa4aea969 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPImplementationExtension.h @@ -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$ */ + +#ifndef tuscany_sca_php_phpimplementationextension_h +#define tuscany_sca_php_phpimplementationextension_h + +#include "tuscany/sca/extension/ImplementationExtension.h" + +namespace tuscany +{ + namespace sca + { + namespace php + { + + class PHPImplementationExtension : public ImplementationExtension + { + public: + /** + * Default constructor + */ + PHPImplementationExtension(); + + /** + * Destructor + */ + virtual ~PHPImplementationExtension(); + + /** + * return the name of the extension + */ + virtual const string& getExtensionName() {return extensionName;} + + /** + * return the QName of schema element for this implementation extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#implementation.phpn") + */ + virtual const string& getExtensionTypeQName() {return typeQName;} + + virtual ComponentType* getImplementation(Composite* composite, DataObjectPtr scdlImplementation); + + private: + static const string extensionName; + static const string typeQName; + + }; + + + } // End namespace php + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_php_phpimplementationextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPServiceWrapper.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPServiceWrapper.cpp new file mode 100644 index 0000000000..1b11e660c6 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPServiceWrapper.cpp @@ -0,0 +1,405 @@ +/* + * 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$ */ + + +// some strangeness in the build that causes +// WinSock.h and WinSock2.h to be included leading to redefinitions +#define _WINSOCKAPI_ + +#include "tuscany/sca/php/PHPServiceWrapper.h" + +#include "osoa/sca/ServiceRuntimeException.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/Interface.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/php/model/PHPImplementation.h" + +#include <php_embed.h> + +using namespace osoa::sca; + +namespace tuscany +{ + namespace sca + { + namespace php + { + // a global!! place to put the response + // as I can't get the PHP return value + // processing to work. Need to be + // removed when the proper PHP SAPI is used + // The variable is only valid between the PHP engine call and + // the results processing. It stores the last thing that + // the script echoed + string scriptResponse; + + // Global callbacks used by the PHP engine + + // Callback for log messages + void php_log_message(char *message) + { + LOGINFO_1(5, "PHP Log (%s)", message); + } + + // Callback for unbuffered writes (echo, print etc.) + int php_ub_write(const char *str, unsigned int str_length TSRMLS_DC) + { + LOGINFO_1(5, "PHP Write (%s)", str); + scriptResponse = str; + return str_length; + } + + // Callback for errors + void php_error_cb(int type, + const char *error_filename, + const uint error_lineno, + const char *format, va_list args) + { + char buffer[2048]; + int len; + + len = snprintf(buffer, 2048, "Error on line %d: ", error_lineno); + vsnprintf(buffer + len, (2048 - len), format, args); + LOGINFO_1(5, "PHP Unformatted Error (%s)", buffer); + zend_bailout(); + } + + // Callback for flush (could be used to do something with the scriptResponse) + void php_flush(void *server_context) + { + LOGINFO(5, "Flush"); + } + + // =========== + // Constructor + // =========== + PHPServiceWrapper::PHPServiceWrapper(Service* service) + : ServiceWrapper(service) + { + LOGENTRY(1,"PHPServiceWrapper::constructor"); + + component = service->getComponent(); + interf = service->getType()->getInterface(); + remotable = interf->isRemotable(); + + // ----------------------------------------------- + // Get the implementation for the target component + // ----------------------------------------------- + PHPImplementation* impl = (PHPImplementation*)component->getType(); + if (!impl) + { + string msg = "Component " + component->getName() + " has no implementation defined"; + throw ServiceNotFoundException(msg.c_str()); + } + + LOGINFO_1(3,"PHPServiceWrapper::getServiceWrapper module %s", impl->getModule().c_str()); + LOGINFO_1(3,"PHPServiceWrapper::getServiceWrapper class %s", impl->getClass().c_str()); + + LOGEXIT(1,"PHPServiceWrapper::constructor"); + + } + + // ========== + // Destructor + // ========== + PHPServiceWrapper::~PHPServiceWrapper() + { + LOGENTRY(1,"PHPServiceWrapper::destructor"); + LOGEXIT(1,"PHPServiceWrapper::destructor"); + } + + + // ====================================================================== + // invoke: wrapper call to service with setting the component context + // ====================================================================== + void PHPServiceWrapper::invoke(Operation& operation) + { + LOGENTRY(1,"PHPServiceWrapper::invoke"); + + SCARuntime* runtime = SCARuntime::getInstance(); + runtime->setCurrentComponent(component); + + try + { + LOGINFO_1(4, "PHPServiceWrapper::invoke called with operation name: %s", operation.getName().c_str()); + + // create a temporary script which + // - includes the named script + // - creates a class instance if required + // - calls the named method with the provided arguments + + // get the component type information + PHPImplementation* impl = (PHPImplementation*)component->getType(); + + // first create the temporay script and include the module + string script = "include '" + impl->getModule() + ".php';"; + + // if we have a class create an instance + string className = impl->getClass(); + if( &className != NULL && className.size() > 0) + { + script += "$anobject = new " + className + "();"; + } + + // construct the call to the function + script += "$response = "; + + if( &className != NULL && className.size() > 0) + { + script += " $anobject->"; + } + + script += operation.getName().c_str(); + script += "("; + + char tempString [32]; + + // add the parameters to the call + for(unsigned int i = 0; i < operation.getNParms(); i++) + { + const Operation::Parameter& parm = operation.getParameter(i); + switch(parm.getType()) + { + case Operation::BOOL: + { + if( *(bool*)parm.getValue()) + { + //boolean true + script += "true"; + } + else + { + script += "false"; + } + break; + } + case Operation::SHORT: + { + sprintf ( tempString, "%d", *(short*)parm.getValue() ); + script += tempString; + break; + } + case Operation::USHORT: + { + sprintf ( tempString, "%d", *(unsigned short*)parm.getValue() ); + script += tempString; + break; + } + case Operation::LONG: + { + sprintf ( tempString, "%d", *(long*)parm.getValue() ); + script += tempString; + break; + } + case Operation::ULONG: + { + sprintf ( tempString, "%d", *(unsigned long*)parm.getValue() ); + script += tempString; + break; + } + case Operation::FLOAT: + { + sprintf ( tempString, "%g", *(float*)parm.getValue() ); + script += tempString; + break; + } + case Operation::DOUBLE: + { + sprintf ( tempString, "%g", *(double*)parm.getValue() ); + script += tempString; + break; + } + case Operation::LONGDOUBLE: + { + sprintf ( tempString, "%g", *(long double*)parm.getValue() ); + script += tempString; + break; + } + case Operation::CHARS: + { + script += *(char**)parm.getValue(); + break; + } + case Operation::STRING: + { + script += (*(string*)parm.getValue()).c_str(); + break; + } + default: + { + throw new ComponentInvocationException("Operation parameter type not supported"); + } + } + + if ( ( i + 1 ) < operation.getNParms() ) + { + script += ", "; + } + } + + + // the closing bracket of the call + script += ");echo $response;return $response;"; + + // we now have the temporary script to make the call + LOGINFO_1(5, "Executing PHP script \n%s", script.c_str()); + + // load the PHP logging and error callback methods + php_embed_module.log_message = php_log_message; + php_embed_module.ub_write = php_ub_write; + php_embed_module.flush = php_flush; + + //PHP_EMBED_START_BLOCK(/* argc */ 0, /* argv */ NULL) + void ***tsrm_ls; + int status = php_embed_init(0, NULL PTSRMLS_CC); + LOGINFO_1(5, "Engine startup status %d", status); + + zend_first_try { + // set error handler + zend_error_cb = php_error_cb; + + // call the dynamically created script + //zval retval; + zend_eval_string((char *) script.c_str(), + NULL,//&retval, + "PHP Component" TSRMLS_CC); + + // get the response + // This doesn't want to work for some reason + // so have chaced the last echo that the script + // returns in the global scriptResponse variable + // This is a bit of a rubbish way of doing things so + // needs replacing when proper SAPI is used + //convert_to_string(&retval); + //LOGINFO_1(5, "Script returned %s", Z_STRVAL(retval)); + //zval_dtor(&retval); + + //PHP_EMBED_END_BLOCK() + } zend_catch { + int exit_status = EG(exit_status); + LOGINFO_1(5, "In catch %d", exit_status); + } zend_end_try(); + + //clean up + php_embed_shutdown(TSRMLS_C); + LOGINFO(5, "Engine shutdown"); + + // get the response values + LOGINFO_1(5, "Script returned %s", scriptResponse.c_str()); + + switch(operation.getReturnType()) + { + case Operation::BOOL: + { + if(scriptResponse == "true") + { + *(bool*)operation.getReturnValue() = true; + } + break; + } + case Operation::SHORT: + { + *(short*)operation.getReturnValue() = (short) strtol(scriptResponse.c_str(), NULL,10); + break; + } + case Operation::LONG: + { + *(long*)operation.getReturnValue() = (long) strtol(scriptResponse.c_str(), NULL,10); + break; + } + case Operation::USHORT: + { + *(unsigned short*)operation.getReturnValue() = (unsigned short) strtoul(scriptResponse.c_str(), NULL,10); + break; + } + case Operation::ULONG: + { + *(unsigned long*)operation.getReturnValue() = (unsigned long) strtoul(scriptResponse.c_str(), NULL,10); + break; + } + case Operation::FLOAT: + { + *(float*)operation.getReturnValue() = (float) strtod(scriptResponse.c_str(), NULL); + break; + } + case Operation::DOUBLE: + { + *(double*)operation.getReturnValue() = (double) strtod(scriptResponse.c_str(), NULL); + break; + } + case Operation::LONGDOUBLE: + { + *(long double*)operation.getReturnValue() = (long double) strtod(scriptResponse.c_str(), NULL); + break; + } + case Operation::CHARS: + { + *(char**)operation.getReturnValue() = (char *)scriptResponse.c_str(); + break; + } + case Operation::STRING: + { + *(string*)operation.getReturnValue() = scriptResponse; + break; + } + default:; + } + } + catch (...) + { + runtime->unsetCurrentComponent(); + throw; + } + runtime->unsetCurrentComponent(); + LOGEXIT(1,"PHPServiceWrapper::invoke"); + + } + + // ====================================================================== + // getServiceWrapper: create a wrapper for the target ComponentService + // ====================================================================== + PHPServiceWrapper* PHPServiceWrapper::getServiceWrapper(Service* service) + { + LOGENTRY(1,"PHPServiceWrapper::getServiceWrapper"); + PHPServiceWrapper* serviceWrapper = 0; + + // --------------------------------- + // Create an instance of the wrapper + // --------------------------------- + serviceWrapper = new PHPServiceWrapper(service); + if (!serviceWrapper) + { + string msg = "Could not create new PHPServiceWrapper"; + LOGERROR(1, msg.c_str()); + throw ServiceNotFoundException(msg.c_str()); + } + + LOGEXIT(1,"PHPServiceWrapper::getServiceWrapper"); + return serviceWrapper; + } + + } // End namespace php + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPServiceWrapper.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPServiceWrapper.h new file mode 100644 index 0000000000..ef83a026a6 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/PHPServiceWrapper.h @@ -0,0 +1,110 @@ +/* + * 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_php_phpservicewrapper_h +#define tuscany_sca_php_phpservicewrapper_h + + +#include "osoa/sca/export.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/core/Operation.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Interface.h" + +using namespace tuscany::sca::model; + + +namespace tuscany +{ + namespace sca + { + namespace php + { + class PHPInterface; + + /** + * Wraps the service on a component implementation. + * This abstract class is extended by generated code which provides + * the implementation of some of the methods. + * An instance of this class wraps the actual component implementation which + * has been written by a developer of an SCA application. + */ + class SCA_PHP_API PHPServiceWrapper : public ServiceWrapper + { + public: + /** + * Factory method to create a new PHPServiceWrapper for a given target + * service. This method will provide all the loading of dlls required to + * create the target component. + * @param target The service on the component for which this wrapper is to be + * created. + * @return A wrapper that references the given target. + */ + static PHPServiceWrapper* getServiceWrapper(Service* service); + + /** + * Constructor. + * @param target The component service to which this wrapper refers. + */ + PHPServiceWrapper(Service* service); + + /** + * Destructor. + */ + virtual ~PHPServiceWrapper(); + + /** + * All business method calls to the target component go through the invoke method. + * @param operation The details of the method, paramaters and return value for the + * business method to be called on the target component. + */ + virtual void invoke(Operation& operation); + + + protected: + + + private: + + + /** + * The component to which this wrapper refers. + */ + Component* component; + + /** + * Set to true if the service is remotable. + */ + bool remotable; + + /** + * A pointer to the interface which the service exposes. + */ + Interface* interf; + + }; + + } // End namespace php + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_php_phpservicewrapper_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/model/PHPImplementation.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/model/PHPImplementation.cpp new file mode 100644 index 0000000000..f8992ed498 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/model/PHPImplementation.cpp @@ -0,0 +1,87 @@ +/* + * 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/php/model/PHPImplementation.h" +#include "tuscany/sca/php/model/PHPServiceBinding.h" +//#include "tuscany/sca/php/model/PHPReferenceBinding.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/util/Utils.h" + +namespace tuscany +{ + namespace sca + { + + namespace php + { + + // Constructor + PHPImplementation::PHPImplementation(Composite* composite, const string& module, const string& className) + : ComponentType(composite, module), + module(module), className(className) + { + LOGENTRY(1,"PHPImplementation::constructor"); + LOGEXIT(1,"PHPImplementation::constructor"); + } + + PHPImplementation::~PHPImplementation() + { + LOGENTRY(1,"PHPImplementation::destructor"); + LOGEXIT(1,"PHPImplementation::destructor"); + } + + void PHPImplementation::initializeComponent(Component* component) + { + LOGENTRY(1,"PHPImplementation::initializeComponent"); + ComponentType::initializeComponent(component); + + // Create PHP bindings for all the services + const Component::SERVICE_MAP& services = component->getServices(); + Component::SERVICE_MAP::const_iterator iter = services.begin(); + for (unsigned int i=0; i< services.size(); i++) + { + Service *service = iter->second; + PHPServiceBinding* binding = new PHPServiceBinding(service); + service->setBinding(binding); + iter++; + } + + // References not yet supported.. + + //// Create PHP bindings for all the references + //const Component::REFERENCE_MAP& references = component->getReferences(); + //Component::REFERENCE_MAP::const_iterator refiter = references.begin(); + //for (int ri=0; ri< references.size(); ri++) + //{ + // Reference *reference = refiter->second; + // PHPReferenceBinding* binding = new PHPReferenceBinding(reference); + // reference->setBinding(binding); + // refiter++; + //} + LOGEXIT(1,"PHPImplementation::initializeComponent"); + } + + } // End namespace php + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/model/PHPImplementation.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/model/PHPImplementation.h new file mode 100644 index 0000000000..b89ba8c5c2 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/model/PHPImplementation.h @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_php_model_phpimplementation_h +#define tuscany_sca_php_model_phpimplementation_h +#include "tuscany/sca/model/ComponentType.h" + +#include <map> +using std::map; +#include <string> +using std::string; + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace php + { + /** + * Holds information about an SCA implementation written in PHP + */ + class PHPImplementation : public ComponentType + { + + public: + /** + * Constructor. + * @param composite Composite containing this implementation. + * @param module Name of the module. + * @param modulePath Path to the module (could be a blank string + * if this is not specified). + * @param className Name of the class in the module (could be a blank string + * if this is not specified). + */ + PHPImplementation(Composite* composite, const string& module, const string& className); + + /** + * Destructor + */ + virtual ~PHPImplementation(); + + /** + * Initialize a component of this type. + * @param component The component to initialize. + */ + virtual void initializeComponent(Component* component); + + /** + * Returns the name of the module. + * @return The name of the module. + */ + const string& getModule() const { return module; } + + /** + * Get the name of the class. + * @return The class name if specified. + */ + const string& getClass() const { return className; } + + private: + + /** + * Name of the module. + */ + string module; + + /** + * Name of the class in the header file declaring the implementation. + * May be an empty string if not set in the SCDL file. + */ + string className; + }; + + } // End namespace php + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_php_model_phpimplementation_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/model/PHPServiceBinding.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/model/PHPServiceBinding.cpp new file mode 100644 index 0000000000..fa162ce8f2 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/model/PHPServiceBinding.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/php/model/PHPServiceBinding.h" +#include "tuscany/sca/php/PHPServiceWrapper.h" + +namespace tuscany +{ + namespace sca + { + namespace php + { + + // Constructor + PHPServiceBinding::PHPServiceBinding(Service* service) + : ServiceBinding(service, "") + { + LOGENTRY(1,"PHPServiceBinding::constructor"); + serviceWrapper = PHPServiceWrapper::getServiceWrapper(service); + LOGEXIT(1,"PHPServiceBinding::constructor"); + } + + // Destructor + PHPServiceBinding::~PHPServiceBinding() + { + LOGENTRY(1,"PHPServiceBinding::destructor"); + LOGEXIT(1,"PHPServiceBinding::destructor"); + } + + ServiceWrapper* PHPServiceBinding::getServiceWrapper() + { + LOGENTRY(1,"PHPServiceBinding::getServiceWrapper"); + LOGEXIT(1,"PHPServiceBinding::getServiceWrapper"); + return (ServiceWrapper*)serviceWrapper; + } + + } // End namespace php + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/model/PHPServiceBinding.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/model/PHPServiceBinding.h new file mode 100644 index 0000000000..6b1e694bd6 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/src/tuscany/sca/php/model/PHPServiceBinding.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_php_model_phpservicebinding_h +#define tuscany_sca_php_model_phpservicebinding_h + +#include "tuscany/sca/model/ServiceBinding.h" +using namespace tuscany::sca::model; +#include <string> +using std::string; + +namespace tuscany +{ + namespace sca + { + namespace php + { + /** + * Information about a PHP service binding for service or a reference. + */ + class PHPServiceBinding : public ServiceBinding + { + public: + + /** + * Constructor. + * @param uri The uri of the binding. + * @param port The definition of the port to which the entrypoint + * or external service is to be bound. This is of the form + * "namespace"#endpoint("service"/"port") + */ + PHPServiceBinding(Service* service); + + /** + * Destructor. + */ + virtual ~PHPServiceBinding(); + + /** + * Returns the type of binding. + */ + virtual string getType() { return "http://www.osoa.org/xmlns/sca/1.0#PHPImplementationBinding"; }; + + /** + * Create a wrapper for the service configured by this + * binding. + */ + virtual ServiceWrapper* getServiceWrapper(); + + private: + + /** + * The wrapper for the service configured by this binding. + */ + ServiceWrapper* serviceWrapper; + + }; + + } // End namespace php + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_php_model_phpservicebinding_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/xsd/sca-implementation-php.xsd b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/xsd/sca-implementation-php.xsd new file mode 100644 index 0000000000..0f32f120e6 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/php/xsd/sca-implementation-php.xsd @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.osoa.org/xmlns/sca/1.0" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + elementFormDefault="qualified"> + + <element name="implementation.php" type="sca:PHPImplementation" substitutionGroup="sca:implementation"/> + <complexType name="PHPImplementation"> + <complexContent> + <extension base="sca:Implementation"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> + </sequence> + <attribute name="module" type="NCName" use="required"/> + <attribute name="class" type="Name" use="optional"/> + <anyAttribute namespace="##any" processContents="lax"/> + </extension> + </complexContent> + </complexType> +</schema> diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/Makefile.am new file mode 100644 index 0000000000..83e70b4b94 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/Makefile.am @@ -0,0 +1,24 @@ +# 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 + +datadir=$(prefix)/extensions/python + +nobase_data_DATA = xsd/*.xsd + +EXTRA_DIST = xsd
\ No newline at end of file diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/deploy.bat b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/deploy.bat new file mode 100644 index 0000000000..94d4186eb5 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/deploy.bat @@ -0,0 +1,77 @@ +@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 extdir=%deploydir%\extensions +set pythonextdir=%extdir%\python +set srcdir=%rootdir%\runtime\extensions\python\src + +if . == .%2 ( +echo input directory not specified +goto usage +) +set inpath=%2 +echo %inpath% + + +if not exist %deploydir% mkdir %deploydir% +if not exist %extdir% mkdir %extdir% +if not exist %pythonextdir% mkdir %pythonextdir% +if not exist %pythonextdir%\bin mkdir %pythonextdir%\bin +if not exist %pythonextdir%\lib mkdir %pythonextdir%\lib +if not exist %pythonextdir%\xsd mkdir %pythonextdir%\xsd + +del %pythonextdir%\bin\tuscany_sca_python.* +del %pythonextdir%\lib\*.lib + +copy %srcdir%\deploy.cmd %pythonextdir% +copy %srcdir%\..\xsd\*.* %pythonextdir%\xsd + +copy %inpath%\tuscany_sca_python.lib %pythonextdir%\lib +copy %inpath%\tuscany_sca_python.dll %pythonextdir%\bin\tuscany_sca_python.dll.disabled + +if exist %inpath%\tuscany_sca_python.pdb copy %inpath%\tuscany_sca_python.pdb %pythonextdir%\bin + + +echo Building extension to Python +set origdir=%~d0%~p0 +set bindir=%pythonextdir%\bin +cd %srcdir%\tuscany\sca\python\ + +rem if %pythonextdir% is a relative path, it won't be found, so set %bindir% to a full path +if not exist %bindir% set bindir=%origdir%\%pythonextdir%\bin + +%PYTHON_HOME%\python sca_setup.py build +%PYTHON_HOME%\python sca_setup.py install --install-lib %bindir% +cd %origdir% + +goto end +:usage +echo Usage: deploy <sca-root> <build-output> +:end + +endlocal diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/Makefile.am new file mode 100644 index 0000000000..0f221aca05 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/Makefile.am @@ -0,0 +1,62 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +libdir=$(prefix)/extensions/python/lib +lib_LTLIBRARIES = libtuscany_sca_python.la + +install-exec-hook: + cd $(libdir); \ + ln -s -f libtuscany_sca_python.so sca.so; \ + for i in libtuscany_sca_python.*; do mv $$i $$i.disabled; done + +pydir=$(prefix)/extensions/python/lib +py_DATA = tuscany/sca/python/sca_proxy.py +EXTRA_DIST = tuscany/sca/python/sca_proxy.py deploy.sh + +rootdir=$(prefix)/extensions/python +root_SCRIPTS = deploy.sh + +noinst_HEADERS = \ +tuscany/sca/python/*.h \ +tuscany/sca/python/model/*.h + +libtuscany_sca_python_la_SOURCES = \ +tuscany/sca/python/PythonExtension.cpp \ +tuscany/sca/python/PythonImplementationExtension.cpp \ +tuscany/sca/python/PythonInterfaceExtension.cpp \ +tuscany/sca/python/PythonServiceWrapper.cpp \ +tuscany/sca/python/PythonServiceProxy.cpp \ +tuscany/sca/python/sca_module.cpp \ +tuscany/sca/python/model/PythonImplementation.cpp \ +tuscany/sca/python/model/PythonInterface.cpp \ +tuscany/sca/python/model/PythonReferenceBinding.cpp \ +tuscany/sca/python/model/PythonServiceBinding.cpp + +# Need python env varibles set. e.g: +# PYTHON_LIB=/usr/lib +# PYTHON_INCLUDE=/usr/include/python2.4 +# PYTHON_VERSION=python2.4 +libtuscany_sca_python_la_LIBADD = -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo \ + -L$(top_builddir)/runtime/core/src -ltuscany_sca \ + -L${PYTHON_LIB} -l${PYTHON_VERSION} + +INCLUDES = -Imodel -I$(top_builddir)/runtime/core/src \ + -I${TUSCANY_SDOCPP}/include \ + -I${PYTHON_INCLUDE} + +AM_CPPFLAGS = $(CPPFLAGS) -D_DEBUG + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/deploy.cmd b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/deploy.cmd new file mode 100644 index 0000000000..7cd6bb29ab --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/deploy.cmd @@ -0,0 +1,28 @@ +@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
+set currentPath=%~d0%~p0
+
+echo Enabling the Tuscany Python extension
+rename %currentPath%\bin\tuscany_sca_python.dll.disabled tuscany_sca_python.dll
+
+:end
+echo Done
+endlocal
diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/deploy.sh b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/deploy.sh new file mode 100755 index 0000000000..af8ad6f422 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/deploy.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# 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. + +APFULLDIR=`pwd` + +echo "Enabling the Tuscany Python extension" + +for i in lib/*.disabled; do x=${i%.disabled}; mv $i $x; done + +echo "Done" diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonExtension.cpp new file mode 100644 index 0000000000..4744f628e0 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonExtension.cpp @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + + +#include "tuscany/sca/python/PythonExtension.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/python/PythonImplementationExtension.h" +#include "tuscany/sca/python/PythonInterfaceExtension.h" + + +extern "C" +{ + #if defined(WIN32) || defined(_WINDOWS) + __declspec(dllexport) + #endif + void tuscany_sca_extension_initialize() + { + tuscany::sca::python::PythonExtension::initialize(); + } +} + +namespace tuscany +{ + namespace sca + { + namespace python + { + // =================================================================== + // Constructor for the PythonExtension class. + // =================================================================== + PythonExtension::PythonExtension() + { + LOGENTRY(1, "PythonExtension::constructor"); + LOGEXIT(1, "PythonExtension::constructor"); + } + + // =================================================================== + // Destructor for the PythonExtension class. + // =================================================================== + PythonExtension::~PythonExtension() + { + LOGENTRY(1, "PythonExtension::destructor");; + LOGEXIT(1, "PythonExtension::destructor"); + } + + void PythonExtension::initialize() + { + LOGENTRY(1, "PythonExtension::initialize");; + SCARuntime::getInstance()->registerImplementationExtension(new PythonImplementationExtension()); + SCARuntime::getInstance()->registerInterfaceExtension(new PythonInterfaceExtension()); + LOGEXIT(1, "PythonExtension::initialize");; + } + + } // End namespace python + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonExtension.h new file mode 100644 index 0000000000..783f37a228 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonExtension.h @@ -0,0 +1,57 @@ +/* + * 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_python_pythonextension_h +#define tuscany_sca_python_pythonextension_h + +namespace tuscany +{ + namespace sca + { + namespace python + { + + class PythonExtension + { + public: + /** + * Default constructor + */ + PythonExtension(); + + /** + * Destructor + */ + virtual ~PythonExtension(); + + static void initialize(); + + private: + + }; + + + } // End namespace python + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_python_pythonextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonImplementationExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonImplementationExtension.cpp new file mode 100644 index 0000000000..0623fb206c --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonImplementationExtension.cpp @@ -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$ */ + + +#include "tuscany/sca/python/PythonImplementationExtension.h" +#include "tuscany/sca/python/model/PythonImplementation.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" + + +namespace tuscany +{ + namespace sca + { + namespace python + { + // =================================================================== + // Constructor for the PythonImplementationExtension class. + // =================================================================== + PythonImplementationExtension::PythonImplementationExtension() + { + LOGENTRY(1, "PythonImplementationExtension::constructor"); + LOGEXIT(1, "PythonImplementationExtension::constructor"); + } + + // =================================================================== + // Destructor for the PythonImplementationExtension class. + // =================================================================== + PythonImplementationExtension::~PythonImplementationExtension() + { + LOGENTRY(1, "PythonImplementationExtension::destructor");; + LOGEXIT(1, "PythonImplementationExtension::destructor"); + } + + const string PythonImplementationExtension::extensionName("python"); + const string PythonImplementationExtension::typeQName("http://www.osoa.org/xmlns/sca/1.0#PythonImplementation"); + + // =================================================================== + // loadModelElement - load the info from implementation.python + // =================================================================== + ComponentType* PythonImplementationExtension::getImplementation(Composite *composite, DataObjectPtr scdlImplementation) + { + string implType = scdlImplementation->getType().getName(); + if (implType == "PythonImplementation") + { + string module = scdlImplementation->getCString("module"); + string path = scdlImplementation->getCString("path"); + string className = scdlImplementation->getCString("class"); + string scopeName = scdlImplementation->getCString("scope"); + + PythonImplementation::Scope scope; + if (scopeName == "composite") + { + scope = PythonImplementation::COMPOSITE; + } + else + { + scope = PythonImplementation::STATELESS; + } + + PythonImplementation* pythonImpl = new PythonImplementation(composite, module, path, className, scope); + + return pythonImpl; + } + else + { + return NULL; + } + } + + } // End namespace python + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonImplementationExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonImplementationExtension.h new file mode 100644 index 0000000000..69414dce22 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonImplementationExtension.h @@ -0,0 +1,73 @@ +/* + * 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_python_pythonimplementationextension_h +#define tuscany_sca_python_pythonimplementationextension_h + +#include "tuscany/sca/extension/ImplementationExtension.h" + +namespace tuscany +{ + namespace sca + { + namespace python + { + + class PythonImplementationExtension : public ImplementationExtension + { + public: + /** + * Default constructor + */ + PythonImplementationExtension(); + + /** + * Destructor + */ + virtual ~PythonImplementationExtension(); + + /** + * return the name of the extension + */ + virtual const string& getExtensionName() {return extensionName;} + + /** + * return the QName of schema elemant for this implementation extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#implementation.python") + */ + virtual const string& getExtensionTypeQName() {return typeQName;} + + virtual ComponentType* getImplementation(Composite* composite, DataObjectPtr scdlImplementation); + + private: + static const string extensionName; + static const string typeQName; + + }; + + + } // End namespace python + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_python_pythonimplementationextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonInterfaceExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonInterfaceExtension.cpp new file mode 100644 index 0000000000..2a4c94b7af --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonInterfaceExtension.cpp @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/python/PythonInterfaceExtension.h" +#include "tuscany/sca/python/model/PythonInterface.h" +#include "tuscany/sca/util/Logging.h" + +//#include "commonj/sdo/SDO.h" +//using commonj::sdo::DataObjectList; + +namespace tuscany +{ + namespace sca + { + namespace python + { + // =================================================================== + // Constructor for the PythonInterfaceExtension class. + // =================================================================== + PythonInterfaceExtension::PythonInterfaceExtension() + { + LOGENTRY(1, "PythonInterfaceExtension::constructor"); + LOGEXIT(1, "PythonInterfaceExtension::constructor"); + } + + // =================================================================== + // Destructor for the PythonInterfaceExtension class. + // =================================================================== + PythonInterfaceExtension::~PythonInterfaceExtension() + { + LOGENTRY(1, "PythonInterfaceExtension::destructor");; + LOGEXIT(1, "PythonInterfaceExtension::destructor"); + } + + const string PythonInterfaceExtension::extensionName("python"); + const string PythonInterfaceExtension::typeQName("http://www.osoa.org/xmlns/sca/1.0#PythonInterface"); + + // =================================================================== + // loadModelElement - load the info from interface.python + // =================================================================== + tuscany::sca::model::Interface* PythonInterfaceExtension::getInterface(Composite* composite, DataObjectPtr scdlInterface) + { + // Determine the type + string ifType = scdlInterface->getType().getName(); + if (ifType == "PythonInterface") + { + bool remotable = scdlInterface->getBoolean("remotable"); + bool conversational = scdlInterface->getBoolean("conversational"); + + return new PythonInterface(remotable, conversational); + //DataObjectList& operationList = scdlInterface->getList("operation"); + + //for(int i=0; i<operationList.size(); i++) + //{ + // string opName = operationList[i]->getCString("name"); + + // if(operationList[i]->hasProperty("returnType")) + // { + // string returnType = operationList[i]->getCString("returnType"); + + // if(returnType == "string") + // { + // pythonInterface->addOperation(opName, PythonInterface::STRING); + // } + // else if(returnType == "int") + // { + // pythonInterface->addOperation(opName, PythonInterface::INT); + // } + // else if(returnType == "long") + // { + // pythonInterface->addOperation(opName, PythonInterface::LONG); + // } + // else if(returnType == "boolean") + // { + // pythonInterface->addOperation(opName, PythonInterface::BOOLEAN); + // } + // else if(returnType == "float") + // { + // pythonInterface->addOperation(opName, PythonInterface::FLOAT); + // } + // else if(returnType == "other") + // { + // pythonInterface->addOperation(opName, PythonInterface::OTHER); + // } + // else + // { + // pythonInterface->addOperation(opName, PythonInterface::NONE); + // } + // } + // else + // { + // // No return Type provided - set as NONE + // pythonInterface->addOperation(opName, PythonInterface::NONE); + // } + //} + // + //return pythonInterface; + } + return 0; + } + + } // End namespace python + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonInterfaceExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonInterfaceExtension.h new file mode 100644 index 0000000000..3596857c0d --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonInterfaceExtension.h @@ -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$ */ + +#ifndef tuscany_sca_python_pythoninterfaceextension_h +#define tuscany_sca_python_pythoninterfaceextension_h + +#include "tuscany/sca/extension/InterfaceExtension.h" + +namespace tuscany +{ + namespace sca + { + namespace python + { + + class PythonInterfaceExtension : public InterfaceExtension + { + public: + /** + * Default constructor + */ + PythonInterfaceExtension(); + + /** + * Destructor + */ + virtual ~PythonInterfaceExtension(); + + /** + * return the name of the extension + */ + virtual const string& getExtensionName() {return extensionName;} + + /** + * return the QName of schema elemant for this implementation extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#PythonInterface") + */ + virtual const string& getExtensionTypeQName() {return typeQName;} + + virtual tuscany::sca::model::Interface* getInterface(Composite* composite, DataObjectPtr scdlInterface); + + private: + static const string extensionName; + static const string typeQName; + + }; + + + } // End namespace python + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_python_pythoninterfaceextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceProxy.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceProxy.cpp new file mode 100644 index 0000000000..ef482f32e8 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceProxy.cpp @@ -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$ */ + +#include "tuscany/sca/python/PythonServiceProxy.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/python/PythonServiceRuntimeException.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/ComponentType.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/ServiceBinding.h" +#include "tuscany/sca/python/model/PythonImplementation.h" +#include "tuscany/sca/python/model/PythonReferenceBinding.h" + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace python + { + + // ============================================ + // Constructor: Create a proxy from a reference + // ============================================ + PythonServiceProxy::PythonServiceProxy(Reference* reference) + : ServiceProxy(reference) + { + LOGENTRY(1,"PythonServiceProxy::constructor(Reference)"); + + // Get the service wrapper + PythonReferenceBinding* referenceBinding = (PythonReferenceBinding*)reference->getBinding(); + serviceWrapper = referenceBinding->getTargetServiceBinding()->getServiceWrapper(); + + LOGEXIT(1,"PythonServiceProxy::constructor(Reference)"); + } + + // ========================================== + // Constructor: Create a proxy from a service + // ========================================== + PythonServiceProxy::PythonServiceProxy(Service* service) + : ServiceProxy(NULL) + { + LOGENTRY(1,"PythonServiceProxy::constructor(Service)"); + + // Get the service wrapper + serviceWrapper = service->getBinding()->getServiceWrapper(); + + LOGEXIT(1,"PythonServiceProxy::constructor(Service)"); + } + + // ========== + // Destructor + // ========== + PythonServiceProxy::~PythonServiceProxy() + { + LOGENTRY(1,"PythonServiceProxy::destructor"); + LOGEXIT(1,"PythonServiceProxy::destructor"); + } + + // ===================================================== + // invokeService: invoke the service wired to this proxy + // ===================================================== + void PythonServiceProxy::invokeService(Operation& operation) + { + LOGENTRY(1,"PythonServiceProxy::invokeService"); + + // Invoke the service + serviceWrapper->invoke(operation); + + LOGEXIT(1,"PythonServiceProxy::invokeService"); + } + } // End namespace python + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceProxy.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceProxy.h new file mode 100644 index 0000000000..f16cb95609 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceProxy.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_python_pythonserviceproxy_h +#define tuscany_sca_python_pythonserviceproxy_h + +#include "tuscany/sca/core/ServiceProxy.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/util/Library.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/Service.h" + +#include "export.h" + +using namespace tuscany::sca::model; + + +namespace tuscany +{ + namespace sca + { + namespace python + { + + /** + * Holds a proxy for a given reference from a component implemented in Python. + */ + class PythonServiceProxy : public 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. + */ + PythonServiceProxy(Reference* reference); + + /** + * Create a new service proxy for a service. The proxy will contain a pointer to + * the target ServiceWrapper. + * @param service The service on the target component. + */ + SCA_PYTHON_API PythonServiceProxy(Service* service); + + /** + * Destructor. + */ + virtual ~PythonServiceProxy(); + + /** + * Invoke the wired service. + */ + virtual void invokeService(Operation& operation); + + private: + + /** + * The target service wrapper + */ + ServiceWrapper* serviceWrapper; + }; + + } // End namespace python + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_python_pythonserviceproxy_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceRuntimeException.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceRuntimeException.h new file mode 100644 index 0000000000..aa8c88d06d --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceRuntimeException.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_python_pythonserviceruntimeexception_h +#define tuscany_sca_python_pythonserviceruntimeexception_h + +#include "export.h" + +#include "tuscany/sca/util/Exceptions.h" +using tuscany::sca::TuscanyRuntimeException; +namespace tuscany +{ + namespace sca + { + namespace python + { + /** + * Exception to represent a failure in a Python call. + */ + class SCA_PYTHON_API PythonServiceRuntimeException : public TuscanyRuntimeException + { + public: + PythonServiceRuntimeException( + const char *name="PythonServiceRuntimeException", + severity_level sev=Severe, + const char* msg_text="") + : TuscanyRuntimeException(name, sev, msg_text) + { + } + }; // End PythonServiceRuntimeException class definition + + /** + * The target of a wire cannot be found, or the reference has not been + * configured. + */ + class SCA_PYTHON_API PythonServiceNotFoundException: public PythonServiceRuntimeException + { + public: + PythonServiceNotFoundException(const char* msg) + : PythonServiceRuntimeException("PythonServiceNotFoundException", Error, + msg) + { + } + private: + }; // End PythonServiceNotFoundException class definition + + + /** + * There is no current component (for example, if a non-SCA component + * tries to get the current ComponentContext). + */ + class SCA_PYTHON_API PythonComponentContextException: public PythonServiceRuntimeException + { + public: + PythonComponentContextException(const char* msg) + : PythonServiceRuntimeException("PythonComponentContextException", Error, + msg) + { + } + private: + }; // End PythonComponentContextException class definition + + /** + * There is no current component (for example, if a non-SCA component + * tries to get the current ComponentContext). + */ + class SCA_PYTHON_API PythonComponentInvocationException: public PythonServiceRuntimeException + { + public: + PythonComponentInvocationException(const char* msg) + : PythonServiceRuntimeException("ComponentInvocationException", Error, + msg) + { + } + private: + }; // End PythonComponentInvocationException class definition + + } // End namespace python + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_python_pythonserviceruntimeexception_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceWrapper.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceWrapper.cpp new file mode 100644 index 0000000000..0223a5741d --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceWrapper.cpp @@ -0,0 +1,950 @@ +/* + * 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/python/PythonServiceRuntimeException.h" +#include "tuscany/sca/python/PythonServiceWrapper.h" + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/Interface.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/python/model/PythonImplementation.h" + +#include "commonj/sdo/SDO.h" +using namespace commonj::sdo; + +namespace tuscany +{ + namespace sca + { + namespace python + { + + /** + * Prints out PyObject and dir(PyObject) + * for debugging purposes + */ + void printPyObject(char * name, PyObject *pObj) + { + PyObject* pObjRepr = PyObject_Repr(pObj); + LOGINFO_2(5, "PythonServiceWrapper::printPyObject %s: %s", name, PyString_AsString(pObjRepr)); + Py_DECREF(pObjRepr); + + PyObject* pObjDir = PyObject_Dir(pObj); + PyObject* pObjDirRepr = PyObject_Repr(pObjDir); + LOGINFO_2(5, "PythonServiceWrapper::printPyObject dir(%s): %s", name, PyString_AsString(pObjDirRepr)); + Py_DECREF(pObjDirRepr); + Py_DECREF(pObjDir); + } + + // =========== + // Constructor + // =========== + PythonServiceWrapper::PythonServiceWrapper(Service* service) + : ServiceWrapper(service) + { + LOGENTRY(1,"PythonServiceWrapper::constructor"); + + component = service->getComponent(); + implementation = (PythonImplementation*)component->getType(); + + pythonModule = NULL; + pythonClassInstance = NULL; + + // ----------------------------------------------- + // Get the implementation for the target component + // ----------------------------------------------- + PythonImplementation* impl = (PythonImplementation*)component->getType(); + if (!impl) + { + string msg = "Component " + component->getName() + " has no implementation defined"; + throw PythonServiceNotFoundException(msg.c_str()); + } + + LOGINFO_1(3,"PythonServiceWrapper::constructor module %s", impl->getModule().c_str()); + LOGINFO_1(3,"PythonServiceWrapper::constructor path %s", impl->getModulePath().c_str()); + LOGINFO_1(3,"PythonServiceWrapper::constructor class %s", impl->getClass().c_str()); + + // Initialize the Python environment + Py_Initialize(); + + // Add the path to the composite (+ any further path specified) to the Python sys.path + string path = component->getComposite()->getRoot() + "/" + impl->getModulePath(); + + PyObject* pSysName = PyString_FromString("sys"); + PyObject* pSys = PyImport_Import(pSysName); + Py_DECREF(pSysName); + + if(pSys != NULL) + { + PyObject* pSysPath = PyObject_GetAttrString(pSys, "path"); + + if(pSysPath != NULL && PyList_Check(pSysPath)) + { + PyObject* pPath = PyString_FromString(path.c_str()); + PyList_Append(pSysPath, pPath); + + + Py_DECREF(pPath); + Py_DECREF(pSysPath); + } + Py_DECREF(pSys); + } + + if(&(impl->getModule()) != NULL && impl->getModule().size() > 0) + { + // Now import the module + PyObject* pModuleName = PyString_FromString(impl->getModule().c_str()); + + pythonModule = PyImport_Import(pModuleName); + Py_DECREF(pModuleName); + } + + if (!pythonModule) + { + if(PyErr_Occurred()) + { + PyErr_Print(); + } + string msg = "Failed to load module named " + impl->getModule(); + LOGERROR(0, msg.c_str()); + throw PythonComponentContextException(msg.c_str()); + } + //else + //{ + // addReferences(pythonModule); + // addProperties(pythonModule); + //} + + printPyObject("pythonModule",pythonModule); + + LOGEXIT(1,"PythonServiceWrapper::constructor"); + + } + + // ========== + // Destructor + // ========== + PythonServiceWrapper::~PythonServiceWrapper() + { + LOGENTRY(1,"PythonServiceWrapper::destructor"); + Py_XDECREF(pythonClassInstance); + Py_XDECREF(pythonModule); + Py_Finalize(); + LOGEXIT(1,"PythonServiceWrapper::destructor"); + } + + // ====================================================================== + // newInstance: create a new class instance + // ====================================================================== + PyObject* PythonServiceWrapper::newInstance() + { + LOGENTRY(1,"PythonServiceWrapper::newInstance"); + PythonImplementation* impl = (PythonImplementation*)component->getType(); + string className = impl->getClass(); + + PyObject* pClassInstance = NULL; + if (pythonModule != NULL) + { + if(&className != NULL && className.size() > 0) + { + // We have a class name, so create an instance and use this to invoke the correct function + PyObject* pClass = PyObject_GetAttrString(pythonModule, (char*) className.c_str()); + + if(pClass == NULL) + { + if(PyErr_Occurred()) + { + PyErr_Print(); + } + string msg = "Cannot find class named " + className + " in Python module"; + LOGERROR(0, msg.c_str()); + throw new PythonComponentInvocationException(msg.c_str()); + } + + pClassInstance = PyInstance_New(pClass, NULL, NULL); + + if(pClassInstance == NULL || !PyInstance_Check(pClassInstance)) + { + if(PyErr_Occurred()) + { + PyErr_Print(); + } + string msg = "Could not create new instance of class named " + className + " in Python module"; + LOGERROR(0, msg.c_str()); + throw new PythonComponentInvocationException(msg.c_str()); + } + Py_XDECREF(pClass); + } + } + LOGEXIT(1,"PythonServiceWrapper::newInstance"); + return pClassInstance; + } + + // ====================================================================== + // getInstance: get a class instance for this scope + // ====================================================================== + PyObject* PythonServiceWrapper::getInstance() + { + LOGENTRY(1,"PythonServiceWrapper::getInstance"); + + PythonImplementation::Scope scope = implementation->getScope(); + if (scope == PythonImplementation::COMPOSITE) + { + if (!pythonClassInstance) + { + pythonClassInstance = newInstance(); + } + return pythonClassInstance; + } + else // (scope == PythonImplementation::STATELESS) + { + return newInstance(); + } + LOGEXIT(1,"PythonServiceWrapper::getInstance"); + } + + // ====================================================================== + // releaseImplementation: release the implementation for this scope + // ====================================================================== + void PythonServiceWrapper::releaseInstance() + { + LOGENTRY(1,"PythonServiceWrapper::releaseInstance"); + + PythonImplementation::Scope scope = implementation->getScope(); + if(scope == PythonImplementation::STATELESS) + { + // Delete the class instance if there is one + if(pythonClassInstance != NULL && PyInstance_Check(pythonClassInstance)) + { + Py_DECREF(pythonClassInstance); + pythonClassInstance = NULL; + } + + // Need to reload the module + PyObject* reloadedPythonModule = PyImport_ReloadModule(pythonModule); + + if(reloadedPythonModule != NULL) + { + // Get rid of old pythonModule and replace with the reloaded one + Py_DECREF(pythonModule); + pythonModule = reloadedPythonModule; + } + } + LOGEXIT(1,"PythonServiceWrapper::releaseInstance"); + } + + // ====================================================================== + // invoke: wrapper call to service with setting the component context + // ====================================================================== + void PythonServiceWrapper::invoke(Operation& operation) + { + LOGENTRY(1,"PythonServiceWrapper::invoke"); + + SCARuntime* runtime = SCARuntime::getInstance(); + runtime->setCurrentComponent(component); + + + // Load the references & properties into the module + addReferences(pythonModule); + addProperties(pythonModule); + + try + { + LOGINFO_1(4, "PythonServiceWrapper::invoke called with operation name: %s", operation.getName().c_str()); + + PyObject* pFunc = NULL; + pythonClassInstance = getInstance(); + + if(pythonClassInstance != NULL && PyInstance_Check(pythonClassInstance)) + { + // Get the function from the instance + pFunc = PyObject_GetAttrString(pythonClassInstance, (char*) operation.getName().c_str()); + } + if(pFunc == NULL && pythonModule != NULL) + { + // Get the function directly from the module if it could not be got from an instance + pFunc = PyObject_GetAttrString(pythonModule, (char*) operation.getName().c_str()); + } + if(pFunc == NULL) + { + // Can't get the function from the class or module - throw exception + string msg = "Python module or class instance has not been created"; + LOGERROR(0, msg.c_str()); + throw new PythonComponentInvocationException(msg.c_str()); + } + + if (pFunc && PyCallable_Check(pFunc)) + { + PyObject* pArgs = PyTuple_New(operation.getNParms()); + PyObject* pValue = NULL; + + for(unsigned int i = 0; i < operation.getNParms(); i++) + { + const Operation::Parameter& parm = operation.getParameter(i); + switch(parm.getType()) + { + case Operation::BOOL: + { + if( *(bool*)parm.getValue()) + { + //boolean true + pValue = Py_True; + } + else + { + pValue = Py_False; + } + break; + } + case Operation::SHORT: + { + pValue = PyInt_FromLong(*(short*)parm.getValue()); + break; + } + case Operation::USHORT: + { + pValue = PyInt_FromLong(*(unsigned short*)parm.getValue()); + break; + } + case Operation::INT: + { + pValue = PyInt_FromLong(*(int*)parm.getValue()); + break; + } + case Operation::UINT: + { + pValue = PyInt_FromLong(*(unsigned int*)parm.getValue()); + break; + } + case Operation::LONG: + { + pValue = PyLong_FromLong(*(long*)parm.getValue()); + break; + } + case Operation::ULONG: + { + pValue = PyLong_FromUnsignedLong(*(unsigned long*)parm.getValue()); + break; + } + case Operation::FLOAT: + { + pValue = PyFloat_FromDouble(*(float*)parm.getValue()); + break; + } + case Operation::DOUBLE: + { + pValue = PyFloat_FromDouble(*(double*)parm.getValue()); + break; + } + case Operation::LONGDOUBLE: + { + pValue = PyFloat_FromDouble(*(long double*)parm.getValue()); + break; + } + case Operation::CHARS: + { + pValue = PyString_FromString(*(char**)parm.getValue()); + break; + } + case Operation::STRING: + { + pValue = PyString_FromString((*(string*)parm.getValue()).c_str()); + break; + } + default: throw new PythonComponentInvocationException("Operation parameter type not supported"); + } + + if (!pValue) + { + Py_DECREF(pArgs); + + if(PyErr_Occurred()) + { + PyErr_Print(); + } + + string msg = "Error converting parameter into Python type"; + LOGERROR(0, msg.c_str()); + throw new PythonComponentInvocationException(msg.c_str()); + + } + //printPyObject("Param value", pValue); + + /* pValue reference stolen here: */ + PyTuple_SetItem(pArgs, i, pValue); + } + + pValue = PyObject_CallObject(pFunc, pArgs); + //printPyObject("Return value", pValue); + + Py_DECREF(pArgs); + if (pValue != NULL) + { + char buf[20]; + if(PyInt_Check(pValue) || PyLong_Check(pValue)) + { + long* data = new long; + if(PyInt_Check(pValue)) + { + LOGINFO_1(3, "PythonServiceWrapper::invoke Return value is int type: %d", PyInt_AsLong(pValue)); + *data = PyInt_AsLong(pValue); + } + else + { + LOGINFO_1(3, "PythonServiceWrapper::invoke Return value is long type: %l", PyLong_AsLong(pValue)); + *data = PyLong_AsLong(pValue); + } + + // Check if the return type has already been set (for typed languages) + switch(operation.getReturnType()) + { + case Operation::BOOL: + { + *(bool*)operation.getReturnValue() = (*data != 0); + break; + } + case Operation::SHORT: + { + *(short*)operation.getReturnValue() = (short)*data; + break; + } + case Operation::USHORT: + { + *(unsigned short*)operation.getReturnValue() = (unsigned short)*data; + break; + } + case Operation::INT: + { + *(int*)operation.getReturnValue() = (int)*data; + break; + } + case Operation::UINT: + { + *(unsigned int*)operation.getReturnValue() = (unsigned int)*data; + break; + } + case Operation::LONG: + { + *(long*)operation.getReturnValue() = (long)*data; + break; + } + case Operation::ULONG: + { + *(unsigned long*)operation.getReturnValue() = (unsigned long)*data; + break; + } + case Operation::FLOAT: + { + *(float*)operation.getReturnValue() = (float)*data; + break; + } + case Operation::DOUBLE: + { + *(double*)operation.getReturnValue() = (double)*data; + break; + } + case Operation::LONGDOUBLE: + { + *(long double*)operation.getReturnValue() = (long double)*data; + break; + } + case Operation::CHARS: + { + sprintf(buf, "%d", *data); + *(char**)operation.getReturnValue() = buf; + break; + } + case Operation::STRING: + { + sprintf(buf, "%d", *data); + *(string*)operation.getReturnValue() = buf; + break; + } + default: + { + // The type is set as something else or has not been set + operation.setReturnValue(data); + } + } + } + else if(PyBool_Check(pValue)) + { + LOGINFO_1(3, "PythonServiceWrapper::invoke Return value is bool type: %d", (pValue == Py_True)); + bool* data = new bool; + *data = (pValue == Py_True); + + // Check if the return type has already been set (for typed languages) + switch(operation.getReturnType()) + { + case Operation::BOOL: + { + *(bool*)operation.getReturnValue() = *data; + break; + } + case Operation::SHORT: + { + *(short*)operation.getReturnValue() = (short)*data; + break; + } + case Operation::USHORT: + { + *(unsigned short*)operation.getReturnValue() = (unsigned short)*data; + break; + } + case Operation::INT: + { + *(int*)operation.getReturnValue() = (int)*data; + break; + } + case Operation::UINT: + { + *(unsigned int*)operation.getReturnValue() = (unsigned int)*data; + break; + } + case Operation::LONG: + { + *(long*)operation.getReturnValue() = (long)*data; + break; + } + case Operation::ULONG: + { + *(unsigned long*)operation.getReturnValue() = (unsigned long)*data; + break; + } + case Operation::FLOAT: + { + *(float*)operation.getReturnValue() = (float)*data; + break; + } + case Operation::DOUBLE: + { + *(double*)operation.getReturnValue() = (double)*data; + break; + } + case Operation::LONGDOUBLE: + { + *(long double*)operation.getReturnValue() = (long double)*data; + break; + } + case Operation::CHARS: + { + if(*data) + { + *(char**)operation.getReturnValue() = "true"; + } + else + { + *(char**)operation.getReturnValue() = "false"; + } + break; + } + case Operation::STRING: + { + if(*data) + { + *(string*)operation.getReturnValue() = "true"; + } + else + { + *(string*)operation.getReturnValue() = "false"; + } + break; + } + default: + { + // The type is set as something else or has not been set + operation.setReturnValue(data); + } + } + } + else if(PyFloat_Check(pValue)) + { + LOGINFO_1(3, "PythonServiceWrapper::invoke Return value is float type: %f", PyFloat_AsDouble(pValue)); + + double* data = new double; + *data = PyFloat_AsDouble(pValue); + + // Check if the return type has already been set (for typed languages) + switch(operation.getReturnType()) + { + case Operation::BOOL: + { + *(bool*)operation.getReturnValue() = (*data != 0.0); + break; + } + case Operation::SHORT: + { + *(short*)operation.getReturnValue() = (short)*data; + break; + } + case Operation::USHORT: + { + *(unsigned short*)operation.getReturnValue() = (unsigned short)*data; + break; + } + case Operation::INT: + { + *(int*)operation.getReturnValue() = (int)*data; + break; + } + case Operation::UINT: + { + *(unsigned int*)operation.getReturnValue() = (unsigned int)*data; + break; + } + case Operation::LONG: + { + *(long*)operation.getReturnValue() = (long)*data; + break; + } + case Operation::ULONG: + { + *(unsigned long*)operation.getReturnValue() = (unsigned long)*data; + break; + } + case Operation::FLOAT: + { + *(float*)operation.getReturnValue() = (float)*data; + break; + } + case Operation::DOUBLE: + { + *(double*)operation.getReturnValue() = (double)*data; + break; + } + case Operation::LONGDOUBLE: + { + *(long double*)operation.getReturnValue() = (long double)*data; + break; + } + case Operation::CHARS: + { + sprintf(buf, "%f", *data); + *(char**)operation.getReturnValue() = buf; + break; + } + case Operation::STRING: + { + sprintf(buf, "%f", *data); + *(string*)operation.getReturnValue() = buf; + break; + } + default: + { + // The type is set as something else or has not been set + operation.setReturnValue(data); + } + } + } + else if(PyString_Check(pValue)) + { + LOGINFO_1(3, "PythonServiceWrapper::invoke Return value is string type: %s", PyString_AsString(pValue)); + const char** data = new const char*; + *data = PyString_AsString(pValue); + + // Check if the return type has already been set (for typed languages) + switch(operation.getReturnType()) + { + case Operation::BOOL: + { + // If the string is empty or "0" or "false" set to false, otherwise true + if(strlen(*data) == 0 || strcmp(*data, "0") == 0 || strcmp(*data, "false") == 0) + { + *(bool*)operation.getReturnValue() = false; + } + else + { + *(bool*)operation.getReturnValue() = true; + } + break; + } + case Operation::SHORT: + { + *(short*)operation.getReturnValue() = (short)atoi(*data); + break; + } + case Operation::USHORT: + { + *(unsigned short*)operation.getReturnValue() = (unsigned short)atoi(*data); + break; + } + case Operation::INT: + { + *(int*)operation.getReturnValue() = (int)atoi(*data); + break; + } + case Operation::UINT: + { + *(unsigned int*)operation.getReturnValue() = (unsigned int)atoi(*data); + break; + } + case Operation::LONG: + { + *(long*)operation.getReturnValue() = (long)atol(*data); + break; + } + case Operation::ULONG: + { + *(unsigned long*)operation.getReturnValue() = (unsigned long)atol(*data); + break; + } + case Operation::FLOAT: + { + *(float*)operation.getReturnValue() = (float)atof(*data); + break; + } + case Operation::DOUBLE: + { + *(double*)operation.getReturnValue() = (double)atof(*data); + break; + } + case Operation::LONGDOUBLE: + { + *(long double*)operation.getReturnValue() = (long double)atof(*data); + break; + } + case Operation::CHARS: + { + *(const char**)operation.getReturnValue() = *data; + break; + } + case Operation::STRING: + { + *(string*)operation.getReturnValue() = *data; + break; + } + default: + { + // The type is set as something else or has not been set + operation.setReturnValue(data); + } + } + } + else + { + PyObject* valueRepr = PyObject_Repr(pValue); + PyObject* valueType = PyObject_Type(pValue); + PyObject* valueTypeRepr = PyObject_Repr(valueType); + LOGINFO_2(3, "PythonServiceWrapper::invoke Return value is of unknown type (%s) and has repr: %s", PyString_AsString(valueTypeRepr), PyString_AsString(valueRepr)); + Py_DECREF(valueTypeRepr); + Py_DECREF(valueType); + Py_DECREF(valueRepr); + } + + Py_DECREF(pValue); + } + else + { + Py_DECREF(pFunc); + if(PyErr_Occurred()) + { + PyErr_Print(); + } + string msg = "Error whilst calling Python module"; + LOGERROR(0, msg.c_str()); + throw new PythonComponentInvocationException(msg.c_str()); + } + } + else + { + if (PyErr_Occurred()) + { + PyErr_Print(); + } + string msg = "Cannot find the operation named " + operation.getName() + " in the Python module"; + LOGERROR(0, msg.c_str()); + throw new PythonComponentInvocationException(msg.c_str()); + } + Py_XDECREF(pFunc); + + } + catch (...) + { + releaseInstance(); + runtime->unsetCurrentComponent(); + throw; + } + releaseInstance(); + runtime->unsetCurrentComponent(); + LOGEXIT(1,"PythonServiceWrapper::invoke"); + + } + + + // ========================================================================== + // Add any properties into the loaded implementation module as Python objects + // ========================================================================== + void PythonServiceWrapper::addProperties(PyObject* module) + { + // Set all the configured properties + DataObjectPtr properties = component->getProperties(); + PropertyList pl = properties->getInstanceProperties(); + + for (int i = 0; i < pl.size(); i++) + { + if (properties->isSet(pl[i])) + { + string propName = pl[i].getName(); + string propValue = properties->getCString(pl[i]); + PyObject* property; + + if(pl[i].isMany()) + { + //TODO - deal with properties that are many + } + + switch(pl[i].getTypeEnum()) + { + case Type::BooleanType: + { + if(properties->getBoolean(pl[i])) + { + property = Py_True; + } + else + { + property = Py_False; + } + Py_INCREF(property); + break; + } + case Type::BigIntegerType: + case Type::BigDecimalType: + case Type::LongType: + { + property = PyLong_FromLongLong(properties->getLong(pl[i])); + break; + } + case Type::ShortType: + case Type::IntegerType: + { + property = PyInt_FromLong(properties->getInteger(pl[i])); + break; + } + case Type::DoubleType: + case Type::FloatType: + { + property = PyFloat_FromDouble(properties->getDouble(pl[i])); + break; + } + case Type::DataObjectType: + case Type::OpenDataObjectType: + { + // Serialize a DataObject and create a python string object from the XML + DataObjectPtr data = properties->getDataObject(pl[i]); + XMLHelperPtr helper = HelperProvider::getXMLHelper(properties->getDataFactory()); + string serializedData = helper->save(data, "", propName); + property = PyString_FromString(serializedData.c_str()); + break; + } + case Type::CharacterType: + case Type::StringType: + case Type::TextType: + case Type::UriType: + default: + { + // For strings and by default create a python string object + property = PyString_FromString(propValue.c_str()); + break; + } + } + + int success = PyModule_AddObject(module, (char*)propName.c_str(), property); + + if(success == 0) + { + LOGINFO_3(3, "Successfully added property named %s with type %s and value %s to python module", propName.c_str(), pl[i].getType().getName(), propValue.c_str()); + } + else + { + LOGERROR_1(1, "Failed to add property named %s to python module", propName.c_str()); + } + } + } + } + + + // ====================================================================== + // Add any references into the loaded implementation module as class instances that look like + // the classes defined in the interface.python xml + // ====================================================================== + void PythonServiceWrapper::addReferences(PyObject* module) + { + + // Import the TuscanySCA python-extension module + PyObject* pModuleName = PyString_FromString("sca_proxy"); + PyObject* sca_proxy_module = PyImport_Import(pModuleName); + Py_DECREF(pModuleName); + + if(!sca_proxy_module) + { + if(PyErr_Occurred()) + { + PyErr_Print(); + } + string msg = "Failed to load the sca_proxy Python module - has it been successfully installed?\nReferences from Python components will not be supported"; + LOGERROR(0, msg.c_str()); + } + else + { + // Get the sca_proxy class + PyObject* sca_proxy_class = PyObject_GetAttrString(sca_proxy_module, "sca_proxy_class"); + + // Iterate through the references of the current component, adding + // each reference to the module + Component::REFERENCE_MAP references = component->getReferences(); + Component::REFERENCE_MAP::iterator pos; + for( pos = references.begin(); pos != references.end(); ++pos) + { + ReferenceType* referenceType = ((Reference*) pos->second)->getType(); + string referenceName = referenceType->getName(); + + PyObject* tuscanySCAArgs = PyTuple_New(2); + PyObject* refName = PyString_FromString(referenceType->getName().c_str()); + PyTuple_SetItem(tuscanySCAArgs, 0, refName); + Py_INCREF(Py_True); + PyTuple_SetItem(tuscanySCAArgs, 1, Py_True); + + // Create the instance of the TuscanySCAReference class + PyObject* sca_proxy_classInstance = PyInstance_New(sca_proxy_class, tuscanySCAArgs, NULL); + Py_DECREF(tuscanySCAArgs); + + int success = PyModule_AddObject(module, (char*)referenceName.c_str(), sca_proxy_classInstance); + + if(success == 0) + { + LOGINFO_1(3, "Successfully added sca_proxy_class instance as %s to pythonModule", referenceName.c_str()); + } + else + { + LOGERROR_1(1, "Failed to add sca_proxy_class instance as %s to pythonModule", referenceName.c_str()); + } + } + Py_DECREF(sca_proxy_module); + } + } + } // End namespace python + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceWrapper.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceWrapper.h new file mode 100644 index 0000000000..51b0f1dd64 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceWrapper.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_python_pythonservicewrapper_h +#define tuscany_sca_python_pythonservicewrapper_h + +#include "tuscany/sca/python/export.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/core/Operation.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Interface.h" +#include "tuscany/sca/python/model/PythonImplementation.h" + +using namespace tuscany::sca::model; + +// undefine _DEBUG so Python does not need it's deebug dll +#ifdef _DEBUG +#undef _DEBUG +#define _SCA_PYTHON_DEBUG +#endif +#include <Python.h> +#ifdef _SCA_PYTHON_DEBUG +#define _DEBUG +#endif + + +namespace tuscany +{ + namespace sca + { + namespace python + { + class PythonInterface; + + /** + * Wraps the service on a component implementation. + * This abstract class is extended by generated code which provides + * the implementation of some of the methods. + * An instance of this class wraps the actual component implementation which + * has been written by a developer of an SCA application. + */ + class PythonServiceWrapper : public ServiceWrapper + { + public: + + /** + * Constructor. + * @param target The component service to which this wrapper refers. + */ + PythonServiceWrapper(Service* service); + + /** + * Destructor. + */ + virtual ~PythonServiceWrapper(); + + /** + * All business method calls to the target component go through the invoke method. + * @param operation The details of the method, paramaters and return value for the + * business method to be called on the target component. + */ + virtual void invoke(Operation& operation); + + + protected: + + /** + * Return the current instance of the python class. + * @return A pointer to an instance of the python class. + */ + virtual PyObject* getInstance(); + + /** + * Creates a new instance of the python class. + * @return A pointer to a new instance of the python class. + */ + virtual PyObject* newInstance(); + + /** + * Indicates that the current instance of the python module or class + * has been finished with. + */ + virtual void releaseInstance(); + + + private: + /** + * Holds a class instance if a classname is provided. + * Will be constructed each time if scope is set to STATELESS + */ + PyObject* pythonClassInstance; + + /** + * Holds the module + */ + PyObject* pythonModule; + + /** + * Adds references to the provided implementation module or class instance + */ + void addReferences(PyObject* module); + + /** + * Adds properties to the provided implementation module or class instance + */ + void addProperties(PyObject* module); + + /** + * The component to which this wrapper refers. + */ + Component* component; + + /** + * The component implementation + */ + PythonImplementation* implementation; + + }; + + } // End namespace python + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_python_pythonservicewrapper_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/export.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/export.h new file mode 100644 index 0000000000..b608a50711 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/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_python_export_h +#define tuscany_sca_python_export_h + +#if defined(WIN32) || defined (_WINDOWS) +#pragma warning(disable: 4786) + +#ifdef TUSCANY_SCA_PYTHON_EXPORTS +#define SCA_PYTHON_API __declspec(dllexport) +#else +#define SCA_PYTHON_API __declspec(dllimport) +#endif + +#else +#include <sys/time.h> +#include <inttypes.h> +#include <stdlib.h> +#define SCA_PYTHON_API +#endif + +#endif // tuscany_sca_export_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonImplementation.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonImplementation.cpp new file mode 100644 index 0000000000..413d87173d --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonImplementation.cpp @@ -0,0 +1,87 @@ +/* + * 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/python/model/PythonImplementation.h" +#include "tuscany/sca/python/model/PythonServiceBinding.h" +#include "tuscany/sca/python/model/PythonReferenceBinding.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/util/Utils.h" + +namespace tuscany +{ + namespace sca + { + + namespace python + { + + // Constructor + PythonImplementation::PythonImplementation( + Composite* composite, const string& module, const string& modulePath, const string& className, Scope scope) + : ComponentType(composite, modulePath + "/" + module), + module(module), modulePath(modulePath), className(className), scope(scope) + { + LOGENTRY(1,"PythonImplementation::constructor"); + LOGEXIT(1,"PythonImplementation::constructor"); + } + + PythonImplementation::~PythonImplementation() + { + LOGENTRY(1,"PythonImplementation::destructor"); + LOGEXIT(1,"PythonImplementation::destructor"); + } + + void PythonImplementation::initializeComponent(Component* component) + { + LOGENTRY(1,"PythonImplementation::initializeComponent"); + ComponentType::initializeComponent(component); + + // Create Python bindings for all the services + const Component::SERVICE_MAP& services = component->getServices(); + Component::SERVICE_MAP::const_iterator iter = services.begin(); + for (unsigned int i=0; i< services.size(); i++) + { + Service *service = iter->second; + PythonServiceBinding* binding = new PythonServiceBinding(service); + service->setBinding(binding); + iter++; + } + + // Create Python bindings for all the references + const Component::REFERENCE_MAP& references = component->getReferences(); + Component::REFERENCE_MAP::const_iterator refiter = references.begin(); + for (int ri=0; ri< references.size(); ri++) + { + Reference *reference = refiter->second; + PythonReferenceBinding* binding = new PythonReferenceBinding(reference); + reference->setBinding(binding); + refiter++; + } + + LOGEXIT(1,"PythonImplementation::initializeComponent"); + } + + } // End namespace python + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonImplementation.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonImplementation.h new file mode 100644 index 0000000000..6d4cece5fd --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonImplementation.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_python_model_pythonimplementation_h +#define tuscany_sca_python_model_pythonimplementation_h +#include "tuscany/sca/model/ComponentType.h" + +#include <map> +using std::map; +#include <string> +using std::string; + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace python + { + /** + * Holds information about an SCA implementation written in Python + */ + class PythonImplementation : public ComponentType + { + + public: + /** + * Scope of the component implementation. + */ + enum Scope + { + COMPOSITE, + STATELESS + }; + + /** + * Constructor. + * @param composite The composite containing this implementation. + * @param module Name of the module. + * @param modulePath Path to the module (could be a blank string + * if this is not specified). + * @param className Name of the class in the module (could be a blank string + * if this is not specified). + */ + PythonImplementation(Composite* composite, const string& module, const string& modulePath, const string& className, Scope scope); + + /** + * Destructor + */ + virtual ~PythonImplementation(); + + /** + * Initialize a component of this type. + * @param component The component to initialize. + */ + virtual void initializeComponent(Component* component); + + /** + * Returns the name of the module. + * @return The name of the module. + */ + const string& getModule() const { return module; } + + /** + * Get the header path. + * @return The pathe element of the header. + */ + const string& getModulePath() const { return modulePath; } + + /** + * Get the name of the class. + * @return The class name if specified. + */ + const string& getClass() const { return className; } + + /** + * Returns the implementation scope + */ + Scope getScope() const { return scope; } + + private: + + /** + * Name of the module. + */ + string module; + + /** + * Path to the module. + */ + string modulePath; + + /** + * Name of the class in the header file declaring the implementation. + * May be an empty string if not set in the SCDL file. + */ + string className; + + /** + * The implementation scope + */ + Scope scope; + }; + + } // End namespace python + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_python_model_pythonimplementation_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonInterface.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonInterface.cpp new file mode 100644 index 0000000000..6836158e0d --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonInterface.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/util/Logging.h" +#include "tuscany/sca/python/export.h" +#include "tuscany/sca/python/model/PythonInterface.h" + + +namespace tuscany +{ + namespace sca + { + namespace python + { + const string PythonInterface::typeQName("http://www.osoa.org/xmlns/sca/1.0#PythonInterface"); + + // Constructor + PythonInterface::PythonInterface( + bool remotable, + bool conversational) + : Interface(remotable, conversational) + { + LOGENTRY(1, "PythonInterface::constructor"); + LOGEXIT(1, "PythonInterface::constructor"); + } + + PythonInterface::~PythonInterface() + { + } + + } // End namespace python + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonInterface.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonInterface.h new file mode 100644 index 0000000000..ed42a3920d --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonInterface.h @@ -0,0 +1,84 @@ +/* + * 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_python_model_pythoninterface_h +#define tuscany_sca_python_model_pythoninterface_h + +#include "tuscany/sca/python/export.h" +#include "tuscany/sca/model/Interface.h" + +#include <map> +using std::map; +#include <vector> +using std::vector; +#include <string> +using std::string; + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace python + { + /** + * Holds information about an interface described using a C++ + * header file. + */ + class PythonInterface : public Interface + { + + public: + /** + * Constuctor. + * @param scope The scope of the interface (stateless or composite). + * @param remotable True if the interface is remotable. + */ + PythonInterface( + bool remotable, + bool conversational); + + /** + * Destructor. + */ + virtual ~PythonInterface(); + + /** + * return the QName of the schema type for this interface type + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#interface.cpp") + */ + const string& getInterfaceTypeQName() { return typeQName; }; + + /** + * The QName of the schema type for this interface type. + */ + SCA_PYTHON_API static const string typeQName; + + }; + + } // End namespace python + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_python_model_pythoninterface_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonReferenceBinding.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonReferenceBinding.cpp new file mode 100644 index 0000000000..82f5811203 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonReferenceBinding.cpp @@ -0,0 +1,59 @@ +/* + * 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/python/model/PythonReferenceBinding.h" +#include "tuscany/sca/python/PythonServiceProxy.h" + + +namespace tuscany +{ + namespace sca + { + namespace python + { + + // Constructor + PythonReferenceBinding::PythonReferenceBinding(Reference* reference) + : ReferenceBinding(reference, ""), serviceProxy(NULL) + { + } + + // Destructor + PythonReferenceBinding::~PythonReferenceBinding() + { + } + + ServiceProxy* PythonReferenceBinding::getServiceProxy() + { + return serviceProxy; + } + + void PythonReferenceBinding::configure(ServiceBinding* binding) + { + targetServiceBinding = binding; + + serviceProxy = new PythonServiceProxy(getReference()); + } + + } // End namespace python + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonReferenceBinding.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonReferenceBinding.h new file mode 100644 index 0000000000..b37d261416 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonReferenceBinding.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_python_model_pythonreferencebinding_h +#define tuscany_sca_python_model_pythonreferencebinding_h + +#include "tuscany/sca/model/ReferenceBinding.h" + + +#include <string> +using std::string; + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace python + { + /** + * Information about a Python service binding for service or a reference. + */ + class PythonReferenceBinding : public ReferenceBinding + { + public: + + /** + * Constructor. + */ + PythonReferenceBinding(Reference* reference); + + /** + * Destructor. + */ + virtual ~PythonReferenceBinding(); + + /** + * Returns the type of binding. + */ + virtual string getType() { return "http://www.osoa.org/xmlns/sca/1.0#PythonImplementationBinding"; }; + + /** + * Create a proxy representing the reference to the + * client component. + */ + virtual ServiceProxy* getServiceProxy(); + + /** + * Configure this binding from a service binding. + */ + virtual void configure(ServiceBinding* serviceBinding); + + /** + * Returns the target service binding. + */ + ServiceBinding* getTargetServiceBinding() const { return targetServiceBinding; }; + + private: + + /** + * The proxy representing the reference to the client + * component. + */ + ServiceProxy* serviceProxy; + + /** + * The service binding of the target + */ + ServiceBinding* targetServiceBinding; + }; + + } // End namespace python + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_python_model_pythonreferencebinding_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonServiceBinding.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonServiceBinding.cpp new file mode 100644 index 0000000000..544682c18e --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonServiceBinding.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/python/model/PythonServiceBinding.h" +#include "tuscany/sca/python/PythonServiceWrapper.h" + +namespace tuscany +{ + namespace sca + { + namespace python + { + + // Constructor + PythonServiceBinding::PythonServiceBinding(Service* service) + : ServiceBinding(service, "") + { + LOGENTRY(1,"PythonServiceBinding::constructor"); + serviceWrapper = new PythonServiceWrapper(service); + LOGEXIT(1,"PythonServiceBinding::constructor"); + } + + // Destructor + PythonServiceBinding::~PythonServiceBinding() + { + LOGENTRY(1,"PythonServiceBinding::destructor"); + LOGEXIT(1,"PythonServiceBinding::destructor"); + } + + ServiceWrapper* PythonServiceBinding::getServiceWrapper() + { + LOGENTRY(1,"PythonServiceBinding::getServiceWrapper"); + LOGEXIT(1,"PythonServiceBinding::getServiceWrapper"); + return (ServiceWrapper*)serviceWrapper; + } + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonServiceBinding.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonServiceBinding.h new file mode 100644 index 0000000000..f2d64b3edc --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonServiceBinding.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_python_model_pythonservicebinding_h +#define tuscany_sca_python_model_pythonservicebinding_h + +#include "tuscany/sca/model/ServiceBinding.h" +using namespace tuscany::sca::model; +#include <string> +using std::string; + +namespace tuscany +{ + namespace sca + { + namespace python + { + /** + * Information about a Python service binding for service or a reference. + */ + class PythonServiceBinding : public ServiceBinding + { + public: + + /** + * Constructor. + * @param uri The uri of the binding. + * @param port The definition of the port to which the entrypoint + * or external service is to be bound. This is of the form + * "namespace"#endpoint("service"/"port") + */ + PythonServiceBinding(Service* service); + + /** + * Destructor. + */ + virtual ~PythonServiceBinding(); + + /** + * Returns the type of binding. + */ + virtual string getType() { return "http://www.osoa.org/xmlns/sca/1.0#PythonImplementationBinding"; }; + + /** + * Create a wrapper for the service configured by this + * binding. + */ + virtual ServiceWrapper* getServiceWrapper(); + + private: + + /** + * The wrapper for the service configured by this binding. + */ + ServiceWrapper* serviceWrapper; + + }; + + } // End namespace python + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_python_model_pythonservicebinding_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/sca_module.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/sca_module.cpp new file mode 100644 index 0000000000..d3a92ba57b --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/sca_module.cpp @@ -0,0 +1,380 @@ +/* + * 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 <Python.h> + +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/model/ServiceBinding.h" +#include "tuscany/sca/core/Operation.h" +using namespace tuscany::sca; +using namespace tuscany::sca::model; + +#include "PythonServiceProxy.h" +using namespace tuscany::sca::python; + +#include "tuscany/sca/util/Logging.h" + +#include <string> +#include <iostream> +using namespace std; + +static PyObject* scaError; + +/** +* Prints out PyObject and dir(PyObject) +* for debugging purposes +*/ +static void printPyObject(char* prefix, char* name, PyObject* pObj) +{ + LOGINFO(4, "Entering printPyObject"); + PyObject* pObjRepr = PyObject_Repr(pObj); + LOGINFO_3(4, "%s printPyObject %s: %s", prefix, name, PyString_AsString(pObjRepr)); + Py_XDECREF(pObjRepr); + + if(pObj != NULL) + { + PyObject* pObjDir = PyObject_Dir(pObj); + PyObject* pObjDirRepr = PyObject_Repr(pObjDir); + LOGINFO_3(4, "%s printPyObject dir(%s): %s", prefix, name, PyString_AsString(pObjDirRepr)); + Py_DECREF(pObjDirRepr); + Py_DECREF(pObjDir); + } + LOGINFO(4, "Returning from printPyObject"); +} + +static PyObject* sca_locateservice(PyObject *self, PyObject *args) +{ + // Get the service name + PyObject* pServiceName = PyTuple_GetItem(args, 0); + + // Import the SCA python-extension module + PyObject* pModuleName = PyString_FromString("sca_proxy"); + PyObject* sca_proxy_module = PyImport_Import(pModuleName); + Py_DECREF(pModuleName); + + if(!sca_proxy_module) + { + if(PyErr_Occurred()) + { + PyErr_Print(); + } + string msg = "Failed to load the sca_proxy Python module - has it been successfully installed?\nReferences from Python components will not be supported"; + LOGERROR(0, msg.c_str()); + } + else + { + // Get the sca_proxy class + PyObject* sca_proxy_class = PyObject_GetAttrString(sca_proxy_module, "sca_proxy_class"); + + PyObject* scaArgs = PyTuple_New(2); + PyTuple_SetItem(scaArgs, 0, pServiceName); + Py_INCREF(Py_True); + PyTuple_SetItem(scaArgs, 1, Py_False); + + // Create the instance of the scaReference class + PyObject* sca_proxy_classInstance = PyInstance_New(sca_proxy_class, scaArgs, NULL); + Py_DECREF(scaArgs); + + return sca_proxy_classInstance; + } + + Py_INCREF(Py_None); + return Py_None; +} + + +static PythonServiceProxy* getServiceProxy(PyObject *args) +{ + LOGENTRY(1, "sca_module getPythonServiceProxy"); + + PythonServiceProxy* serviceProxy = NULL; + SCARuntime* runtime = SCARuntime::getInstance(); + + // The first argument holds the name + string name; + PyObject* pName = PyTuple_GetItem(args, 0); + if(pName && PyString_Check(pName)) + { + name = PyString_AsString(pName); + } + if(name.size() > 0) + { + LOGINFO_1(3, "sca_invoke Service/Reference name is %s", name.c_str()); + } + else + { + string msg = "sca_invoke Service/Reference name has not been set"; + LOGERROR(1, msg.c_str()); + PyErr_SetString(scaError, msg.c_str()); + return NULL; + } + + // The second argument is a boolean + PyObject* isReference = PyTuple_GetItem(args, 1); + + // Get the serviceProxy from the reference or service name provided + if(PyObject_IsTrue(isReference)) + { + Component* component = runtime->getCurrentComponent(); + Reference* ref = component->findReference(name); + if(!ref) + { + string msg = "sca_invoke Could not find the reference named "+name; + LOGERROR(1, msg.c_str()); + PyErr_SetString(scaError, msg.c_str()); + + return NULL; + } + + ReferenceBinding* refBinding = ref->getBinding(); + serviceProxy = (PythonServiceProxy*) refBinding->getServiceProxy(); + } + else + { + Component* component = runtime->getDefaultComponent(); + Composite* composite = (Composite*)component->getType(); + Service* service = composite->findComponentService(name); + + if(!service) + { + string msg = "sca_invoke Could not find the service named "+name; + LOGERROR(1, msg.c_str()); + PyErr_SetString(scaError, msg.c_str()); + return NULL; + } + + serviceProxy = new PythonServiceProxy(service); + } + + return serviceProxy; +} + + +static PyObject* sca_invoke(PyObject *self, PyObject *args) +{ + LOGENTRY(1, "sca_invoke"); + + PythonServiceProxy* pythonServiceProxy = getServiceProxy(args); + if(!pythonServiceProxy) + { + return NULL; + } + + // Get the name of the operation to invoke + string operationName; + PyObject* opName = PyTuple_GetItem(args, 2); + if(opName && PyString_Check(opName)) + { + operationName = PyString_AsString(opName); + } + + if(operationName.size() > 0) + { + LOGINFO_1(3, "sca_invoke Operation name is %s", operationName.c_str()); + } + else + { + string msg = "sca_invoke Operation name has not been set"; + LOGERROR(1, msg.c_str()); + PyErr_SetString(scaError, msg.c_str()); + return NULL; + } + + // Create the Operation object + Operation operation(operationName.c_str()); + + // Parameters are the fourth argument + PyObject* paramTuple = PyTuple_GetItem(args, 3); + + // Go through the supplied parameters + for(int i=0; i < PyTuple_Size(paramTuple); i++) + { + PyObject* param = PyTuple_GetItem(paramTuple, i); + + if(PyInt_Check(param)) + { + LOGINFO_2(3, "sca_invoke Param %d is int type: %d", i, PyInt_AsLong(param)); + long* intData = new long; + *intData = PyInt_AsLong(param); + operation.addParameter(intData); + } + else if(PyBool_Check(param)) + { + LOGINFO_2(3, "sca_invoke Param %d is bool type: %d", i, (param == Py_True)); + bool* boolData = new bool; + *boolData = (param == Py_True); + operation.addParameter(boolData); + } + else if(PyLong_Check(param)) + { + LOGINFO_2(3, "sca_invoke Param %d is long type: %l", i, PyLong_AsLong(param)); + long* longData = new long; + *longData = PyLong_AsLong(param); + operation.addParameter(longData); + } + else if(PyFloat_Check(param)) + { + LOGINFO_2(3, "sca_invoke Param %d is float type: %f", i, PyFloat_AsDouble(param)); + double* doubleData = new double; + *doubleData = PyFloat_AsDouble(param); + operation.addParameter(doubleData); + } + else if(PyString_Check(param)) + { + LOGINFO_2(3, "sca_invoke %d is string type: %s", i, PyString_AsString(param)); + const char** stringData = new const char*; + *stringData = PyString_AsString(param); + operation.addParameter(stringData); + } + else + { + PyObject* paramRepr = PyObject_Repr(param); + PyObject* paramType = PyObject_Type(param); + PyObject* paramTypeRepr = PyObject_Repr(paramType); + + string msg = "sca_invoke Param "; + msg += i; + msg += "is of unknown type ("; + msg += PyString_AsString(paramTypeRepr); + msg += ") and has repr: "; + msg += PyString_AsString(paramRepr); + + LOGERROR(1, msg.c_str()); + PyErr_SetString(scaError, msg.c_str()); + + Py_DECREF(paramTypeRepr); + Py_DECREF(paramType); + Py_DECREF(paramRepr); + + return NULL; + } + } + + PyObject* returnValue = NULL; + + try + { + // Invoke the wired service + pythonServiceProxy->invokeService(operation); + } + catch(...) + { + string msg = "sca_invoke Exception thrown whilst invoking the service"; + LOGERROR(1, msg.c_str()); + PyErr_SetString(scaError, msg.c_str()); + return NULL; + } + + + switch(operation.getReturnType()) + { + case Operation::BOOL: + { + if(*(bool*)operation.getReturnValue()) + { + returnValue = Py_True; + } + else + { + returnValue = Py_False; + } + break; + } + case Operation::SHORT: + { + returnValue = PyInt_FromLong(*(short*)operation.getReturnValue()); + break; + } + case Operation::LONG: + { + returnValue = PyLong_FromLong(*(long*)operation.getReturnValue()); + break; + } + case Operation::USHORT: + { + returnValue = PyInt_FromLong(*(unsigned short*)operation.getReturnValue()); + break; + } + case Operation::ULONG: + { + returnValue = PyLong_FromLong(*(unsigned long*)operation.getReturnValue()); + break; + } + case Operation::FLOAT: + { + returnValue = PyFloat_FromDouble(*(float*)operation.getReturnValue()); + break; + } + case Operation::DOUBLE: + { + returnValue = PyFloat_FromDouble(*(double*)operation.getReturnValue()); + break; + } + case Operation::LONGDOUBLE: + { + returnValue = PyFloat_FromDouble(*(long double*)operation.getReturnValue()); + break; + } + case Operation::CHARS: + { + returnValue = PyString_FromString(*(char**)operation.getReturnValue()); + break; + } + case Operation::STRING: + { + returnValue = PyString_FromString((*(string*)operation.getReturnValue()).c_str()); + break; + } + default: + { + Py_INCREF(Py_None); + returnValue = Py_None; + } + + } + + LOGEXIT(1, "sca_invoke"); + return returnValue; +} +static PyMethodDef ModuleMethods[] = +{ + {"locateservice", sca_locateservice, METH_VARARGS, "Locates an SCA service & returns an sca_proxy_class instance"}, + {"invoke", sca_invoke, METH_VARARGS, "Invoke an operation on an SCA service or reference"}, + {NULL, NULL, 0, NULL} /* Sentinel */ +}; + +PyMODINIT_FUNC initsca(void) +{ + LOGENTRY(1, "initsca"); + + // Create a new module + PyObject* module = Py_InitModule("sca", ModuleMethods); + + scaError = PyErr_NewException("sca.error", NULL, NULL); + Py_INCREF(scaError); + PyModule_AddObject(module, "error", scaError); + + LOGEXIT(1, "initsca"); +} diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/sca_proxy.py b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/sca_proxy.py new file mode 100644 index 0000000000..1846bf994d --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/sca_proxy.py @@ -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.
+#
+#
+#
+#
+# This Python code is used in the SCA package and
+# provides the proxy objects to a Python SCA component or SCA
+# client.
+#
+# This is done by overloading the __getattr__ method which makes
+# calls to myProxy.anyMethod go to __getattr__ which will return
+# the invokeFunction defined inside the invoke method
+
+import sca
+
+class sca_proxy_class:
+
+ sca_proxy_name = ''
+ sca_proxy_is_reference = 1
+
+ def __init__(self, name, isReference):
+ self.sca_proxy_name = name
+ self.sca_proxy_is_reference = isReference
+ return
+
+ def invoke(self, operationName):
+
+ def invokeFunction(*args,**kwargs):
+ return sca.invoke(self.sca_proxy_name, self.sca_proxy_is_reference, operationName, args)
+
+ return invokeFunction
+
+ def __getattr__(self, operationName):
+ return self.invoke(operationName)
+
+ def __str__(self):
+ return '<sca_proxy.sca_proxy_class instance for ' + self.sca_proxy_name + '>'
+
+ def __repr__(self):
+ return '<sca_proxy.sca_proxy_class instance for ' + self.sca_proxy_name + '>'
+
diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/sca_setup.py b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/sca_setup.py new file mode 100644 index 0000000000..9363d5533f --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/src/tuscany/sca/python/sca_setup.py @@ -0,0 +1,60 @@ +# 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.
+#
+#
+#
+#
+# This Python code builds and/or installs the sca and
+# sca_proxy extension modules
+#
+# Build/install with the following comands:
+# python scaSetup.py build
+# python scaSetup.py install
+#
+#
+
+from distutils.core import setup, Extension, os
+
+TUSCANY_SCACPP = os.environ.get("TUSCANY_SCACPP")
+print 'Using TUSCANY_SCACPP at ' + TUSCANY_SCACPP
+
+TUSCANY_SDOCPP = os.environ.get("TUSCANY_SDOCPP")
+print 'Using TUSCANY_SDOCPP at ' + TUSCANY_SDOCPP
+
+macros = []
+if os.name == 'nt':
+ macros = [ ('WIN32',None) ]
+
+module1 = Extension('sca',
+ define_macros = macros,
+ sources = ['sca_module.cpp'],
+ include_dirs = [ TUSCANY_SCACPP + '/include',
+ TUSCANY_SCACPP + '/extensions/python/include',
+ TUSCANY_SDOCPP + '/include'],
+ libraries = ['tuscany_sca',
+ 'tuscany_sdo',
+ 'tuscany_sca_python'],
+ library_dirs = [ TUSCANY_SCACPP + '/lib',
+ TUSCANY_SCACPP + '/extensions/python/lib',
+ TUSCANY_SDOCPP + '/lib'])
+
+setup (name = 'sca',
+ version = '1.0',
+ description = 'The Tuscany SCA package',
+ url='http://incubator.apache.org/tuscany/',
+ ext_modules = [module1],
+ py_modules = ['sca_proxy'])
diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/xsd/sca-implementation-python.xsd b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/xsd/sca-implementation-python.xsd new file mode 100644 index 0000000000..e1c7247992 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/xsd/sca-implementation-python.xsd @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.osoa.org/xmlns/sca/1.0" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + elementFormDefault="qualified"> + + + <element name="implementation.python" type="sca:PythonImplementation" substitutionGroup="sca:implementation"/> + <complexType name="PythonImplementation"> + <complexContent> + <extension base="sca:Implementation"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> + </sequence> + <attribute name="module" type="NCName" use="required"/> + <attribute name="path" type="NCName" use="optional"/> + <attribute name="class" type="Name" use="optional"/> + <attribute name="scope" type="sca:PythonImplementationScope" use="optional" /> + <anyAttribute namespace="##any" processContents="lax"/> + </extension> + </complexContent> + </complexType> + + <simpleType name="PythonImplementationScope"> + <restriction base="string"> + <enumeration value="stateless" /> + <enumeration value="composite" /> + </restriction> + </simpleType> +</schema> diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/xsd/sca-interface-python.xsd b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/xsd/sca-interface-python.xsd new file mode 100644 index 0000000000..dd9075c7fb --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/python/xsd/sca-interface-python.xsd @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.osoa.org/xmlns/sca/1.0" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + elementFormDefault="qualified"> + + <element name="interface.python" type="sca:PythonInterface" substitutionGroup="sca:interface"/> + <complexType name="PythonInterface"> + <complexContent> + <extension base="sca:Interface"> + <sequence> + <element name="operation" type="sca:PythonOperation" minOccurs="0" maxOccurs="unbounded" /> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> + </sequence> + <attribute name="remotable" type="boolean" use="optional" /> + <attribute name="conversational" type="boolean" use="optional" /> + <anyAttribute namespace="##any" processContents="lax" /> + </extension> + </complexContent> + </complexType> + + <complexType name="PythonOperation"> + <complexContent> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> + </sequence> + <attribute name="name" type="string" use="required" /> + <attribute name="returnType" type="sca:PythonReturnTypes" use="optional" /> + <anyAttribute namespace="##any" processContents="lax" /> + </complexContent> + </complexType> + + <simpleType name="PythonReturnTypes"> + <restriction base="string"> + <enumeration value="string" /> + <enumeration value="int" /> + <enumeration value="long" /> + <enumeration value="boolean" /> + <enumeration value="float" /> + <enumeration value="other" /> + </restriction> + </simpleType> +</schema> diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/Makefile.am new file mode 100644 index 0000000000..ac176d8811 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/Makefile.am @@ -0,0 +1,24 @@ +# 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 + +datadir=$(prefix)/extensions/ruby + +nobase_data_DATA = xsd/*.xsd + +EXTRA_DIST = xsd
\ No newline at end of file diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/deploy.bat b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/deploy.bat new file mode 100644 index 0000000000..e53a8780cf --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/deploy.bat @@ -0,0 +1,64 @@ +@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 extdir=%deploydir%\extensions +set rubyextdir=%extdir%\ruby +set srcdir=%rootdir%\runtime\extensions\ruby\src + +if . == .%2 ( +echo input directory not specified +goto usage +) +set inpath=%2 +echo %inpath% + + +if not exist %deploydir% mkdir %deploydir% +if not exist %extdir% mkdir %extdir% +if not exist %rubyextdir% mkdir %rubyextdir% +if not exist %rubyextdir%\bin mkdir %rubyextdir%\bin +if not exist %rubyextdir%\lib mkdir %rubyextdir%\lib +if not exist %rubyextdir%\xsd mkdir %rubyextdir%\xsd + +del %rubyextdir%\bin\tuscany_sca_ruby.* +del %rubyextdir%\lib\*.lib + +copy %srcdir%\deploy.cmd %rubyextdir% +copy %srcdir%\..\xsd\*.* %rubyextdir%\xsd + +copy %inpath%\tuscany_sca_ruby.lib %rubyextdir%\lib +copy %inpath%\tuscany_sca_ruby.dll %rubyextdir%\bin\tuscany_sca_ruby.dll.disabled + +if exist %inpath%\tuscany_sca_ruby.pdb copy %inpath%\tuscany_sca_ruby.pdb %rubyextdir%\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/extensions/ruby/src/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/Makefile.am new file mode 100644 index 0000000000..d73ac1f90c --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/Makefile.am @@ -0,0 +1,54 @@ +# 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. + +libdir=$(prefix)/extensions/ruby/lib +lib_LTLIBRARIES = libtuscany_sca_ruby.la + +install-exec-hook: + cd $(libdir); \ + ln -s -f libtuscany_sca_ruby.so tuscany_sca_ruby.so; \ + for i in libtuscany_sca_ruby.*; do mv $$i $$i.disabled; done + +rootdir=$(prefix)/extensions/ruby +root_SCRIPTS = deploy.sh + +noinst_HEADERS = \ +tuscany/sca/ruby/*.h \ +tuscany/sca/ruby/model/*.h + +EXTRA_DIST = deploy.sh + +libtuscany_sca_ruby_la_SOURCES = \ +tuscany/sca/ruby/RubyExtension.cpp \ +tuscany/sca/ruby/RubyImplementationExtension.cpp \ +tuscany/sca/ruby/RubyServiceProxy.cpp \ +tuscany/sca/ruby/RubyServiceWrapper.cpp \ +tuscany/sca/ruby/model/RubyImplementation.cpp \ +tuscany/sca/ruby/model/RubyReferenceBinding.cpp \ +tuscany/sca/ruby/model/RubyServiceBinding.cpp \ +tuscany/sca/ruby/RubyCompositeContext.cpp + +libtuscany_sca_ruby_la_LIBADD = -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo \ + -L$(top_builddir)/runtime/core/src -ltuscany_sca \ + -L${RUBY_LIB} -lruby + +INCLUDES = -Imodel -I$(top_builddir)/runtime/core/src \ + -I${TUSCANY_SDOCPP}/include \ + -I${RUBY_INCLUDE} + +AM_CPPFLAGS = $(CPPFLAGS) -D_DEBUG +
\ No newline at end of file diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/deploy.cmd b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/deploy.cmd new file mode 100644 index 0000000000..5baf8289e3 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/deploy.cmd @@ -0,0 +1,28 @@ +@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
+set currentPath=%~d0%~p0
+
+echo Enabling the Tuscany Ruby extension
+rename %currentPath%\bin\tuscany_sca_ruby.dll.disabled tuscany_sca_ruby.dll
+
+:end
+echo Done
+endlocal
diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/deploy.sh b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/deploy.sh new file mode 100755 index 0000000000..492b1b09d1 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/deploy.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# 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. + +APFULLDIR=`pwd` + +echo "Enabling the Tuscany Ruby extension" + +for i in lib/*.disabled; do x=${i%.disabled}; mv $i $x; done + +echo "Done" diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/Ruby.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/Ruby.h new file mode 100644 index 0000000000..a6b8ee8ffa --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/Ruby.h @@ -0,0 +1,39 @@ +/* + * 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_ruby_ruby_h +#define tuscany_sca_ruby_ruby_h + +// Ruby inists on MS VC6 ... we'll see about that! +#if defined(WIN32) || defined (_WINDOWS) +#define _REAL_MSC_VER _MSC_VER +#undef _MSC_VER +#define _MSC_VER 1200 +#endif + +#include <ruby.h> + +#if defined(WIN32) || defined (_WINDOWS) +#undef _MSC_VER +#define _MSC_VER _REAL_MSC_VER +#endif + +#endif // tuscany_sca_ruby_ruby_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyCompositeContext.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyCompositeContext.cpp new file mode 100644 index 0000000000..148bccc025 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyCompositeContext.cpp @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/ComponentType.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/ruby/RubyServiceProxy.h" + +using namespace tuscany::sca::ruby; + +extern "C" +{ + + // Implement the Sca::locateService module function + SCA_RUBY_API VALUE tuscany_sca_ruby_locateService(VALUE module, VALUE value) + { + + // Get the default component + Component* defaultComponent = tuscany::sca::SCARuntime::getInstance()->getDefaultComponent(); + Composite* composite = (Composite*)defaultComponent->getType(); + + // Locate the service + const char* serviceName = rb_string_value_cstr(&value); + Service* service = composite->findComponentService(serviceName); + string msg; + if (!service) + { + string msg = "Service not found: "; + msg = msg + serviceName; + rb_raise(rb_eRuntimeError, msg.c_str()); + } + + // Get a Proxy for this service + RubyServiceProxy* serviceProxy = new RubyServiceProxy(service); + + // Return the Ruby proxy value object + return serviceProxy->getProxyValue(); + } + + // Initialize the Ruby extension + SCA_RUBY_API void Init_tuscany_sca_ruby() + { + + // Define the Sca::locateService() function + VALUE module = rb_define_module("SCA"); + rb_define_module_function(module, "locateService", (VALUE(*)(ANYARGS))tuscany_sca_ruby_locateService, 1); + + } + + SCA_RUBY_API void Init_libtuscany_sca_ruby() + { + Init_tuscany_sca_ruby(); + } +} diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyExtension.cpp new file mode 100644 index 0000000000..7153ef4fb1 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyExtension.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/ruby/RubyExtension.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/ruby/RubyImplementationExtension.h" + + +extern "C" +{ + #if defined(WIN32) || defined(_WINDOWS) + __declspec(dllexport) + #endif + void tuscany_sca_extension_initialize() + { + tuscany::sca::ruby::RubyExtension::initialize(); + } +} + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + // =================================================================== + // Constructor for the RubyExtension class. + // =================================================================== + RubyExtension::RubyExtension() + { + LOGENTRY(1, "RubyExtension::constructor"); + LOGEXIT(1, "RubyExtension::constructor"); + } + + // =================================================================== + // Destructor for the RubyExtension class. + // =================================================================== + RubyExtension::~RubyExtension() + { + LOGENTRY(1, "RubyExtension::destructor");; + LOGEXIT(1, "RubyExtension::destructor"); + } + + void RubyExtension::initialize() + { + LOGENTRY(1, "RubyExtension::initialize");; + SCARuntime::getInstance()->registerImplementationExtension(new RubyImplementationExtension()); + LOGEXIT(1, "RubyExtension::initialize");; + } + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyExtension.h new file mode 100644 index 0000000000..232431ca1e --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyExtension.h @@ -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$ */ + + +#ifndef tuscany_sca_ruby_rubyextension_h +#define tuscany_sca_ruby_rubyextension_h + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + class RubyExtension + { + public: + /** + * Default constructor + */ + RubyExtension(); + + /** + * Destructor + */ + virtual ~RubyExtension(); + + static void initialize(); + + private: + + }; + + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_rubyextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.cpp new file mode 100644 index 0000000000..2bc5f9d0d9 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.cpp @@ -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$ */ + +#include "tuscany/sca/ruby/RubyImplementationExtension.h" +#include "tuscany/sca/ruby/model/RubyImplementation.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" + + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + // =================================================================== + // Constructor for the RubyImplementationExtension class. + // =================================================================== + RubyImplementationExtension::RubyImplementationExtension() + { + LOGENTRY(1, "RubyImplementationExtension::constructor"); + LOGEXIT(1, "RubyImplementationExtension::constructor"); + } + + // =================================================================== + // Destructor for the RubyImplementationExtension class. + // =================================================================== + RubyImplementationExtension::~RubyImplementationExtension() + { + LOGENTRY(1, "RubyImplementationExtension::destructor");; + LOGEXIT(1, "RubyImplementationExtension::destructor"); + } + + const string RubyImplementationExtension::extensionName("ruby"); + const string RubyImplementationExtension::typeQName("http://www.osoa.org/xmlns/sca/1.0#RubyImplementation"); + + // =================================================================== + // loadModelElement - load the info from implementation.ruby + // =================================================================== + ComponentType* RubyImplementationExtension::getImplementation(Composite *composite, DataObjectPtr scdlImplementation) + { + string implType = scdlImplementation->getType().getName(); + if (implType == "RubyImplementation") + { + string module = scdlImplementation->getCString("module"); + string className = scdlImplementation->getCString("class"); + string script = scdlImplementation->getCString("script"); + + RubyImplementation* rubyImpl = new RubyImplementation(composite, module, className, script); + + return rubyImpl; + } + else + { + return NULL; + } + } + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.h new file mode 100644 index 0000000000..a1c5f26a3e --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.h @@ -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$ */ + +#ifndef tuscany_sca_ruby_rubyimplementationextension_h +#define tuscany_sca_ruby_rubyimplementationextension_h + +#include "tuscany/sca/extension/ImplementationExtension.h" + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + class RubyImplementationExtension : public ImplementationExtension + { + public: + /** + * Default constructor + */ + RubyImplementationExtension(); + + /** + * Destructor + */ + virtual ~RubyImplementationExtension(); + + /** + * return the name of the extension + */ + virtual const string& getExtensionName() {return extensionName;} + + /** + * return the QName of schema elemant for this implementation extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#implementation.ruby") + */ + virtual const string& getExtensionTypeQName() {return typeQName;} + + virtual ComponentType* getImplementation(Composite* composite, DataObjectPtr scdlImplementation); + + private: + static const string extensionName; + static const string typeQName; + + }; + + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_rubyimplementationextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.cpp new file mode 100644 index 0000000000..228f1f8940 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.cpp @@ -0,0 +1,374 @@ +/* + * 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/ruby/RubyServiceProxy.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/util/Exceptions.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/ComponentType.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/ServiceBinding.h" +#include "tuscany/sca/ruby/model/RubyImplementation.h" +#include "tuscany/sca/ruby/model/RubyReferenceBinding.h" + +extern "C" +{ + + // Initialize a Ruby proxy + SCA_RUBY_API VALUE tuscany_sca_ruby_proxy_initialize(VALUE self, VALUE serviceProxy) + { + rb_iv_set(self, "@cppProxy", serviceProxy); + return self; + } + + // Handle a method_missing message and dispatch to + // our C++ proxy + SCA_RUBY_API VALUE tuscany_sca_ruby_proxy_method_missing(int argc, VALUE* argv, VALUE self) + { + VALUE proxy = rb_iv_get(self, "@cppProxy"); + + // Get the target service wrapper + tuscany::sca::ruby::RubyServiceProxy *serviceProxy; + Data_Get_Struct(proxy, tuscany::sca::ruby::RubyServiceProxy, serviceProxy); + + // Handle the invocation + return serviceProxy->invoke(argc, argv); + + } + +} + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + VALUE RubyServiceProxy::proxyClass = Qnil; + + // ============================ + // Constructor: Create a proxy + // ============================ + RubyServiceProxy::RubyServiceProxy(Reference* reference) + : ServiceProxy(reference) + { + LOGENTRY(1,"RubyServiceProxy::constructor"); + + // ---------------------- + // Get the component + // ---------------------- + component = reference->getComponent(); + string name = reference->getType()->getName(); + + // Get the service wrapper + RubyReferenceBinding* referenceBinding = (RubyReferenceBinding*)reference->getBinding(); + + serviceWrapper = referenceBinding->getTargetServiceBinding()->getServiceWrapper(); + + // Create the Ruby proxy + createProxy(); + + LOGEXIT(1,"RubyServiceProxy::constructor"); + } + + // ============================ + // Constructor: Create a proxy + // ============================ + RubyServiceProxy::RubyServiceProxy(Service* service) + : ServiceProxy(0) + { + LOGENTRY(1,"RubyServiceProxy::constructor"); + + // ---------------------- + // Get the component + // ---------------------- + component = service->getComponent(); + string name = service->getType()->getName(); + + // Get the service wrapper + serviceWrapper = service->getBinding()->getServiceWrapper(); + + // Create the Ruby proxy + createProxy(); + + LOGEXIT(1,"RubyServiceProxy::constructor"); + } + + // ========== + // Destructor + // ========== + RubyServiceProxy::~RubyServiceProxy() + { + LOGENTRY(1,"RubyServiceProxy::destructor"); + LOGEXIT(1,"RubyServiceProxy::destructor"); + } + + void RubyServiceProxy::createProxy() + { + // Create the Ruby proxy class + if (RubyServiceProxy::proxyClass == Qnil) + { + VALUE module = rb_define_module("Tuscany"); + proxyClass = rb_define_class_under(module, "ServiceProxy", rb_cObject); + rb_define_method(proxyClass, "initialize", (VALUE(*)(ANYARGS))tuscany_sca_ruby_proxy_initialize, 1); + rb_define_method(proxyClass, "method_missing", (VALUE(*)(ANYARGS))tuscany_sca_ruby_proxy_method_missing, -1); + } + + // Create the Ruby proxy instance, pass the service wrapper to it + VALUE* args = new VALUE[1]; + args[0] = Data_Wrap_Struct(rb_cObject, NULL, NULL, this); + proxyValue = rb_class_new_instance(1, args, proxyClass); + + // Mark proxyValue busy so that it doesn't get GC'ed by Ruby + rb_gc_register_address(&proxyValue); + } + + + VALUE RubyServiceProxy::invoke(int argc, VALUE* argv) + { + // Get the method name + char* methodName = rb_id2name(SYM2ID(argv[0])); + + // Get the block passed by the caller + VALUE block =rb_block_given_p() ? rb_block_proc() : Qnil; + + // Create new Operation object + Operation operation(methodName); + + // Convert the Ruby parameters to C++ + for (int i = 1; i < argc; i++) + { + VALUE value = argv[i]; + + int valueType = TYPE(value); + + switch (valueType) + { + case T_FLOAT: + { + float* data = new float; + *data = rb_num2dbl(value); + operation.addParameter(data); + break; + } + case T_STRING: + { + string* data = new string(rb_string_value_cstr(&value)); + const char** cdata = new const char*; + *cdata = data->c_str(); + operation.addParameter(cdata); + break; + } + case T_FIXNUM: + { + long* data = new long; + *data = rb_num2long(value); + operation.addParameter(data); + break; + } + case T_BIGNUM: + { + long double* data = new long double; + *data = rb_num2dbl(value); + operation.addParameter(data); + break; + } + case T_TRUE: + { + bool* data = new bool; + *data = true; + operation.addParameter(data); + break; + } + case T_FALSE: + { + bool* data = new bool; + *data = false; + operation.addParameter(data); + break; + } + case T_OBJECT: + { + VALUE klass = rb_obj_class(value); + if (klass == RubyImplementation::getXMLDocumentClass()) + { + // Convert a REXML::Document to a DataObject + ID to_s = rb_intern("to_s"); + VALUE vstr = rb_funcall(value, to_s, 0); + string str = string(rb_string_value_cstr(&vstr)); + + Composite* composite = getReference()->getComponent()->getComposite(); + commonj::sdo::XMLHelper* xmlHelper = composite->getXMLHelper(); + commonj::sdo::XMLDocumentPtr xmlDoc = xmlHelper->load(str.c_str()); + + DataObjectPtr dob; + if (xmlDoc != NULL) + { + dob = xmlDoc->getRootDataObject(); + } + if (dob != NULL) + { + operation.addParameter(&dob); + } + else + { + string msg = "Document could not be converted to a DataObject"; + rb_raise(rb_eTypeError, msg.c_str()); + return Qnil; + } + } + else + { + string msg = "Ruby type not supported: " + valueType; + rb_raise(rb_eTypeError, msg.c_str()); + return Qnil; + } + break; + } + default:; + string msg = "Ruby type not supported: " + valueType; + rb_raise(rb_eTypeError, msg.c_str()); + return Qnil; + } + + } + + try + { + // Call into the target service wrapper + serviceWrapper->invoke(operation); + + // Convert the result to a Ruby value + VALUE value; + Operation::ParameterType resultType = operation.getReturnType(); + switch(resultType) + { + case Operation::BOOL: + { + if( *(bool*)operation.getReturnValue()) + { + //boolean true + value = rb_int2inum(1); + } + else + { + value = rb_int2inum(0); + } + break; + } + case Operation::SHORT: + { + value = rb_int2inum(*(short*)operation.getReturnValue()); + break; + } + case Operation::USHORT: + { + value = rb_uint2inum(*(unsigned short*)operation.getReturnValue()); + break; + } + case Operation::LONG: + { + value = rb_int2inum(*(long*)operation.getReturnValue()); + break; + } + case Operation::ULONG: + { + value = rb_uint2inum(*(unsigned long*)operation.getReturnValue()); + break; + } + case Operation::FLOAT: + { + value = rb_float_new(*(float*)operation.getReturnValue()); + break; + } + case Operation::DOUBLE: + { + value = rb_float_new(*(double*)operation.getReturnValue()); + break; + } + case Operation::LONGDOUBLE: + { + value = rb_float_new(*(long double*)operation.getReturnValue()); + break; + } + case Operation::CHARS: + { + value = rb_str_new2(*(char**)operation.getReturnValue()); + break; + } + case Operation::STRING: + { + value = rb_str_new2((*(string*)operation.getReturnValue()).c_str()); + break; + } + case Operation::DATAOBJECT: + { + DataObjectPtr dob = *(DataObjectPtr*)operation.getReturnValue(); + + // Convert a DataObject to a REXML Document object + Composite* composite = component->getComposite(); + commonj::sdo::XMLHelper* xmlHelper = composite->getXMLHelper(); + char* str = xmlHelper->save( + dob, + dob->getType().getURI(), + dob->getType().getName()); + VALUE vstr[1]; + vstr[0] = rb_str_new2(str); + + value = rb_class_new_instance(1, vstr, RubyImplementation::getXMLDocumentClass()); + break; + } + default: + { + //throw new ComponentInvocationException("Operation parameter type not supported"); + string msg = "Operation parameter type not supported" + resultType; + rb_raise(rb_eRuntimeError, msg.c_str()); + return Qnil; + } + } + + return value; + + } + catch(TuscanyRuntimeException &ex) + { + string msg = "Exception while invoking a service: "; + msg += ex.getEClassName(); + msg += ": "; + msg += ex.getMessageText(); + rb_raise(rb_eRuntimeError, msg.c_str()); + return Qnil; + } + + return Qnil; + } + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.h new file mode 100644 index 0000000000..f4692733f1 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.h @@ -0,0 +1,117 @@ +/* + * 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_ruby_rubyserviceproxy_h +#define tuscany_sca_ruby_rubyserviceproxy_h + +#include "tuscany/sca/ruby/export.h" +#include "tuscany/sca/core/ServiceProxy.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/Service.h" + +using namespace tuscany::sca::model; + +#include "tuscany/sca/ruby/Ruby.h" + + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + /** + * 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 RubyServiceProxy : public 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. + */ + RubyServiceProxy(Reference* reference); + + /** + * Create a new service proxy for a service. The proxy will contain a pointer to + * the target ServiceWrapper. + * @param reference The service on the target component. + * @param target The wrapper of the target service. + */ + RubyServiceProxy(Service* service); + + /** + * Destructor. + */ + virtual ~RubyServiceProxy(); + + /** + * Returns the Ruby value of the proxy + */ + VALUE getProxyValue() const { return proxyValue; }; + + /** + * Handles the invocation of a Ruby method. + */ + VALUE invoke(int argc, VALUE* argv); + + private: + + /** + * Create the Ruby proxy object + */ + void createProxy(); + + /** + * The target service wrapper + */ + ServiceWrapper* serviceWrapper; + + /** + * The Ruby value of the proxy + */ + VALUE proxyValue; + + /** + * The component owning the proxy + */ + Component* component; + + /** + * The Ruby proxy class + */ + static VALUE proxyClass; + + }; + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_rubyserviceproxy_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp new file mode 100644 index 0000000000..a0eb97142d --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp @@ -0,0 +1,724 @@ +/* + * 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/ruby/RubyServiceWrapper.h" + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/util/Library.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/ruby/model/RubyImplementation.h" +#include "tuscany/sca/ruby/model/RubyServiceBinding.h" +#include "tuscany/sca/ruby/RubyServiceProxy.h" +#include "commonj/sdo/SDO.h" + +using commonj::sdo::PropertyList; + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + // =========== + // Constructor + // =========== + RubyServiceWrapper::RubyServiceWrapper(Service* service) + : ServiceWrapper(service) + { + LOGENTRY(1,"RubyServiceWrapper::constructor"); + + component = service->getComponent(); + implementation = (RubyImplementation*)component->getType(); + interf = service->getType()->getInterface(); + + LOGEXIT(1,"RubyServiceWrapper::constructor"); + + } + + // ========== + // Destructor + // ========== + RubyServiceWrapper::~RubyServiceWrapper() + { + LOGENTRY(1,"RubyServiceWrapper::destructor"); + LOGEXIT(1,"RubyServiceWrapper::destructor"); + } + + // ====================================================================== + // invoke: wrapper call to service with setting the component context + // ====================================================================== + void RubyServiceWrapper::invoke(Operation& operation) + { + LOGENTRY(1,"RubyServiceWrapper::invoke"); + + SCARuntime* runtime = SCARuntime::getInstance(); + runtime->setCurrentComponent(component); + + try + { + + // Create a new instance of the Ruby implementation class + VALUE instance = rb_class_new_instance(0, NULL, implementation->getImplementationClass()); + + // Set all the references + const Component::REFERENCE_MAP& references = component->getReferences(); + Component::REFERENCE_MAP::const_iterator refiter = references.begin(); + for (int ri=0; ri< references.size(); ri++) + { + Reference* reference = refiter->second; + RubyServiceProxy* proxy = (RubyServiceProxy*)reference->getBinding()->getServiceProxy(); + if (proxy != NULL) + { + VALUE proxyValue = proxy->getProxyValue(); + string varName = "@" + refiter->first; + rb_iv_set(instance, varName.c_str(), proxyValue); + } + refiter++; + } + + // Set all the configured properties + DataObjectPtr properties = component->getProperties(); + PropertyList pl = properties->getInstanceProperties(); + for (int i = 0; i < pl.size(); i++) + { + if (properties->isSet(pl[i])) + { + string varName = "@"; + varName += pl[i].getName(); + string cstr = properties->getCString(pl[i]); + VALUE propertyValue; + if (cstr == "true") + { + propertyValue = Qtrue; + } + else if (cstr == "false") + { + propertyValue = Qfalse; + } + else + { + //TODO use one of the rb_str_to_inum() functions + // to convert a numeric value to a Ruby numeric + propertyValue = rb_str_new2(cstr.c_str()); + } + rb_iv_set(instance, varName.c_str(), propertyValue); + } + } + + // Get the ID of the specified method + ID method = rb_intern(operation.getName().c_str()); + + // Convert C++ parameters to Ruby parameters + VALUE *args = NULL; + int n = operation.getNParms(); + if (n != 0) + { + args=new VALUE[n]; + + for(int i = 0; i < operation.getNParms(); i++) + { + VALUE value; + + const Operation::Parameter& parm = operation.getParameter(i); + Operation::ParameterType parmType = parm.getType(); + switch(parmType) + { + case Operation::BOOL: + { + if( *(bool*)parm.getValue()) + { + //boolean true + value = rb_int2inum(1); + } + else + { + value = rb_int2inum(0); + } + break; + } + case Operation::SHORT: + { + value = rb_int2inum(*(short*)parm.getValue()); + break; + } + case Operation::USHORT: + { + value = rb_uint2inum(*(unsigned short*)parm.getValue()); + break; + } + case Operation::LONG: + { + value = rb_int2inum(*(long*)parm.getValue()); + break; + } + case Operation::ULONG: + { + value = rb_uint2inum(*(unsigned long*)parm.getValue()); + break; + } + case Operation::FLOAT: + { + value = rb_float_new(*(float*)parm.getValue()); + break; + } + case Operation::DOUBLE: + { + value = rb_float_new(*(double*)parm.getValue()); + break; + } + case Operation::LONGDOUBLE: + { + value = rb_float_new(*(long double*)parm.getValue()); + break; + } + case Operation::CHARS: + { + value = rb_str_new2(*(char**)parm.getValue()); + break; + } + case Operation::STRING: + { + value = rb_str_new2((*(string*)parm.getValue()).c_str()); + break; + } + case Operation::DATAOBJECT: + { + DataObjectPtr dob = *(DataObjectPtr*)parm.getValue(); + + // Convert a DataObject to a REXML Document object + Composite* composite = component->getComposite(); + commonj::sdo::XMLHelper* xmlHelper = composite->getXMLHelper(); + char* str = xmlHelper->save( + dob, + dob->getType().getURI(), + dob->getType().getName()); + VALUE vstr[1]; + vstr[0] = rb_str_new2(str); + + value = rb_class_new_instance(1, vstr, RubyImplementation::getXMLDocumentClass()); + break; + } + default: + { + //throw new ComponentInvocationException("Operation parameter type not supported"); + string msg = "Operation parameter type not supported" + parmType; + throw msg.c_str(); + } + } + + args[i] = value; + } + } + + + // Invoke the specified method + VALUE result; + if (n == 0) + { + result = rb_funcall(instance, method, 0); + } + else + { + result = rb_funcall2(instance, method, n, args); + } + + // Convert the Ruby result value to a C++ result + int resultType = TYPE(result); + char buf[20]; + switch(resultType) + { + case T_FLOAT: + { + float* data = new float; + *data = rb_num2dbl(result); + + // Check if the return type has already been set for typed languages + switch(operation.getReturnType()) + { + case Operation::BOOL: + { + *(bool*)operation.getReturnValue() = (*data != 0.0); + break; + } + case Operation::SHORT: + { + *(short*)operation.getReturnValue() = (short)*data; + break; + } + case Operation::USHORT: + { + *(unsigned short*)operation.getReturnValue() = (unsigned short)*data; + break; + } + case Operation::INT: + { + *(int*)operation.getReturnValue() = (int)*data; + break; + } + case Operation::UINT: + { + *(unsigned int*)operation.getReturnValue() = (unsigned int)*data; + break; + } + case Operation::LONG: + { + *(long*)operation.getReturnValue() = (long)*data; + break; + } + case Operation::ULONG: + { + *(unsigned long*)operation.getReturnValue() = (unsigned long)*data; + break; + } + case Operation::FLOAT: + { + *(float*)operation.getReturnValue() = (float)*data; + break; + } + case Operation::DOUBLE: + { + *(double*)operation.getReturnValue() = (double)*data; + break; + } + case Operation::LONGDOUBLE: + { + *(long double*)operation.getReturnValue() = (long double)*data; + break; + } + case Operation::CHARS: + { + sprintf(buf, "%f", *data); + *(char**)operation.getReturnValue() = buf; + break; + } + case Operation::STRING: + { + sprintf(buf, "%f", *data); + *(string*)operation.getReturnValue() = buf; + break; + } + default: + { + // The type is set as something else or has not been set + operation.setReturnValue(data); + } + } + break; + } + case T_STRING: + { + string* stringdata = new string(rb_string_value_cstr(&result)); + const char** data = new const char*; + *data = stringdata->c_str(); + + // Check if the return type has already been set (for typed languages) + switch(operation.getReturnType()) + { + case Operation::BOOL: + { + // If the string is empty or "0" or "false" set to false, otherwise true + if(strlen(*data) == 0 || strcmp(*data, "0") == 0 || strcmp(*data, "false") == 0) + { + *(bool*)operation.getReturnValue() = false; + } + else + { + *(bool*)operation.getReturnValue() = true; + } + break; + } + case Operation::SHORT: + { + *(short*)operation.getReturnValue() = (short)atoi(*data); + break; + } + case Operation::USHORT: + { + *(unsigned short*)operation.getReturnValue() = (unsigned short)atoi(*data); + break; + } + case Operation::INT: + { + *(int*)operation.getReturnValue() = (int)atoi(*data); + break; + } + case Operation::UINT: + { + *(unsigned int*)operation.getReturnValue() = (unsigned int)atoi(*data); + break; + } + case Operation::LONG: + { + *(long*)operation.getReturnValue() = (long)atol(*data); + break; + } + case Operation::ULONG: + { + *(unsigned long*)operation.getReturnValue() = (unsigned long)atol(*data); + break; + } + case Operation::FLOAT: + { + *(float*)operation.getReturnValue() = (float)atof(*data); + break; + } + case Operation::DOUBLE: + { + *(double*)operation.getReturnValue() = (double)atof(*data); + break; + } + case Operation::LONGDOUBLE: + { + *(long double*)operation.getReturnValue() = (long double)atof(*data); + break; + } + case Operation::CHARS: + { + *(const char**)operation.getReturnValue() = *data; + break; + } + case Operation::STRING: + { + *(string*)operation.getReturnValue() = *data; + break; + } + default: + { + // The type is set as something else or has not been set + operation.setReturnValue(data); + } + } + break; + } + case T_FIXNUM: + { + long* data = new long; + *data = rb_num2long(result); + + // Check if the return type has already been (set for typed languages) + switch(operation.getReturnType()) + { + case Operation::BOOL: + { + *(bool*)operation.getReturnValue() = (*data != 0); + break; + } + case Operation::SHORT: + { + *(short*)operation.getReturnValue() = (short)*data; + break; + } + case Operation::USHORT: + { + *(unsigned short*)operation.getReturnValue() = (unsigned short)*data; + break; + } + case Operation::INT: + { + *(int*)operation.getReturnValue() = (int)*data; + break; + } + case Operation::UINT: + { + *(unsigned int*)operation.getReturnValue() = (unsigned int)*data; + break; + } + case Operation::LONG: + { + *(long*)operation.getReturnValue() = (long)*data; + break; + } + case Operation::ULONG: + { + *(unsigned long*)operation.getReturnValue() = (unsigned long)*data; + break; + } + case Operation::FLOAT: + { + *(float*)operation.getReturnValue() = (float)*data; + break; + } + case Operation::DOUBLE: + { + *(double*)operation.getReturnValue() = (double)*data; + break; + } + case Operation::LONGDOUBLE: + { + *(long double*)operation.getReturnValue() = (long double)*data; + break; + } + case Operation::CHARS: + { + sprintf(buf, "%d", *data); + *(char**)operation.getReturnValue() = buf; + break; + } + case Operation::STRING: + { + sprintf(buf, "%d", *data); + *(string*)operation.getReturnValue() = buf; + break; + } + default: + { + // The type is set as something else or has not been set + operation.setReturnValue(data); + } + } + + break; + } + case T_BIGNUM: + { + long double* data = new long double; + *data = rb_num2dbl(result); + + // Check if the return type has already been set (for typed languages) + switch(operation.getReturnType()) + { + case Operation::BOOL: + { + *(bool*)operation.getReturnValue() = (*data != 0.0); + break; + } + case Operation::SHORT: + { + *(short*)operation.getReturnValue() = (short)*data; + break; + } + case Operation::USHORT: + { + *(unsigned short*)operation.getReturnValue() = (unsigned short)*data; + break; + } + case Operation::INT: + { + *(int*)operation.getReturnValue() = (int)*data; + break; + } + case Operation::UINT: + { + *(unsigned int*)operation.getReturnValue() = (unsigned int)*data; + break; + } + case Operation::LONG: + { + *(long*)operation.getReturnValue() = (long)*data; + break; + } + case Operation::ULONG: + { + *(unsigned long*)operation.getReturnValue() = (unsigned long)*data; + break; + } + case Operation::FLOAT: + { + *(float*)operation.getReturnValue() = (float)*data; + break; + } + case Operation::DOUBLE: + { + *(double*)operation.getReturnValue() = (double)*data; + break; + } + case Operation::LONGDOUBLE: + { + *(long double*)operation.getReturnValue() = (long double)*data; + break; + } + case Operation::CHARS: + { + sprintf(buf, "%f", *data); + *(char**)operation.getReturnValue() = buf; + break; + } + case Operation::STRING: + { + sprintf(buf, "%f", *data); + *(string*)operation.getReturnValue() = buf; + break; + } + default: + { + // The type is set as something else or has not been set + operation.setReturnValue(data); + } + } + break; + } + case T_TRUE: + case T_FALSE: + { + bool* data = new bool; + *data = (resultType == T_TRUE); + // Check if the return type has already been set (for typed languages) + switch(operation.getReturnType()) + { + case Operation::BOOL: + { + *(bool*)operation.getReturnValue() = *data; + break; + } + case Operation::SHORT: + { + *(short*)operation.getReturnValue() = (short)*data; + break; + } + case Operation::USHORT: + { + *(unsigned short*)operation.getReturnValue() = (unsigned short)*data; + break; + } + case Operation::INT: + { + *(int*)operation.getReturnValue() = (int)*data; + break; + } + case Operation::UINT: + { + *(unsigned int*)operation.getReturnValue() = (unsigned int)*data; + break; + } + case Operation::LONG: + { + *(long*)operation.getReturnValue() = (long)*data; + break; + } + case Operation::ULONG: + { + *(unsigned long*)operation.getReturnValue() = (unsigned long)*data; + break; + } + case Operation::FLOAT: + { + *(float*)operation.getReturnValue() = (float)*data; + break; + } + case Operation::DOUBLE: + { + *(double*)operation.getReturnValue() = (double)*data; + break; + } + case Operation::LONGDOUBLE: + { + *(long double*)operation.getReturnValue() = (long double)*data; + break; + } + case Operation::CHARS: + { + if(*data) + { + *(char**)operation.getReturnValue() = "true"; + } + else + { + *(char**)operation.getReturnValue() = "false"; + } + break; + } + case Operation::STRING: + { + if(*data) + { + *(string*)operation.getReturnValue() = "true"; + } + else + { + *(string*)operation.getReturnValue() = "false"; + } + break; + } + default: + { + // The type is set as something else or has not been set + operation.setReturnValue(data); + } + } + + break; + } + case T_OBJECT: + { + VALUE klass = rb_obj_class(result); + if (klass == RubyImplementation::getXMLDocumentClass()) + { + // Convert a REXML::Document to a DataObject + ID to_s = rb_intern("to_s"); + VALUE vstr = rb_funcall(result, to_s, 0); + string str = string(rb_string_value_cstr(&vstr)); + + Composite* composite = component->getComposite(); + commonj::sdo::XMLHelper* xmlHelper = composite->getXMLHelper(); + commonj::sdo::XMLDocumentPtr xmlDoc = xmlHelper->load(str.c_str()); + + DataObjectPtr dob; + if (xmlDoc != NULL) + { + dob = xmlDoc->getRootDataObject(); + } + if (dob != NULL) + { + operation.setReturnValue(&dob); + } + else + { + string msg = "Document could not be converted to a DataObject"; + throw msg.c_str(); + } + } + else + { + string msg = "Ruby type not supported: " + resultType; + throw msg.c_str(); + } + break; + } + default: + { + string msg = "Ruby type not supported: " + resultType; + throw msg.c_str(); + } + } + + } + catch (...) + { + runtime->unsetCurrentComponent(); + throw; + } + runtime->unsetCurrentComponent(); + LOGEXIT(1,"RubyServiceWrapper::invoke"); + + } + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.h new file mode 100644 index 0000000000..849bbdd33e --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.h @@ -0,0 +1,96 @@ +/* + * 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_ruby_rubyservicewrapper_h +#define tuscany_sca_ruby_rubyservicewrapper_h + +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/core/Operation.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Interface.h" +#include "tuscany/sca/ruby/model/RubyImplementation.h" +#include "tuscany/sca/ruby/export.h" + +#include "tuscany/sca/ruby/Ruby.h" + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + class RubyInterface; + + /** + * Wraps the service on a component implementation. + * This abstract class is extended by generated code which provides + * the implementation of some of the methods. + * An instance of this class wraps the actual component implementation which + * has been written by a developer of an SCA application. + */ + class SCA_RUBY_API RubyServiceWrapper : public ServiceWrapper + { + public: + + /** + * Constructor. + * @param target The component service to which this wrapper refers. + */ + RubyServiceWrapper(Service* service); + + /** + * Destructor. + */ + virtual ~RubyServiceWrapper(); + + /** + * All business method calls to the target component go through the invoke method. + * @param operation The details of the method, paramaters and return value for the + * business method to be called on the target component. + */ + virtual void invoke(Operation& operation); + + private: + + /** + * The component to which this wrapper refers. + */ + Component* component; + + /** + * A pointer to the interface which the service exposes. + */ + Interface* interf; + + /** + * The Ruby implementation + */ + RubyImplementation* implementation; + + }; + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_rubyservicewrapper_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/export.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/export.h new file mode 100644 index 0000000000..21f09dddfc --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/export.h @@ -0,0 +1,38 @@ +/* + * 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_ruby_export_h +#define tuscany_sca_ruby_export_h + +#if defined(WIN32) || defined (_WINDOWS) +#pragma warning(disable: 4786) + +#ifdef TUSCANY_SCA_RUBY_EXPORTS +#define SCA_RUBY_API __declspec(dllexport) +#else +#define SCA_RUBY_API __declspec(dllimport) +#endif + +#else +#define SCA_RUBY_API +#endif + +#endif // tuscany_sca_ruby_export_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp new file mode 100644 index 0000000000..877b98e7b4 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp @@ -0,0 +1,154 @@ +/* + * 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/ruby/model/RubyImplementation.h" +#include "tuscany/sca/ruby/model/RubyServiceBinding.h" +#include "tuscany/sca/ruby/model/RubyReferenceBinding.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/util/Utils.h" + +namespace tuscany +{ + namespace sca + { + + namespace ruby + { + + bool RubyImplementation::initialized = false; + VALUE RubyImplementation::xmlDocumentClass = 0; + + // Constructor + RubyImplementation::RubyImplementation(Composite* composite, const string& module, const string& className, const string& script) + : ComponentType(composite, script.substr(0, script.find_last_of('.'))), + module(module), className(className), script(script) + { + loadClass(); + } + + RubyImplementation::~RubyImplementation() + { + } + + void RubyImplementation::loadClass() + { + // Initialize the Ruby runtime + if (!initialized) + { + ruby_init(); + ruby_init_loadpath(); + + // Load the Rexml module. Rexml is used to handle XML documents. + //rb_require("rexml/document"); + // Use rb_eval_string for now as it provides better error reporting + rb_eval_string("require(\"rexml/document\")"); + + xmlDocumentClass = rb_path2class("REXML::Document"); + + initialized = true; + } + + // Load the specified Ruby script + if (script != "") + { + // Convert any windows slashes \ in the root path to unix slashes / + // otherwise the ruby interpreter throws an error + string rootpath = getComposite()->getRoot(); + int pos = 0; + while((pos = rootpath.find('\\', pos)) != string::npos) + { + rootpath = rootpath.replace(pos, 1, "/"); + } + + // Use rb_eval_string for now as it provides better error reporting + string path = "require(\"" + rootpath + "/" + script +"\")"; + //rb_require((char *)path.c_str()); + rb_eval_string(path.c_str()); + } + + // Load the Ruby implementation class + implementationClass = rb_path2class(className.c_str()); + + // Create a default service + ServiceType* defaultServiceType = new ServiceType(this, "", NULL, NULL); + addServiceType(defaultServiceType); + + // Introspect the Ruby class and create references and properties for + // all public attributes + VALUE methods = rb_class_public_instance_methods(0, NULL, implementationClass); + int n = RARRAY(methods)->len; + for (int i = 0; i<n; i++) + { + VALUE method = rb_ary_entry(methods, i); + string methodName = string(rb_string_value_cstr(&method)); + + // Create a reference type for each setter method + int s = methodName.size(); + if (s > 1 && methodName[s-1] == '=' && methodName[0] != '=') + { + string variableName = methodName.substr(0, s-1); + ReferenceType* referenceType = new ReferenceType( + this, variableName, NULL, NULL, ReferenceType::ONE_ONE); + addReferenceType(referenceType); + + // Create a property type as well + addPropertyType(variableName, "http://www.w3.org/2001/XMLSchema#string", false, NULL); + + } + } + } + + void RubyImplementation::initializeComponent(Component* component) + { + ComponentType::initializeComponent(component); + + // Create Ruby bindings for all the services + const Component::SERVICE_MAP& services = component->getServices(); + Component::SERVICE_MAP::const_iterator iter = services.begin(); + for (int i=0; i< services.size(); i++) + { + Service *service = iter->second; + RubyServiceBinding* binding = new RubyServiceBinding(service); + service->setBinding(binding); + iter++; + } + + // Create Ruby bindings for all the references + const Component::REFERENCE_MAP& references = component->getReferences(); + Component::REFERENCE_MAP::const_iterator refiter = references.begin(); + for (int ri=0; ri< references.size(); ri++) + { + Reference *reference = refiter->second; + RubyReferenceBinding* binding = new RubyReferenceBinding(reference); + reference->setBinding(binding); + refiter++; + } + } + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h new file mode 100644 index 0000000000..32b5801f42 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h @@ -0,0 +1,140 @@ +/* + * 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_ruby_model_rubyimplementation_h +#define tuscany_sca_ruby_model_rubyimplementation_h +#include "tuscany/sca/model/ComponentType.h" + +#include <map> +using std::map; +#include <string> +using std::string; + +#include "tuscany/sca/ruby/Ruby.h" + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + /** + * Holds information about an SCA implementation written in Ruby + */ + class RubyImplementation : public ComponentType + { + + public: + /** + * Constructor. + * @param composite The composite containing this implementation. + * @param module Name of the Ruby module. + * @param className Name of the Ruby implementation class. + * @param script Path of the Ruby script. + */ + RubyImplementation(Composite* composite, const string& module, const string& className, const string& script); + + /** + * Destructor + */ + virtual ~RubyImplementation(); + + /** + * Initialize a component of this type. + * @param component The component to initialize. + */ + virtual void initializeComponent(Component* component); + + /** + * Returns the name of the Ruby module. + * @return The name of the Ruby module. + */ + const string& getModule() const { return module; } + + /** + * Returns the name of Ruby class. + * @return Name of the Ruby class. + */ + const string& getClass() const { return className; } + + /** + * Returns the path of the Ruby script. + * @return The path of the Ruby script. + */ + const string& getScript() const { return script; } + + /** + * Returns the Ruby implementation class + */ + VALUE getImplementationClass() const { return implementationClass; } + + /** + * Returns the Ruby REXML::Document class + */ + static VALUE getXMLDocumentClass() { return xmlDocumentClass; } + + private: + + /** + * Load the Ruby implementation class + */ + void loadClass(); + + /** + * Name of the Ruby module. + */ + string module; + + /** + * Name of the Ruby class. + */ + string className; + + /** + * Path of the Ruby script. + */ + string script; + + /** + * The Ruby implementation class + */ + VALUE implementationClass; + + /** + * True if the Ruby runtime has been initialized + */ + static bool initialized; + + /** + * The Ruby REXML::Document class. + */ + static VALUE xmlDocumentClass; + + }; + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_model_rubyimplementation_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.cpp new file mode 100644 index 0000000000..0e813983f2 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.cpp @@ -0,0 +1,59 @@ +/* + * 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/ruby/model/RubyReferenceBinding.h" +#include "tuscany/sca/ruby/RubyServiceProxy.h" + + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + // Constructor + RubyReferenceBinding::RubyReferenceBinding(Reference* reference) + : ReferenceBinding(reference, ""), serviceProxy(NULL), targetServiceBinding(NULL) + { + } + + // Destructor + RubyReferenceBinding::~RubyReferenceBinding() + { + } + + ServiceProxy* RubyReferenceBinding::getServiceProxy() + { + return serviceProxy; + } + + void RubyReferenceBinding::configure(ServiceBinding* binding) + { + targetServiceBinding = binding; + + serviceProxy = new RubyServiceProxy(getReference()); + } + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.h new file mode 100644 index 0000000000..cab1c22c48 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.h @@ -0,0 +1,96 @@ +/* + * 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_ruby_model_rubyreferencebinding_h +#define tuscany_sca_ruby_model_rubyreferencebinding_h + +#include "tuscany/sca/model/ReferenceBinding.h" + + +#include <string> +using std::string; + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + /** + * Information about a Ruby service binding for service or a reference. + */ + class RubyReferenceBinding : public ReferenceBinding + { + public: + + /** + * Constructor. + */ + RubyReferenceBinding(Reference* reference); + + /** + * Destructor. + */ + virtual ~RubyReferenceBinding(); + + /** + * Returns the type of binding. + */ + virtual string getType() { return "http://www.osoa.org/xmlns/sca/1.0#RubyImplementationBinding"; }; + + /** + * Create a proxy representing the reference to the + * client component. + */ + virtual ServiceProxy* getServiceProxy(); + + /** + * Configure this binding from a service binding. + */ + virtual void configure(ServiceBinding* serviceBinding); + + /** + * Returns the target service binding. + */ + ServiceBinding* getTargetServiceBinding() const { return targetServiceBinding; }; + + private: + + /** + * The proxy representing the reference to the client + * component. + */ + ServiceProxy* serviceProxy; + + /** + * The service binding of the target + */ + ServiceBinding* targetServiceBinding; + }; + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_model_rubyreferencebinding_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.cpp new file mode 100644 index 0000000000..376a4db0f7 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.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/util/Logging.h" +#include "tuscany/sca/ruby/model/RubyServiceBinding.h" +#include "tuscany/sca/ruby/RubyServiceWrapper.h" + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + // Constructor + RubyServiceBinding::RubyServiceBinding(Service* service) + : ServiceBinding(service, "") + { + serviceWrapper = new RubyServiceWrapper(service); + } + + // Destructor + RubyServiceBinding::~RubyServiceBinding() + { + } + + ServiceWrapper* RubyServiceBinding::getServiceWrapper() + { + return (ServiceWrapper*)serviceWrapper; + } + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.h new file mode 100644 index 0000000000..24c0275bb9 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.h @@ -0,0 +1,78 @@ +/* + * 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_ruby_model_rubyservicebinding_h +#define tuscany_sca_ruby_model_rubyservicebinding_h + +#include "tuscany/sca/model/ServiceBinding.h" +using namespace tuscany::sca::model; +#include <string> +using std::string; + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + /** + * Information about a Ruby service binding for service or a reference. + */ + class RubyServiceBinding : public ServiceBinding + { + public: + + /** + * Constructor. + */ + RubyServiceBinding(Service* service); + + /** + * Destructor. + */ + virtual ~RubyServiceBinding(); + + /** + * Returns the type of binding. + */ + virtual string getType() { return "http://www.osoa.org/xmlns/sca/1.0#RubyImplementationBinding"; }; + + /** + * Create a wrapper for the service configured by this + * binding. + */ + virtual ServiceWrapper* getServiceWrapper(); + + private: + + /** + * The wrapper for the service configured by this binding. + */ + ServiceWrapper* serviceWrapper; + + }; + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_model_rubyservicebinding_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/xsd/sca-implementation-ruby.xsd b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/xsd/sca-implementation-ruby.xsd new file mode 100644 index 0000000000..f6598590d1 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/xsd/sca-implementation-ruby.xsd @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.osoa.org/xmlns/sca/1.0" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + elementFormDefault="qualified"> + + <element name="implementation.ruby" type="sca:RubyImplementation" substitutionGroup="sca:implementation"/> + <complexType name="RubyImplementation"> + <complexContent> + <extension base="sca:Implementation"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> + </sequence> + <attribute name="module" type="NCName" use="optional"/> + <attribute name="class" type="Name" use="optional"/> + <anyAttribute namespace="##any" processContents="lax"/> + </extension> + </complexContent> + </complexType> +</schema> diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/Makefile.am new file mode 100644 index 0000000000..50dfb45557 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/Makefile.am @@ -0,0 +1,23 @@ +# 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 = reference service +datadir=$(prefix)/extensions/sca + +nobase_data_DATA = xsd/*.xsd + +EXTRA_DIST = xsd diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/Makefile.am new file mode 100644 index 0000000000..18e9ba89b9 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/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 = axis2c diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/Makefile.am new file mode 100644 index 0000000000..2b9491ec1c --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/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/extensions/sca/reference/axis2c/src/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/src/Makefile.am new file mode 100644 index 0000000000..75eba52f73 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/src/Makefile.am @@ -0,0 +1,38 @@ +# 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. + +libdir=$(prefix)/extensions/sca/reference/lib +lib_LTLIBRARIES = libtuscany_sca_binding_reference.la + +noinst_HEADERS = \ +tuscany/sca/binding/*.h \ +tuscany/sca/binding/model/*.h + +libtuscany_sca_binding_reference_la_SOURCES = \ +tuscany/sca/binding/SCAServiceBindingExtension.cpp \ +tuscany/sca/binding/model/SCAServiceBinding.cpp + +libtuscany_sca_binding_reference_la_LIBADD = \ + -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo -ltuscany_sdo_axiom \ + -L$(top_builddir)/runtime/core/src -ltuscany_sca \ + -L$(top_builddir)/runtime/extensions/ws/reference/axis2c/src -ltuscany_sca_ws_reference + +INCLUDES = -I$(top_builddir)/runtime/core/src \ + -I${TUSCANY_SDOCPP}/include \ + -I$(top_builddir)/runtime/extensions/ws/reference/axis2c/src + +AM_CPPFLAGS = $(CPPFLAGS) -D_DEBUG diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/src/tuscany/sca/binding/SCAServiceBindingExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/src/tuscany/sca/binding/SCAServiceBindingExtension.cpp new file mode 100644 index 0000000000..b12702bf43 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/src/tuscany/sca/binding/SCAServiceBindingExtension.cpp @@ -0,0 +1,97 @@ +/* + * 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 "SCAServiceBindingExtension.h" +#include "model/SCAServiceBinding.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/core/SCARuntime.h" + +extern "C" +{ + #if defined(WIN32) || defined(_WINDOWS) + __declspec(dllexport) + #endif + void tuscany_sca_extension_initialize() + { + tuscany::sca::binding::SCAServiceBindingExtension::initialize(); + } +} + + +namespace tuscany +{ + namespace sca + { + namespace binding + { + // =================================================================== + // Constructor for the SCAServiceBinding class. + // =================================================================== + SCAServiceBindingExtension::SCAServiceBindingExtension() + { + LOGENTRY(1, "SCAServiceBindingExtension::constructor"); + LOGEXIT(1, "SCAServiceBindingExtension::constructor"); + } + + // =================================================================== + // Destructor for the SCAServiceBindingExtension class. + // =================================================================== + SCAServiceBindingExtension::~SCAServiceBindingExtension() + { + LOGENTRY(1, "SCAServiceBindingExtension::destructor");; + LOGEXIT(1, "SCAServiceBindingExtension::destructor"); + } + + const string SCAServiceBindingExtension::extensionName("sca"); + const string SCAServiceBindingExtension::typeQName("http://www.osoa.org/xmlns/sca/1.0#SCABinding"); + + + // =================================================================== + // loadModelElement - load the info from binding.ws + // =================================================================== + ServiceBinding* SCAServiceBindingExtension::getServiceBinding(Composite *composite, Service* service, DataObjectPtr scdlBinding) + { + string bindingType = scdlBinding->getType().getName(); + if (bindingType == "SCABinding") + { + string uri = scdlBinding->getCString("uri"); + + SCAServiceBinding* serviceBinding = new SCAServiceBinding(service, uri); + + return serviceBinding; + } + else + { + return NULL; + } + } + + void SCAServiceBindingExtension::initialize() + { + LOGENTRY(1, "SCAServiceBindingExtension::initialize");; + SCARuntime::getInstance()->registerServiceBindingExtension(new SCAServiceBindingExtension()); + LOGEXIT(1, "SCAServiceBindingExtension::initialize");; + } + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/src/tuscany/sca/binding/SCAServiceBindingExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/src/tuscany/sca/binding/SCAServiceBindingExtension.h new file mode 100644 index 0000000000..4cd05bee16 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/src/tuscany/sca/binding/SCAServiceBindingExtension.h @@ -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. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_extension_binding_scaservicebindingextension_h +#define tuscany_sca_extension_binding_scaservicebindingextension_h + +#include "tuscany/sca/extension/ServiceBindingExtension.h" + +namespace tuscany +{ + namespace sca + { + namespace binding + { + + class SCAServiceBindingExtension : public ServiceBindingExtension + { + public: + /** + * Default constructor + */ + SCAServiceBindingExtension(); + + /** + * Destructor + */ + virtual ~SCAServiceBindingExtension(); + + /** + * return the name of the extension + */ + virtual const string& getExtensionName() {return extensionName;} + + /** + * return the QName of schema elemant for this implementation extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#binding.ws") + */ + virtual const string& getExtensionTypeQName() {return typeQName;} + + virtual ServiceBinding* getServiceBinding(Composite* composite, Service* service, DataObjectPtr scdlBinding); + + static void initialize(); + + private: + static const string extensionName; + static const string typeQName; + + }; + + + } // End namespace binding + } // End namespace sca +} // End namespace tuscany + +#endif //tuscany_sca_extension_binding_scaservicebindingextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/src/tuscany/sca/binding/model/SCAServiceBinding.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/src/tuscany/sca/binding/model/SCAServiceBinding.cpp new file mode 100644 index 0000000000..a6b052f04f --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/src/tuscany/sca/binding/model/SCAServiceBinding.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/binding/model/SCAServiceBinding.h" +#include "tuscany/sca/core/ServiceWrapper.h" + +namespace tuscany +{ + namespace sca + { + namespace binding + { + + // Constructor + SCAServiceBinding::SCAServiceBinding(Service* service, const string& uri) + : WSServiceBinding(service, uri, "", "") + { + } + + // Destructor + SCAServiceBinding::~SCAServiceBinding() + { + } + + } // End namespace binding + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/src/tuscany/sca/binding/model/SCAServiceBinding.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/src/tuscany/sca/binding/model/SCAServiceBinding.h new file mode 100644 index 0000000000..90eb222b7b --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/reference/axis2c/src/tuscany/sca/binding/model/SCAServiceBinding.h @@ -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$ */ + +#ifndef tuscany_sca_extension_binding_model_scaservicebinding_h +#define tuscany_sca_extension_binding_model_scaservicebinding_h + +#include "tuscany/sca/model/ServiceBinding.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/ws/model/WSServiceBinding.h" + +#include <string> +using std::string; + +using namespace tuscany::sca::model; +using namespace tuscany::sca::ws; + +namespace tuscany +{ + namespace sca + { + namespace binding + { + /** + * Information about an SCA service binding for service or a reference. + */ + class SCAServiceBinding : public WSServiceBinding + { + public: + + /** + * Constructor. + * @param uri The uri of the binding. + */ + SCAServiceBinding(model::Service* service, const string& uri); + + /** + * Destructor. + */ + virtual ~SCAServiceBinding(); + + /** + * Returns the type of binding. + */ + virtual string getType() { return "http://www.osoa.org/xmlns/sca/1.0#SCABinding"; }; + + private: + + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_extension_ws_model_wsservicebinding_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/Makefile.am new file mode 100644 index 0000000000..18e9ba89b9 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/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 = axis2c diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/Makefile.am new file mode 100644 index 0000000000..feadf9e317 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/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
\ No newline at end of file diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/src/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/src/Makefile.am new file mode 100644 index 0000000000..b03e398106 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/src/Makefile.am @@ -0,0 +1,38 @@ +# 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. + +libdir=$(prefix)/extensions/sca/service/lib +lib_LTLIBRARIES = libtuscany_sca_binding_service.la + +noinst_HEADERS = \ +tuscany/sca/binding/*.h \ +tuscany/sca/binding/model/*.h + +libtuscany_sca_binding_service_la_SOURCES = \ +tuscany/sca/binding/SCAReferenceBindingExtension.cpp \ +tuscany/sca/binding/model/SCAReferenceBinding.cpp + +libtuscany_sca_binding_service_la_LIBADD = \ + -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo -ltuscany_sdo_axiom \ + -L$(top_builddir)/runtime/core/src -ltuscany_sca \ + -L$(top_builddir)/runtime/extensions/ws/service/axis2c/src -ltuscany_sca_ws_service + +INCLUDES = -I$(top_builddir)/runtime/core/src \ + -I${TUSCANY_SDOCPP}/include \ + -I$(top_builddir)/runtime/extensions/ws/service/axis2c/src + +AM_CPPFLAGS = $(CPPFLAGS) -D_DEBUG diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/src/tuscany/sca/binding/SCAReferenceBindingExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/src/tuscany/sca/binding/SCAReferenceBindingExtension.cpp new file mode 100644 index 0000000000..7fb9b4af64 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/src/tuscany/sca/binding/SCAReferenceBindingExtension.cpp @@ -0,0 +1,97 @@ +/* + * 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 "SCAReferenceBindingExtension.h" +#include "model/SCAReferenceBinding.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/core/SCARuntime.h" + + +extern "C" +{ + #if defined(WIN32) || defined(_WINDOWS) + __declspec(dllexport) + #endif + void tuscany_sca_extension_initialize() + { + tuscany::sca::binding::SCAReferenceBindingExtension::initialize(); + } +} + +namespace tuscany +{ + namespace sca + { + namespace binding + { + // =================================================================== + // Constructor for the SCAReferenceBinding class. + // =================================================================== + SCAReferenceBindingExtension::SCAReferenceBindingExtension() + { + LOGENTRY(1, "SCAReferenceBindingExtension::constructor"); + LOGEXIT(1, "SCAReferenceBindingExtension::constructor"); + } + + // =================================================================== + // Destructor for the SCAReferenceBindingExtension class. + // =================================================================== + SCAReferenceBindingExtension::~SCAReferenceBindingExtension() + { + LOGENTRY(1, "SCAReferenceBindingExtension::destructor");; + LOGEXIT(1, "SCAReferenceBindingExtension::destructor"); + } + + const string SCAReferenceBindingExtension::extensionName("sca"); + const string SCAReferenceBindingExtension::typeQName("http://www.osoa.org/xmlns/sca/1.0#SCABinding"); + + // =================================================================== + // loadModelElement - load the info from binding.ws + // =================================================================== + ReferenceBinding* SCAReferenceBindingExtension::getReferenceBinding(Composite *composite, Reference* reference, DataObjectPtr scdlBinding) + { + string bindingType = scdlBinding->getType().getName(); + if (bindingType == "SCABinding") + { + string uri = scdlBinding->getCString("uri"); + + SCAReferenceBinding* serviceBinding = new SCAReferenceBinding(reference, uri); + + return serviceBinding; + } + else + { + return NULL; + } + } + + void SCAReferenceBindingExtension::initialize() + { + LOGENTRY(1, "SCAReferenceBindingExtension::initialize");; + SCARuntime::getInstance()->registerReferenceBindingExtension(new SCAReferenceBindingExtension()); + LOGEXIT(1, "SCAReferenceBindingExtension::initialize");; + } + + } // End namespace binding + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/src/tuscany/sca/binding/SCAReferenceBindingExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/src/tuscany/sca/binding/SCAReferenceBindingExtension.h new file mode 100644 index 0000000000..9f5ddd55eb --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/src/tuscany/sca/binding/SCAReferenceBindingExtension.h @@ -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. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_extension_binding_scareferencebindingextension_h +#define tuscany_sca_extension_binding_scareferencebindingextension_h + +#include "tuscany/sca/extension/ReferenceBindingExtension.h" + +namespace tuscany +{ + namespace sca + { + namespace binding + { + + class SCAReferenceBindingExtension : public ReferenceBindingExtension + { + public: + /** + * Default constructor + */ + SCAReferenceBindingExtension(); + + /** + * Destructor + */ + virtual ~SCAReferenceBindingExtension(); + + /** + * return the name of the extension + */ + virtual const string& getExtensionName() {return extensionName;} + + /** + * return the QName of schema elemant for this implementation extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#binding.ws") + */ + virtual const string& getExtensionTypeQName() {return typeQName;} + + virtual ReferenceBinding* getReferenceBinding(Composite* composite, Reference *reference, DataObjectPtr scdlBinding); + + static void initialize(); + + private: + static const string extensionName; + static const string typeQName; + + }; + + + } // End namespace binding + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_extension_binding_scareferencebindingextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/src/tuscany/sca/binding/model/SCAReferenceBinding.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/src/tuscany/sca/binding/model/SCAReferenceBinding.cpp new file mode 100644 index 0000000000..6e7b4eaccc --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/src/tuscany/sca/binding/model/SCAReferenceBinding.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/binding/model/SCAReferenceBinding.h" +#include "tuscany/sca/ws/model/WSReferenceBinding.h" +#include "tuscany/sca/core/ServiceProxy.h" + +namespace tuscany +{ + namespace sca + { + namespace binding + { + + // Constructor + SCAReferenceBinding::SCAReferenceBinding(Reference* reference, const string& uri) + : WSReferenceBinding(reference, uri, "", "") + { + } + + // Destructor + SCAReferenceBinding::~SCAReferenceBinding() + { + } + + } // End namespace binding + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/src/tuscany/sca/binding/model/SCAReferenceBinding.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/src/tuscany/sca/binding/model/SCAReferenceBinding.h new file mode 100644 index 0000000000..445a00be82 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/service/axis2c/src/tuscany/sca/binding/model/SCAReferenceBinding.h @@ -0,0 +1,71 @@ +/* + * 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_binding_model_scareferencebinding_h +#define tuscany_sca_extension_binding_model_scareferencebinding_h + +#include "tuscany/sca/model/ReferenceBinding.h" +#include "tuscany/sca/ws/model/WSReferenceBinding.h" + +using namespace tuscany::sca::model; +using namespace tuscany::sca::ws; + +#include <string> +using std::string; + +namespace tuscany +{ + namespace sca + { + namespace binding + { + /** + * Information about a web service binding for service or a reference. + */ + class SCAReferenceBinding : public WSReferenceBinding + { + public: + + /** + * Constructor. + * @param uri The uri of the binding. + */ + SCAReferenceBinding(Reference* reference, const string&uri); + + /** + * Destructor. + */ + virtual ~SCAReferenceBinding(); + + /** + * Returns the type of binding. + */ + virtual string getType() { return "http://www.osoa.org/xmlns/sca/1.0#SCABinding"; }; + + private: + + }; + + } // End namespace binding + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_extension_binding_model_scareferencebinding_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/xsd/sca-binding-sca.xsd b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/xsd/sca-binding-sca.xsd new file mode 100644 index 0000000000..1051c3910c --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/sca/xsd/sca-binding-sca.xsd @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.osoa.org/xmlns/sca/1.0" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + elementFormDefault="qualified"> + + <element name="binding.sca" type="sca:SCABinding" substitutionGroup="sca:binding"/> + <complexType name="SCABinding"> + <complexContent> + <extension base="sca:Binding"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> + </sequence> + <anyAttribute namespace="##any" processContents="lax" /> + </extension> + </complexContent> + </complexType> +</schema> diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/Makefile.am new file mode 100644 index 0000000000..806786ce04 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/Makefile.am @@ -0,0 +1,23 @@ +# 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 = reference service +datadir=$(prefix)/extensions/ws + +nobase_data_DATA = xsd/*.xsd + +EXTRA_DIST = xsd diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/deploy.bat b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/deploy.bat new file mode 100644 index 0000000000..567875624f --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/deploy.bat @@ -0,0 +1,45 @@ +@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 extdir=%deploydir%\extensions +set wsextdir=%extdir%\ws +set srcdir=%rootdir%\runtime\extensions\ws + +if not exist %deploydir% mkdir %deploydir% +if not exist %extdir% mkdir %extdir% +if not exist %wsextdir% mkdir %wsextdir% +if not exist %wsextdir%\xsd mkdir %wsextdir%\xsd + +copy %srcdir%\xsd\*.* %wsextdir%\xsd + +goto end +:usage +echo Usage: deploy <sca-root> +:end + +endlocal diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/Makefile.am new file mode 100644 index 0000000000..18e9ba89b9 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/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 = axis2c diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/Makefile.am new file mode 100644 index 0000000000..2b9491ec1c --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/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/extensions/ws/reference/axis2c/src/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/Makefile.am new file mode 100644 index 0000000000..208af0e15a --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/Makefile.am @@ -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. + +libdir=$(prefix)/extensions/ws/reference/lib +lib_LTLIBRARIES = libtuscany_sca_ws_reference.la + +noinst_HEADERS = tuscany/sca/ws/*.h tuscany/sca/ws/model/*.h + +libtuscany_sca_ws_reference_la_SOURCES = \ +tuscany/sca/ws/WSServiceBindingExtension.cpp \ +tuscany/sca/ws/model/WSServiceBinding.cpp \ +tuscany/sca/ws/WSServiceWrapper.cpp \ +tuscany/sca/ws/Axis2Client.cpp + +libtuscany_sca_ws_reference_la_LIBADD = \ + -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo -ltuscany_sdo_axiom \ + -L$(top_builddir)/runtime/core/src -ltuscany_sca \ + -L$(AXIS2C_HOME)/lib \ + -laxis2_util \ + -laxis2_axiom \ + -laxis2_wsdl \ + -laxis2_engine \ + -laxis2_parser \ + -laxis2_minizip \ + -lpthread \ + -lwoden \ + -laxis2_http_sender \ + -laxis2_http_receiver + +INCLUDES = -I$(top_builddir)/runtime/core/src \ + -I${TUSCANY_SDOCPP}/include \ + -I${AXIS2C_HOME}/include + +AM_CPPFLAGS = $(CPPFLAGS) -D_DEBUG + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/Axis2Client.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/Axis2Client.cpp new file mode 100644 index 0000000000..4dfb3e7efd --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/Axis2Client.cpp @@ -0,0 +1,717 @@ +/* + * 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: 4091) +#pragma warning(disable: 4786) +#endif + +#include <axis2_client.h> + +#include <axis2_error_default.h> +#include <axis2_log_default.h> +#include <axis2_defines.h> +#include <axiom_soap_const.h> +#include <platforms/axis2_platform_auto_sense.h> + +#include <sdo_axiom.h> +#include "Axis2Client.h" + +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "model/WSServiceBinding.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/util/Exceptions.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/WSDLDefinition.h" +#include "tuscany/sca/model/WSDLInterface.h" +#include "tuscany/sca/model/WSDLOperation.h" + +#include <sstream> + +using namespace tuscany::sca::ws; + + +using namespace commonj::sdo; +using namespace commonj::sdo_axiom; + +namespace tuscany +{ + namespace sca + { + namespace ws + { + + Axis2Client::Axis2Client(CompositeReference* compositeReference) + : compositeReference(compositeReference) + { + } + + Axis2Client::~Axis2Client() + { + } + + void Axis2Client::invoke(tuscany::sca::Operation& operation) + { + LOGENTRY(1, "Axis2Client::invoke"); + + // Initialize Axis2 stuff + axis2_allocator_t *allocator = axis2_allocator_init (NULL); + axis2_log_t *log = axis2_log_create(allocator, NULL, "tuscany_client.log"); + axis2_error_t *error = axis2_error_create(allocator); + axis2_env_t *env = axis2_env_create_with_error_log(allocator, error, log); + env->log->level = AXIS2_LOG_LEVEL_TRACE; + axis2_error_init(); + + // Get the WS service binding and WSDLOperation + Composite* composite=compositeReference->getComposite(); + Service* service = compositeReference->getService(); + WSServiceBinding* binding = (WSServiceBinding *)service->getBinding(); + const string& operationName = operation.getName(); + WSDLOperation wsdlOperation; + + // Get the WSDL namespace + string wsdlNamespace = binding->getWSDLNamespaceURL(); + if (wsdlNamespace != "") + { + + // Lookup the wsdl model from the composite, keyed on the namespace + // (the wsdl will have been loaded at startup) + WSDLDefinition* wsdlDefinition = composite->findWSDLDefinition(wsdlNamespace); + if (wsdlDefinition == 0) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "WSDL description %s not found\n", wsdlNamespace.c_str()); + string msg = "WSDL not found for " + wsdlNamespace; + throw SystemConfigurationException(msg.c_str()); + } + + // Match the operation in Operation to the operation in the wsdl port type. + try + { + wsdlOperation = wsdlDefinition->findOperation( + binding->getServiceName(), + binding->getEndpointName(), + operationName); + } + catch(SystemConfigurationException &ex) + { + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "SystemConfigurationException has been caught: %s\n", ex.getMessageText()); + throw; + } + + } + else + { + Interface* iface = service->getType()->getInterface(); + if (iface != NULL && + iface->getInterfaceTypeQName() == WSDLInterface::typeQName) + { + WSDLInterface* wsdlInterface = (WSDLInterface*)iface; + wsdlNamespace = wsdlInterface->getNamespaceURI(); + + if (wsdlNamespace != "") + { + + WSDLDefinition* wsdl = composite->findWSDLDefinition(wsdlNamespace); + if (wsdl == 0) + { + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "WSDL description %s not found\n", wsdlNamespace.c_str()); + string msg = "WSDL not found for " + wsdlNamespace; + throw SystemConfigurationException(msg.c_str()); + } + + try + { + wsdlOperation = wsdl->findOperation(wsdlInterface->getName(), operationName); + } + catch(SystemConfigurationException &ex) + { + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "SystemConfigurationException has been caught: %s\n", ex.getMessageText()); + throw; + } + } + } + } + + if (wsdlNamespace == "") + { + + // Create a default document literal wrapped WSDL operation + wsdlNamespace = compositeReference->getName(); + wsdlOperation = WSDLOperation(); + wsdlOperation.setOperationName(operationName); + wsdlOperation.setSoapAction(wsdlNamespace+ "#" +operationName); + wsdlOperation.setEndpoint(""); + wsdlOperation.setSoapVersion(WSDLOperation::SOAP11); + wsdlOperation.setDocumentStyle(true); + wsdlOperation.setWrappedStyle(true); + wsdlOperation.setEncoded(false); + wsdlOperation.setInputType(wsdlNamespace + "#" + operationName); + wsdlOperation.setOutputType(wsdlNamespace + "#" + operationName + "Response"); + } + + // Get the target endpoint address + // The URI specified in the binding overrides the address specified in + // the WSDL + axis2_char_t* address; + if (binding->getURI() != "") + { + address = (axis2_char_t*)binding->getURI().c_str(); + } + else + { + address = (axis2_char_t*)wsdlOperation.getEndpoint().c_str(); + } + + axis2_char_t* opName = (axis2_char_t*)operationName.c_str(); + axis2_char_t* soap_action = (axis2_char_t*)wsdlOperation.getSoapAction().c_str(); + axis2_char_t* serviceName = (axis2_char_t*)binding->getServiceName().c_str(); + + // create OM from Operation and wsdlOperation + axiom_node_t* payload = createPayload(operation, wsdlOperation, env); + + /* Create EPR with given address */ + axis2_endpoint_ref_t* endpoint_ref = axis2_endpoint_ref_create(env, address); + + /* Setup options */ + axis2_options_t* options = axis2_options_create(env); + AXIS2_OPTIONS_SET_TO(options, env, endpoint_ref); + int soap_version = AXIOM_SOAP11; + if (binding->getSOAPVersion() == "1.2") + { + soap_version = AXIOM_SOAP12; + } + else + { + if (wsdlOperation.getSoapVersion() == WSDLOperation::SOAP12) + { + soap_version = AXIOM_SOAP12; + } + } + + AXIS2_OPTIONS_SET_SOAP_VERSION(options, env, soap_version); + AXIS2_OPTIONS_SET_ACTION(options, env, soap_action); + + /* Create service client */ + + axis2_char_t* client_home = AXIS2_GETENV("AXIS2C_HOME"); + if (!client_home) + { + throw SystemConfigurationException("Environment error: AXIS2C_HOME not set"); + } + axis2_svc_client_t* svc_client = axis2_svc_client_create(env, client_home); + if (!svc_client) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "invoke FAILED: Error code:" + " %d :: %s", env->error->error_number, + AXIS2_ERROR_GET_MESSAGE(env->error)); + + throw SystemConfigurationException("Axis2Client: axis2_svc_client_create failed"); + } + + /* Set service client options */ + AXIS2_SVC_CLIENT_SET_OPTIONS(svc_client, env, options); + + /* Send request */ + axiom_node_t* ret_node = AXIS2_SVC_CLIENT_SEND_RECEIVE(svc_client, env, payload); + if(ret_node) + { + setReturn(ret_node, operation, wsdlOperation, env); + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Invoke failed: Error code:" + " %d :: %s", env->error->error_number, + AXIS2_ERROR_GET_MESSAGE(env->error)); + throw SystemConfigurationException("Axis2Client: Invoke failed"); + } + + LOGINFO(2, "Warning: Have not freed Axis2C service client memory due to Jira AXIS2C-209"); + // Uncommenting this code causes crash when invoking a composite with both Axis2C ws.binding + // service and reference. See Jiras TUSCANY-536 and AXIS2C-209 + //if (svc_client) + //{ + // AXIS2_SVC_CLIENT_FREE(svc_client, env); + // svc_client = NULL; + //} + + LOGEXIT(1, "Axis2Client::invoke"); + } + + axiom_node_t* Axis2Client::createPayload(Operation& operation, + const WSDLOperation& wsdlOperation, + axis2_env_t* env) + { + LOGENTRY(1, "Axis2Client::createPayload"); + axiom_node_t* request_node = NULL; + + // map the operation request to the wsdl + if (wsdlOperation.isDocumentStyle()) + { + // Document style + // only support single part messages - WS-I compliant + + // Build up the payload as an SDO + + // Get the data factory for the composite (it will already have the typecreates loaded for the xsds) + DataFactoryPtr dataFactory = compositeReference->getComposite()->getDataFactory(); + + DataObjectPtr inputDataObject; + try + { + + // Create the input wrapper + const Type& rootType = dataFactory->getType(wsdlOperation.getInputTypeUri().c_str(), "RootType"); + const Property& prop = rootType.getProperty(wsdlOperation.getInputTypeName().c_str()); + const Type& inputType = prop.getType(); + inputDataObject = dataFactory->create(inputType); + } + catch (SDORuntimeException e) + { + try + { + // Create the input wrapper + const Type& inputType = dataFactory->getType(wsdlOperation.getInputTypeUri().c_str(), + wsdlOperation.getInputTypeName().c_str()); + inputDataObject = dataFactory->create(inputType); + } + catch (SDORuntimeException e2) + { + + // The input wrapper type is not known, create an open DataObject + inputDataObject = dataFactory->create(Type::SDOTypeNamespaceURI, "OpenDataObject"); + } + } + + // Go through data object to set the input parameters + PropertyList pl = inputDataObject->getType().getProperties(); + + if(pl.size() == 0) + { + if(inputDataObject->getType().isOpenType() && inputDataObject->getType().isDataObjectType()) + { + /* + * This code deals with sending xsd:any elements + */ + for (int i=0; i<operation.getNParms(); i++) + { + ostringstream pname; + pname << "param" << (i+1); + DataObjectList& l = inputDataObject->getList(pname.str()); + + const Operation::Parameter& parm = operation.getParameter(i); + switch(parm.getType()) + { + case Operation::BOOL: + { + l.append(*(bool*)parm.getValue()); + break; + } + case Operation::SHORT: + { + l.append(*(short*)parm.getValue()); + break; + } + case Operation::INT: + { + l.append(*(long*)parm.getValue()); + break; + } + case Operation::LONG: + { + l.append(*(long*)parm.getValue()); + break; + } + case Operation::USHORT: + { + l.append(*(short*)parm.getValue()); + break; + } + case Operation::UINT: + { + l.append(*(long*)parm.getValue()); + break; + } + case Operation::ULONG: + { + l.append(*(long*)parm.getValue()); + break; + } + case Operation::FLOAT: + { + l.append(*(float*)parm.getValue()); + break; + } + case Operation::DOUBLE: + { + l.append(*(long double*)parm.getValue()); + break; + } + case Operation::LONGDOUBLE: + { + l.append(*(long double*)parm.getValue()); + break; + } + case Operation::CHARS: + { + l.append(*(char**)parm.getValue()); + break; + } + case Operation::STRING: + { + l.append((*(string*)parm.getValue()).c_str()); + break; + } + case Operation::DATAOBJECT: + { + l.append(*(DataObjectPtr*)parm.getValue()); + break; + } + default: throw "unsupported parameter type"; + } + } + } + } + else { + + // Each parameter in the operation should be a property on the request dataobject + for (int i=0; i<operation.getNParms(); i++) + { + const Operation::Parameter& parm = operation.getParameter(i); + switch(parm.getType()) + { + case Operation::BOOL: + { + inputDataObject->setBoolean(i, *(bool*)parm.getValue()); + break; + } + case Operation::SHORT: + { + inputDataObject->setShort(i, *(short*)parm.getValue()); + break; + } + case Operation::INT: + { + inputDataObject->setInteger(i, *(int*)parm.getValue()); + break; + } + case Operation::LONG: + { + inputDataObject->setLong(i, *(long*)parm.getValue()); + break; + } + case Operation::USHORT: + { + inputDataObject->setInteger(i, *(unsigned short*)parm.getValue()); + break; + } + case Operation::UINT: + { + inputDataObject->setInteger(i, *(unsigned int*)parm.getValue()); + break; + } + case Operation::ULONG: + { + inputDataObject->setInteger(i, *(unsigned long*)parm.getValue()); + break; + } + case Operation::FLOAT: + { + inputDataObject->setFloat(i, *(float*)parm.getValue()); + break; + } + case Operation::DOUBLE: + { + inputDataObject->setDouble(i, *(double*)parm.getValue()); + break; + } + case Operation::LONGDOUBLE: + { + inputDataObject->setDouble(i, *(long double*)parm.getValue()); + break; + } + case Operation::CHARS: + { + inputDataObject->setCString(i, *(char**)parm.getValue()); + break; + } + case Operation::STRING: + { + inputDataObject->setCString(i, (*(string*)parm.getValue()).c_str()); + break; + } + case Operation::DATAOBJECT: + { + inputDataObject->setDataObject(i, *(DataObjectPtr*)parm.getValue()); + break; + } + default: throw "unsupported parameter type"; + } + } + } + + // Create the Axiom object from the request dataobject + AxiomHelper* axiomHelper = AxiomHelper::getHelper(); + request_node = axiomHelper->toAxiomNode(inputDataObject, + wsdlOperation.getInputTypeUri().c_str(), wsdlOperation.getInputTypeName().c_str()); + AxiomHelper::releaseHelper(axiomHelper); + } + else + { + // RPC + } + + char* str = AXIOM_NODE_TO_STRING(request_node, env); + LOGINFO_1(3, "Sending this OM node in XML : %s \n", str); + + LOGEXIT(1, "Axis2Client::createPayload"); + return request_node; + } + + void Axis2Client::setReturn(axiom_node_t* ret_node, + Operation& operation, + const WSDLOperation& wsdlOperation, + axis2_env_t* env) + { + LOGENTRY(1, "Axis2Client::setReturn"); + + if (wsdlOperation.isDocumentStyle()) + { + // Document style + DataFactoryPtr dataFactory = compositeReference->getComposite()->getDataFactory(); + + // Get the AXIOM node representing the SOAP Body + axiom_node_t* body = AXIOM_NODE_GET_PARENT(ret_node, env); + + // Convert the AXIOM node to an SDO DataObject + char* str = NULL; + str = AXIOM_NODE_TO_STRING(body, env); + if (str) + { + AXIS2_LOG_INFO((env)->log, "Axis2Client invoke has response OM: %s\n", str); + } + + // Convert the SOAP body to an SDO DataObject + AxiomHelper* axiomHelper = AxiomHelper::getHelper(); + DataObjectPtr outputBodyDataObject = axiomHelper->toSdo(body, dataFactory); + AxiomHelper::releaseHelper(axiomHelper); + + if(!outputBodyDataObject) + { + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "Axis2Service invoke: Could not convert received Axiom node to SDO"); + /** TODO: return a SOAP fault here */ + return; + } + + // Get the first body part representing the doc-lit-wrapped wrapper element + DataObjectPtr outputDataObject = NULL; + PropertyList bpl = outputBodyDataObject->getInstanceProperties(); + if (bpl.size()!=0) + { + if (bpl[0].isMany()) + { + DataObjectList& parts = outputBodyDataObject->getList((unsigned int)0); + outputDataObject = parts[0]; + } + else + { + outputDataObject = outputBodyDataObject->getDataObject(bpl[0]); + } + } + if (outputDataObject == NULL) + { + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "Axis2Client invoke: Could not convert body part to SDO"); + return; + } + + PropertyList pl = outputDataObject->getInstanceProperties(); + unsigned int i = 0; + + switch(pl[i].getTypeEnum()) + { + case Type::BooleanType: + { + bool* boolData = new bool; + *boolData = outputDataObject->getBoolean(pl[i]); + operation.setReturnValue(boolData); + } + break; + case Type::ByteType: + { + char* byteData = new char; + *byteData = outputDataObject->getByte(pl[i]); + operation.setReturnValue(byteData); + } + break; + case Type::BytesType: + { + int len = outputDataObject->getLength(pl[i]); + char* bytesData = new char[len+1]; + int bytesWritten = outputDataObject->getBytes(pl[i], bytesData, len); + // Ensure the bytes end with the null char. Not sure if this is neccessary + if(bytesWritten <= len) + { + bytesData[bytesWritten] = 0; + } + else + { + bytesData[len] = 0; + } + //printf("outputDataObject has BytesType named %s with length %d\n", name, bytesWritten); + operation.setReturnValue(&bytesData); + } + break; + case Type::CharacterType: + { + // This code should work but won't be used as there is no mapping from an XSD type to the SDO CharacterType + wchar_t* charData = new wchar_t; + *charData = outputDataObject->getCharacter(pl[i]); + operation.setReturnValue(charData); + } + break; + case Type::DoubleType: + { + long double* doubleData = new long double; + *doubleData = outputDataObject->getDouble(pl[i]); + operation.setReturnValue(doubleData); + } + break; + case Type::FloatType: + { + float* floatData = new float; + *floatData = outputDataObject->getFloat(pl[i]); + operation.setReturnValue(floatData); + } + break; + case Type::IntegerType: + { + long* intData = new long; + *intData = outputDataObject->getInteger(pl[i]); + operation.setReturnValue(intData); + } + break; + case Type::ShortType: + { + short* shortData = new short; + *shortData = outputDataObject->getShort(pl[i]); + operation.setReturnValue(shortData); + } + break; + case Type::StringType: + { + string* str = new string(outputDataObject->getCString(pl[i])); + operation.setReturnValue(str); + } + break; + case Type::DataObjectType: + { + DataObjectPtr dataObjectData = outputDataObject->getDataObject(pl[i]); + if(!dataObjectData) + { + LOGINFO(4, "SDO DataObject return value was null"); + } + operation.setReturnValue(&dataObjectData); + } + break; + case Type::OpenDataObjectType: + { + /* + * This code deals with xsd:any element parameters + */ + + DataObjectList& dataObjectList = outputDataObject->getList(pl[i]); + + for(int j=0; j<dataObjectList.size(); j++) + { + DataObjectPtr dataObjectData = dataObjectList[j]; + if(!dataObjectData) + { + operation.setReturnValue(&dataObjectData); + LOGINFO(4, "SDO OpenDataObject return value was null"); + } + else + { + + SequencePtr sequence = dataObjectData->getSequence(); + if (sequence->size()!=0) + { + // Return a text element + if (sequence->isText(0)) + { + string* stringData = new string(sequence->getCStringValue(0)); + operation.setReturnValue(stringData); + } + else + { + // Return a DataObject representing a complex element + DataObjectPtr dob = sequence->getDataObjectValue(0); + if(!dob) + { + LOGINFO(4, "SDO DataObject return value was null"); + } + operation.setReturnValue(&dob); + } + } + else + { + // Empty content, add an empty string + LOGINFO(4, "SDO OpenDataObject return value was empy"); + string *stringData = new string(""); + operation.setReturnValue(stringData); + } + } + } + } + break; + case Type::DateType: + LOGERROR(0, "SDO DateType return values are not yet supported"); + break; + case Type::LongType: + LOGERROR(0, "SDO LongType (int64_t) return values are not yet supported"); + break; + case Type::UriType: + LOGERROR(0, "SDO UriType return values are not yet supported"); + break; + case Type::BigDecimalType: + LOGERROR(0, "SDO BigDecimalType return values are not yet supported"); + break; + case Type::BigIntegerType: + LOGERROR(0, "SDO BigIntegerType return values are not yet supported"); + break; + default: + LOGERROR(0, "Unknown SDO type has been found in return value. Unknown types are not yet supported"); + break; + } + } + else + { + // RPC + } + LOGEXIT(1, "Axis2Client::setReturn"); + } + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/Axis2Client.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/Axis2Client.h new file mode 100644 index 0000000000..5ec302f0c8 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/Axis2Client.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_extension_ws_axis2client_h +#define tuscany_sca_extension_ws_axis2client_h + +#include <axiom.h> + +#include "tuscany/sca/core/Operation.h" +#include "tuscany/sca/model/CompositeReference.h" +#include "tuscany/sca/model/WSDLOperation.h" + +using namespace tuscany::sca::model; + + +namespace tuscany +{ + namespace sca + { + namespace ws + { + + class Axis2Client + { + public: + Axis2Client(CompositeReference* externalService); + virtual ~Axis2Client(); + + virtual void invoke(Operation& operation); + + private: + CompositeReference* compositeReference; + + axiom_node_t* createPayload(Operation& operation, + const WSDLOperation& wsdlOp, + axis2_env_t* env); + + void setReturn(axiom_node_t* returnNode, + Operation& operation, + const WSDLOperation& wsdlOp, + axis2_env_t* env); + + }; + } // End namespace ws + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_extension_ws_axis2client_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/WSServiceBindingExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/WSServiceBindingExtension.cpp new file mode 100644 index 0000000000..c260445b60 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/WSServiceBindingExtension.cpp @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "WSServiceBindingExtension.h" +#include "model/WSServiceBinding.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/core/SCARuntime.h" + +extern "C" +{ + #if defined(WIN32) || defined(_WINDOWS) + __declspec(dllexport) + #endif + void tuscany_sca_extension_initialize() + { + tuscany::sca::ws::WSServiceBindingExtension::initialize(); + } +} + + +namespace tuscany +{ + namespace sca + { + namespace ws + { + // =================================================================== + // Constructor for the WSServiceBinding class. + // =================================================================== + WSServiceBindingExtension::WSServiceBindingExtension() + { + LOGENTRY(1, "WSServiceBindingExtension::constructor"); + LOGEXIT(1, "WSServiceBindingExtension::constructor"); + } + + // =================================================================== + // Destructor for the WSServiceBindingExtension class. + // =================================================================== + WSServiceBindingExtension::~WSServiceBindingExtension() + { + LOGENTRY(1, "WSServiceBindingExtension::destructor");; + LOGEXIT(1, "WSServiceBindingExtension::destructor"); + } + + const string WSServiceBindingExtension::extensionName("ws"); + const string WSServiceBindingExtension::typeQName("http://www.osoa.org/xmlns/sca/1.0#WebServiceBinding"); + + + // =================================================================== + // loadModelElement - load the info from binding.ws + // =================================================================== + ServiceBinding* WSServiceBindingExtension::getServiceBinding(Composite *composite, Service* service, DataObjectPtr scdlBinding) + { + string bindingType = scdlBinding->getType().getName(); + if (bindingType == "WebServiceBinding") + { + string uri = scdlBinding->getCString("uri"); + string endpoint = scdlBinding->getCString("endpoint"); + commonj::sdo::DataObjectList& soap = scdlBinding->getList("soapbinding"); + string version; + if (soap.size()!=0) + { + version = soap.getCString(0); + } + else + { + version = ""; + } + + WSServiceBinding* serviceBinding = new WSServiceBinding(service, uri, endpoint, version); + + return serviceBinding; + } + else + { + return NULL; + } + } + + void WSServiceBindingExtension::initialize() + { + LOGENTRY(1, "WSServiceBindingExtension::initialize");; + SCARuntime::getInstance()->registerServiceBindingExtension(new WSServiceBindingExtension()); + LOGEXIT(1, "WSServiceBindingExtension::initialize");; + } + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/WSServiceBindingExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/WSServiceBindingExtension.h new file mode 100644 index 0000000000..db2c0c791f --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/WSServiceBindingExtension.h @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + + +#ifndef tuscany_sca_extension_ws_wsservicebindingextension_h +#define tuscany_sca_extension_ws_wsservicebindingextension_h + +#include "tuscany/sca/extension/ServiceBindingExtension.h" + +namespace tuscany +{ + namespace sca + { + namespace ws + { + + class WSServiceBindingExtension : public ServiceBindingExtension + { + public: + /** + * Default constructor + */ + WSServiceBindingExtension(); + + /** + * Destructor + */ + virtual ~WSServiceBindingExtension(); + + /** + * return the name of the extension + */ + virtual const string& getExtensionName() {return extensionName;} + + /** + * return the QName of schema elemant for this implementation extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#binding.ws") + */ + virtual const string& getExtensionTypeQName() {return typeQName;} + + virtual ServiceBinding* getServiceBinding(Composite* composite, Service* service, DataObjectPtr scdlBinding); + + static void initialize(); + + private: + static const string extensionName; + static const string typeQName; + + }; + + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany + +#endif //tuscany_sca_extension_ws_wsservicebindingextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/WSServiceWrapper.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/WSServiceWrapper.cpp new file mode 100644 index 0000000000..5839aa8722 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/WSServiceWrapper.cpp @@ -0,0 +1,110 @@ +/* + * 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: 4091) +#endif + +#include "tuscany/sca/util/Logging.h" +#include "Axis2Client.h" +#include "WSServiceWrapper.h" +#include "tuscany/sca/core/Operation.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/ServiceType.h" + +#include "commonj/sdo/SDO.h" +using namespace commonj::sdo; + +using namespace tuscany::sca; +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace ws + { + + WSServiceWrapper::WSServiceWrapper(Service* service) : ServiceWrapper(service) + { + // Define the SOAP Body type and element to allow a SOAP body to + // be loaded in a DataObject + DataFactoryPtr dataFactory = service->getComponent()->getComposite()->getDataFactory(); + try { + const Type& bodyType = dataFactory->getType("http://www.w3.org/2003/05/soap-envelope", "Body"); + } catch (SDORuntimeException e) + { + dataFactory->addType("http://www.w3.org/2003/05/soap-envelope", "RootType", false, false, false); + dataFactory->addType("http://www.w3.org/2003/05/soap-envelope", "Body", false, true, false); + dataFactory->addPropertyToType( + "http://www.w3.org/2003/05/soap-envelope", "RootType", + "Body", + "http://www.w3.org/2003/05/soap-envelope", "Body", + false, false, true); + + dataFactory->addType("http://schemas.xmlsoap.org/soap/envelope/", "RootType", false, false, false); + dataFactory->addType("http://schemas.xmlsoap.org/soap/envelope/", "Body", false, true, false); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/soap/envelope/", "RootType", + "Body", + "http://schemas.xmlsoap.org/soap/envelope/", "Body", + false, false, true); + } + } + + WSServiceWrapper::~WSServiceWrapper() + { + } + + /// + /// This method will be called when a web service call needs to be made. + /// + void WSServiceWrapper::invoke(Operation& operation) + { + LOGENTRY(1, "WSServiceWrapper::invoke"); + + const string& operationName = operation.getName(); + + LOGINFO_2(2,"Service: %s, Operation: %s", getService()->getType()->getName().c_str() , operationName.c_str()); + + for (unsigned int i=0; i<operation.getNParms(); i++) + { + LOGINFO_2(2, "Parameter %p, Type %u", operation.getParameterValue(i),(int) operation.getParameterType(i)); + } + + // Create the Axis2 client that will handle the Web Service invocation + Service* service = getService(); + CompositeReference* compositeReference = (CompositeReference*)service->getComponent(); + + Axis2Client client(compositeReference); + client.invoke(operation); + + LOGEXIT(1, "WSServiceWrapper::invoke"); + } + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany + + + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/WSServiceWrapper.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/WSServiceWrapper.h new file mode 100644 index 0000000000..93607db4a2 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/WSServiceWrapper.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_extension_ws_wsservicewrapper_h +#define tuscany_sca_extension_ws_wsservicewrapper_h + +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/core/Operation.h" +#include "tuscany/sca/model/Service.h" + +using namespace tuscany::sca::model; + + +namespace tuscany +{ + namespace sca + { + + namespace ws + { + + class WSServiceWrapper : public ServiceWrapper + { + public: + + /** + * Constructor. + * @param target The service wrapper represents a Web service. + */ + WSServiceWrapper(Service* service); + + /** + * Destructor + */ + virtual ~WSServiceWrapper(); + + /** + * 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); + }; + } // End namespace ws + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ws_wsservicewrapper_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/model/WSServiceBinding.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/model/WSServiceBinding.cpp new file mode 100644 index 0000000000..8980ec489b --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/model/WSServiceBinding.cpp @@ -0,0 +1,134 @@ +/* + * 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/ws/model/WSServiceBinding.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/ws/WSServiceWrapper.h" + +namespace tuscany +{ + namespace sca + { + namespace ws + { + + // Constructor + WSServiceBinding::WSServiceBinding(Service* service, const string& uri, const string& endpoint, const string& version) + : ServiceBinding(service, uri), endpoint(endpoint), soapVersion(version) + { + parseEndpoint(); + + serviceWrapper = new WSServiceWrapper(service); + } + + void WSServiceBinding::parseEndpoint() + { + // Endpoint is of the form: <wsdl-namepace-uri>#wsdl.endpoint(<service-name>/<endpoint-name>) + string::size_type hash = endpoint.find("#"); + if (hash != string::npos) + { + // Found a hash + + // Namepace is the part before the # + wsdlNamespaceURL = endpoint.substr(0, hash); + + + if ( (hash+1) < endpoint.length()) + { + // Check the next part is wsdl.endpoint( + int ending = hash+15; + string check = endpoint.substr(hash+1, 14); + if (check.compare("wsdl.endpoint(") == 0) + { + // Find the matching ) + int endBracket = endpoint.find(")",ending); + if (endBracket-1 > ending+1) + { + string serviceAndEndpoint = endpoint.substr(ending, endBracket-ending); + // Look for a '/' + string::size_type slash = serviceAndEndpoint.find("/"); + if (slash != string::npos) + { + serviceName = serviceAndEndpoint.substr(0, slash); + + if ( (slash+1) < serviceAndEndpoint.length()) + { + endpointName = serviceAndEndpoint.substr(slash+1); + } + else + { + endpointName = ""; + } + + } + else + { + // No '/' so all of it is the service name + serviceName = serviceAndEndpoint; + endpointName = ""; + + } + } + else + { + // Nothing between the () + serviceName = ""; + endpointName = ""; + } + } + else + { + // not the correct characters after the #, ignore the rest + serviceName = ""; + endpointName = ""; + } + + } + else + { + // Nothing after the hash + serviceName = ""; + endpointName = ""; + } + } + else + { + // No hash at all + wsdlNamespaceURL = endpoint; + serviceName = ""; + endpointName = ""; + } + } + + // Destructor + WSServiceBinding::~WSServiceBinding() + { + } + + ServiceWrapper* WSServiceBinding::getServiceWrapper() + { + return serviceWrapper; + } + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/model/WSServiceBinding.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/model/WSServiceBinding.h new file mode 100644 index 0000000000..15691ce6eb --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/axis2c/src/tuscany/sca/ws/model/WSServiceBinding.h @@ -0,0 +1,137 @@ +/* + * 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_ws_model_wsservicebinding_h +#define tuscany_sca_extension_ws_model_wsservicebinding_h + +#include "tuscany/sca/model/ServiceBinding.h" +#include "tuscany/sca/model/Service.h" + +#include <string> +using std::string; + +namespace tuscany +{ + namespace sca + { + namespace ws + { + /** + * Information about a web service binding for service or a reference. + */ + class WSServiceBinding : public model::ServiceBinding + { + public: + + /** + * Constructor. + * @param uri The uri of the binding. + * @param endpoint The definition of the endpoint to which the service + * or reference is to be bound. This is of the form + * "namespace"#endpoint("service"/"endpoint") + */ + WSServiceBinding(model::Service* service, const string& uri, const string& endpoint, const string& version); + + /** + * Destructor. + */ + virtual ~WSServiceBinding(); + + /** + * Returns the type of binding. + */ + virtual string getType() { return "http://www.osoa.org/xmlns/sca/1.0#WebServiceBinding"; }; + + /** + * Create a wrapper for the service configured by this + * binding. + */ + virtual ServiceWrapper* getServiceWrapper(); + + /** + * Return the part of the endpoint definition describing the wsdl + * namespace. + * @return The wsdl namespace. + */ + string getWSDLNamespaceURL() const { return wsdlNamespaceURL; }; + + /** + * Return the service part of the endpoint definition. + * @return The service to use. + */ + string getServiceName() const { return serviceName; }; + + /** + * Return the endpoint name part of the endpoint definition. + * @return The endpoint name to use. + */ + string getEndpointName() const { return endpointName; }; + + /** + * Return the SOAP version. + * @return The SOAP version to use. + */ + string getSOAPVersion() const { return soapVersion; }; + + private: + + /** + * Parse the endpoint specification. + */ + void parseEndpoint(); + + /** + * The full endpoint string. + */ + string endpoint; + + /** + * Namespace from the endpoint. + */ + string wsdlNamespaceURL; + + /** + * Service name from the endpoint. + */ + string serviceName; + + /** + * WSDL Endpoint name. + */ + string endpointName; + + /** + * SOAP version. + */ + string soapVersion; + + /** + * The wrapper for the service configured by this binding. + */ + ServiceWrapper* serviceWrapper; + + }; + + } // End namespace model + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_extension_ws_model_wsservicebinding_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/deploy.bat b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/deploy.bat new file mode 100644 index 0000000000..2bba10425c --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/reference/deploy.bat @@ -0,0 +1,65 @@ +@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 extdir=%deploydir%\extensions +set wsextdir=%extdir%\ws +set refextdir=%wsextdir%\reference +set srcdir=%rootdir%\runtime\extensions\ws\reference + +if . == .%2 ( +echo input directory not specified +goto usage +) +set inpath=%2 +echo %inpath% + +call %srcdir%\..\deploy.bat %rootdir% + +if not exist %deploydir% mkdir %deploydir% +if not exist %extdir% mkdir %extdir% +if not exist %wsextdir% mkdir %wsextdir% +if not exist %refextdir% mkdir %refextdir% +if not exist %refextdir%\bin mkdir %refextdir%\bin +if not exist %refextdir%\lib mkdir %refextdir%\lib + +set libname=tuscany_sca_ws_reference + +del %refextdir%\bin\%libname%.* +del %refextdir%\lib\%libname%.* + +copy %inpath%\%libname%.lib %refextdir%\lib +copy %inpath%\%libname%.dll %refextdir%\bin + +if exist %inpath%\%libname%.pdb copy %inpath%\%libname%.pdb %refextdir%\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/extensions/ws/service/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/Makefile.am new file mode 100644 index 0000000000..18e9ba89b9 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/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 = axis2c diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/Makefile.am new file mode 100644 index 0000000000..feadf9e317 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/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
\ No newline at end of file diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/Makefile.am new file mode 100644 index 0000000000..37ab185259 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/Makefile.am @@ -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. + +libdir=$(prefix)/extensions/ws/service/lib +lib_LTLIBRARIES = \ +libtuscany_sca_ws_service.la \ +libtuscany_sca_ws_dispatcher.la + +noinst_HEADERS = \ +tuscany/sca/ws/*.h \ +tuscany/sca/ws/model/*.h + +libtuscany_sca_ws_service_la_SOURCES = \ +tuscany/sca/ws/WSReferenceBindingExtension.cpp \ +tuscany/sca/ws/model/WSReferenceBinding.cpp \ +tuscany/sca/ws/WSServiceProxy.cpp \ +tuscany/sca/ws/Axis2Service.cpp \ +tuscany/sca/ws/Axis2Utils.cpp + +libtuscany_sca_ws_service_la_LIBADD = \ + -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo -ltuscany_sdo_axiom \ + -L$(top_builddir)/runtime/core/src -ltuscany_sca \ + -L$(AXIS2C_HOME)/lib \ + -laxis2_util \ + -laxis2_axiom \ + -laxis2_wsdl \ + -laxis2_engine \ + -laxis2_parser \ + -laxis2_minizip \ + -lpthread \ + -lwoden \ + -laxis2_http_sender \ + -laxis2_http_receiver + +rootdir=$(prefix)/extensions/ws/service +root_DATA = axis2.xml +root_SCRIPTS = deploy.sh + +libtuscany_sca_ws_dispatcher_la_SOURCES = \ +tuscany/sca/ws/Axis2Dispatcher.cpp \ +tuscany/sca/ws/Axis2DispatcherModule.cpp + +libtuscany_sca_ws_dispatcher_la_LIBADD = \ + -L$(AXIS2C_HOME)/lib \ + -laxis2_util \ + -laxis2_axiom \ + -laxis2_wsdl \ + -laxis2_engine \ + -laxis2_parser \ + -laxis2_minizip \ + -lpthread \ + -lwoden \ + -laxis2_http_sender \ + -laxis2_http_receiver + +servicedir=$(rootdir)/services/tuscany +service_DATA = services.xml + +moduledir=$(rootdir)/modules/tuscany +module_DATA = module.xml + +EXTRA_DIST = axis2.xml services.xml module.xml deploy.sh + +install-data-hook: + cd $(servicedir); ln -s -f ../../lib/libtuscany_sca_ws_service.so libtuscany_sca_ws_service.so + cd $(moduledir); ln -s -f ../../lib/libtuscany_sca_ws_dispatcher.so libtuscany_sca_ws_dispatcher.so + +INCLUDES = -I$(top_builddir)/runtime/core/src \ + -I${TUSCANY_SDOCPP}/include \ + -I${AXIS2C_HOME}/include + +AM_CPPFLAGS = $(CPPFLAGS) -D_DEBUG diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/axis2.xml b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/axis2.xml new file mode 100644 index 0000000000..641085466e --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/axis2.xml @@ -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. +--> +<axisconfig name="Axis2/C"> + <!-- ================================================= --> + <!-- Parameters --> + <!-- ================================================= --> + <parameter name="hotdeployment" locked="false">false</parameter> + <parameter name="hotupdate" locked="false">false</parameter> + <parameter name="enableMTOM" locked="false">false</parameter> + <parameter name="enableREST" locked="false">true</parameter> + + <parameter name="userName" locked="false">admin</parameter> + <parameter name="password" locked="false">axis2</parameter> + + <parameter name="seralizeLocation" locked="false">.</parameter> + <hostConfiguration> + <ip>127.0.0.1</ip> + <port>5555</port> + </hostConfiguration> + + + <!--if you want to extract the service archive file and work with that please uncomment this--> + <!--else , it wont extract archive file or does not take into consideration if someone drop--> + <!--exploded directory into /service directory--> + <!--<parameter name="extractServiceArchive" locked="false">true</parameter>--> + + + <!-- The way of adding listener to the system--> + <!-- <listener class="org.apache.axis2.ObserverIMPL">--> + <!-- <parameter name="RSS_URL" locked="false">http://127.0.0.1/rss</parameter>--> + <!-- </listener>--> + + <!-- ================================================= --> + <!-- Message Receivers --> + <!-- ================================================= --> + <!-- This is the Deafult Message Receiver for the Request Response style Operations --> + <!--messageReceiver mep="INOUT" class="axis2_receivers"/--> + + <!-- ================================================= --> + <!-- Transport Ins --> + <!-- ================================================= --> + <transportReceiver name="http" class="axis2_http_receiver"> + <parameter name="port" locked="false">6060</parameter> + </transportReceiver> + + <!-- Uncomment this one with the appropriate papameters to enable the SMTP transport Receiver + <transportReceiver name="mail" class="org.apache.axis2.transport.mail.SimpleMailListener"> + <parameter name="transport.mail.pop3.host" locked="false">127.0.0.1</parameter> + <parameter name="transport.mail.pop3.user" locked="false">axis2</parameter> + <parameter name="transport.mail.pop3.password" locked="false">axis2</parameter> + <parameter name="transport.mail.pop3.port" locked="false">110</parameter> + <parameter name="transport.mail.replyToAddress" locked="false">axis2@127.0.0.1</parameter> + </transportReceiver> --> + + <!-- + <transportReceiver name="tcp" class="org.apache.axis2.transport.tcp.TCPServer"> + <parameter name="port" locked="false">6060</parameter> + </transportReceiver> + --> + <!-- ================================================= --> + <!-- Transport Outs --> + <!-- ================================================= --> + + <!-- + <transportSender name="tcp" class="org.apache.axis2.transport.tcp.TCPTransportSender"/> + <transportSender name="local" class="org.apache.axis2.transport.local.LocalTransportSender"/> + --> + <transportSender name="http" class="axis2_http_sender"> + <parameter name="PROTOCOL" locked="false">HTTP/1.1</parameter> + <!--parameter name="Transfer-Encoding">chunked</parameter--> + <!--parameter name="PROXY" proxy_host="127.0.0.1" proxy_port="8080" locked="true"/--> + </transportSender> + <!-- + <transportSender name="https" class="axis2_http_sender"> + <parameter name="PROTOCOL" locked="false">HTTP/1.1</parameter> + </transportSender> + --> + <!-- Uncomment this one with the appropriate papameters to enable the SMTP transport Receiver + <transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender"> + <parameter name="transport.mail.smtp.host" locked="false">127.0.0.1</parameter> + <parameter name="transport.mail.smtp.user" locked="false">axis2</parameter> + <parameter name="transport.mail.smtp.password" locked="false">axis2</parameter> + <parameter name="transport.mail.smtp.port" locked="false">25</parameter> + </transportSender> + --> + + <!-- ================================================= --> + <!-- Global Modules --> + <!-- ================================================= --> + <!-- Comment this to disable Addressing --> + <module ref="addressing"/> + + <module ref="tuscany"/> + + <!--Configuring module , providing paramters for modules whether they refer or not--> + <!--<moduleConfig name="addressing">--> + <!--<parameter name="addressingPara" locked="false">N/A</parameter>--> + <!--</moduleConfig>--> + + <!-- ================================================= --> + <!-- Phases --> + <!-- ================================================= --> + <phaseOrder type="inflow"> + <!-- System pre defined phases --> + <phase name="TransportIn"/> + <phase name="PreDispatch"/> + <phase name="Dispatch"> + <handler name="AddressingBasedDispatcher" + class="axis2_engine"> + <order phase="Dispatch"/> + </handler> + <handler name="RequestURIBasedDispatcher" + class="axis2_engine"> + <order phase="Dispatch"/> + </handler> + <handler name="SOAPActionBasedDispatcher" + class="axis2_engine"> + <order phase="Dispatch"/> + </handler> + <handler name="SOAPMessageBodyBasedDispatcher" + class="axis2_engine"> + <order phase="Dispatch"/> + </handler> + </phase> + <phase name="PostDispatch"> + <handler name="DispatchPostConditionsEvaluator" + class="axis2_engine"> + <order phase="PostDispatch"/> + </handler> + <handler name="InstanceDispatcher" + class="axis2_engine"> + <order phase="PostDispatch"/> + </handler> + <handler name="SOAPProcessingModelChecker" + class="axis2_engine"> + <order phase="PostDispatch"/> + </handler> + </phase> + <!-- System pre defined phases --> + <!-- After Postdispatch phase module author or or service author can add any phase he want --> + <!--phase name="userphase1"/--> + </phaseOrder> + <phaseOrder type="outflow"> + <!-- user can add his own phases to this area --> + <!--phase name="RMPhase"/--> + <!--phase name="userphase1"/--> + <!--system predefined phase--> + <!--these phase will run irrespective of the service--> + <!--phase name="PolicyDetermination"/--> + <!--phase name="MessageOut"/--> + </phaseOrder> + <phaseOrder type="INfaultflow"> + <!-- user can add his own phases to this area --> + <!--phase name="userphase1"/--> + <!--phase name="RMPhase"/--> + </phaseOrder> + <phaseOrder type="Outfaultflow"> + <!-- user can add his own phases to this area --> + <!--phase name="RMPhase"/--> + <!--phase name="userphase1"/--> + <!--phase name="PolicyDetermination"/--> + <phase name="MessageOut"/> + </phaseOrder> +</axisconfig> + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/deploy.cmd b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/deploy.cmd new file mode 100644 index 0000000000..6493e1cec9 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/deploy.cmd @@ -0,0 +1,39 @@ +@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.
+
+
+rem Will deploy the Tuscany SCA WS service Axis2C service and module
+rem to the correct places within the AXIS2C_HOME directory
+setlocal
+set currentPath=%~d0%~p0
+
+if "%AXIS2C_HOME%" == "" (
+echo "AXIS2C_HOME not set"
+goto end
+)
+echo Deploying to Axis2C installed at %AXIS2C_HOME%
+
+if not exist %AXIS2C_HOME%\services\tuscany mkdir %AXIS2C_HOME%\services\tuscany
+if not exist %AXIS2C_HOME%\modules\tuscany mkdir %AXIS2C_HOME%\modules\tuscany
+
+copy %currentPath%\services\tuscany\* %AXIS2C_HOME%\services\tuscany
+copy %currentPath%\modules\tuscany\* %AXIS2C_HOME%\modules\tuscany
+copy %currentPath%\axis2.xml %AXIS2C_HOME%\axis2.xml
+
+:end
+endlocal
diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/deploy.sh b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/deploy.sh new file mode 100755 index 0000000000..ffe571b0ee --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/deploy.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +# 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. + +APFULLDIR=`pwd` + +if [ x$AXIS2C_HOME = x ]; then +echo "AXIS2C_HOME not set" +exit; +fi +echo "Deploying to Axis2C installed at $AXIS2C_HOME" + +if ! [ -d $AXIS2C_HOME/services/tuscany ]; then + mkdir $AXIS2C_HOME/services/tuscany +fi + +if ! [ -d $AXIS2C_HOME/modules/tuscany ]; then + mkdir $AXIS2C_HOME/modules/tuscany +fi + +cp $APFULLDIR/services/tuscany/services.xml $AXIS2C_HOME/services/tuscany + +if ! [ -f $AXIS2C_HOME/services/tuscany/libtuscany_sca_ws_service.so ]; then + ln -s $APFULLDIR/services/tuscany/libtuscany_sca_ws_service.so $AXIS2C_HOME/services/tuscany/libtuscany_sca_ws_service.so +fi + +cp $APFULLDIR/modules/tuscany/module.xml $AXIS2C_HOME/modules/tuscany +if ! [ -f $AXIS2C_HOME/modules/tuscany/libtuscany_sca_ws_dispatcher.so ]; then + ln -s $APFULLDIR/modules/tuscany/libtuscany_sca_ws_dispatcher.so $AXIS2C_HOME/modules/tuscany/libtuscany_sca_ws_dispatcher.so +fi + +cp $APFULLDIR/axis2.xml $AXIS2C_HOME/axis2.xml diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/module.xml b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/module.xml new file mode 100644 index 0000000000..97d4d43a86 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/module.xml @@ -0,0 +1,25 @@ +<!-- + 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. +--> +<module name="tuscany" class="tuscany_sca_ws_dispatcher"> + <inflow> + <handler name="TuscanyDispatcher" class="tuscany_sca_ws_dispatcher"> + <order phase="Dispatch"/> + </handler> + </inflow> +</module> diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/services.xml b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/services.xml new file mode 100644 index 0000000000..335d4d96be --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/services.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- + 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. +--> +<serviceGroup> +<service name="TuscanyService"> + <parameter name="ServiceClass" locked="xsd:false">tuscany_sca_ws_service</parameter> + <operation name="execute"/> +</service> +</serviceGroup> diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/Axis2Dispatcher.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/Axis2Dispatcher.cpp new file mode 100644 index 0000000000..fe3eb52064 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/Axis2Dispatcher.cpp @@ -0,0 +1,176 @@ +/* + * 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) +#pragma warning(disable: 4091) +#endif + +#include <axis2_handler_desc.h> +#include <axis2_qname.h> +#include <axis2_relates_to.h> +#include <axis2_svc.h> +#include <axis2_const.h> +#include <axis2_conf_ctx.h> +#include <axis2_addr.h> +#include <axis2_utils.h> +#include <axiom_soap_envelope.h> +#include <axiom_soap_body.h> + +extern "C" +{ + +axis2_status_t AXIS2_CALL +Axis2Dispatcher_invoke ( + axis2_handler_t * handler, + const axis2_env_t *env, + struct axis2_msg_ctx *msg_ctx); + +axis2_svc_t *AXIS2_CALL +Axis2Dispatcher_find_svc( + axis2_msg_ctx_t *msg_ctx, + const axis2_env_t *env); + +axis2_op_t *AXIS2_CALL +Axis2Dispatcher_find_op( + axis2_msg_ctx_t *msg_ctx, + const axis2_env_t *env, + axis2_svc_t *svc); + +AXIS2_EXPORT axis2_handler_t* AXIS2_CALL +Axis2Dispatcher_create(const axis2_env_t *env, + axis2_qname_t *qname) +{ + axis2_handler_t *handler = NULL; + + handler = axis2_handler_create(env); + if (!handler) + { + return NULL; + } + + /* handler init is handled by conf loading, so no need to do it here */ + + /* set the base struct's invoke op */ + if (handler->ops) + handler->ops->invoke = Axis2Dispatcher_invoke; + + return handler; +} + +axis2_svc_t *AXIS2_CALL +Axis2Dispatcher_find_svc( + axis2_msg_ctx_t *msg_ctx, + const axis2_env_t *env) +{ + axis2_svc_t *svc = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + axis2_conf_ctx_t *conf_ctx = NULL; + conf_ctx = AXIS2_MSG_CTX_GET_CONF_CTX(msg_ctx, env); + if (conf_ctx) + { + axis2_conf_t *conf = NULL; + conf = AXIS2_CONF_CTX_GET_CONF(conf_ctx, env); + if (conf) + { + axis2_char_t* service_name = "TuscanyService"; + svc = AXIS2_CONF_GET_SVC(conf, env, service_name); + if (svc) + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, + "Service found using target endpoint address"); + } + } + } + + return svc; +} + +axis2_op_t *AXIS2_CALL +Axis2Dispatcher_find_op( + axis2_msg_ctx_t *msg_ctx, + const axis2_env_t *env, + axis2_svc_t *svc) +{ + axis2_op_t *op = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + axis2_qname_t *op_qname = NULL; + axis2_char_t* execute_op_name = "execute"; + op_qname = axis2_qname_create(env, execute_op_name, NULL, NULL); + + op = AXIS2_SVC_GET_OP_WITH_NAME(svc, env, AXIS2_QNAME_GET_LOCALPART(op_qname, env)); + + AXIS2_QNAME_FREE(op_qname, env); + if (op) + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, + "TuscanyService execute operation found"); + } + return op; +} + +axis2_status_t AXIS2_CALL +Axis2Dispatcher_invoke( + axis2_handler_t * handler, + const axis2_env_t *env, + struct axis2_msg_ctx *msg_ctx) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if (!(AXIS2_MSG_CTX_GET_SERVER_SIDE(msg_ctx, env))) + return AXIS2_SUCCESS; + + msg_ctx->ops->find_svc = Axis2Dispatcher_find_svc; + msg_ctx->ops->find_op = Axis2Dispatcher_find_op; + + axis2_svc_t *axis_service = NULL; + axis2_op_t *op = NULL; + + axis_service = AXIS2_MSG_CTX_GET_SVC(msg_ctx, env); + + if (!axis_service) + { + axis_service = AXIS2_MSG_CTX_FIND_SVC(msg_ctx, env); + if (axis_service) + { + AXIS2_MSG_CTX_SET_SVC(msg_ctx, env, axis_service); + /*TODO Set the Service Group Context to the message Context*/ + } + } + op = AXIS2_MSG_CTX_GET_OP(msg_ctx, env); + if (!op) + { + op = AXIS2_MSG_CTX_FIND_OP(msg_ctx, env, axis_service); + + if (op) + { + AXIS2_MSG_CTX_SET_OP(msg_ctx, env, op); + } + } + + return AXIS2_SUCCESS; +} + +} diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/Axis2DispatcherModule.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/Axis2DispatcherModule.cpp new file mode 100644 index 0000000000..0dc8f3358a --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/Axis2DispatcherModule.cpp @@ -0,0 +1,149 @@ +/* + * 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) +#pragma warning(disable: 4091) +#endif + +#include <axis2_module.h> +#include <axis2_addr_mod.h> +#include <axis2_conf_ctx.h> +#include <axis2_disp.h> + +extern "C" +{ + +axis2_status_t AXIS2_CALL +Axis2DispatcherModule_shutdown(axis2_module_t *module, + const axis2_env_t *env); + +axis2_status_t AXIS2_CALL +Axis2DispatcherModule_init( + axis2_module_t *module, + const axis2_env_t *env, + axis2_conf_ctx_t *conf_ctx, + axis2_module_desc_t *module_desc); + +axis2_status_t AXIS2_CALL +Axis2DispatcherModule_fill_handler_create_func_map(axis2_module_t *module, + const axis2_env_t *env); + +AXIS2_EXTERN axis2_handler_t* AXIS2_CALL +Axis2Dispatcher_create(const axis2_env_t *env, + axis2_qname_t *qname); + +axis2_module_t * +Axis2DispatcherModule_create(const axis2_env_t *env) +{ + axis2_module_t *module = NULL; + module = (axis2_module_t*)AXIS2_MALLOC(env->allocator, + sizeof(axis2_module_t)); + + + module->ops = (axis2_module_ops_t*)AXIS2_MALLOC( + env->allocator, sizeof(axis2_module_ops_t)); + + module->ops->shutdown = Axis2DispatcherModule_shutdown; + module->ops->init = Axis2DispatcherModule_init; + module->ops->fill_handler_create_func_map = + Axis2DispatcherModule_fill_handler_create_func_map; + + return module; +} + +axis2_status_t AXIS2_CALL +Axis2DispatcherModule_init( + axis2_module_t *module, + const axis2_env_t *env, + axis2_conf_ctx_t *conf_ctx, + axis2_module_desc_t *module_desc) +{ + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +Axis2DispatcherModule_shutdown(axis2_module_t *module, + const axis2_env_t *env) +{ + if(module->ops) + { + AXIS2_FREE(env->allocator, module->ops); + module->ops = NULL; + } + + if(module->handler_create_func_map) + { + axis2_hash_free(module->handler_create_func_map, env); + module->handler_create_func_map = NULL; + } + + if(module) + { + AXIS2_FREE(env->allocator, module); + module = NULL; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +Axis2DispatcherModule_fill_handler_create_func_map(axis2_module_t *module, + const axis2_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + module->handler_create_func_map = axis2_hash_make(env); + axis2_hash_set(module->handler_create_func_map, "TuscanyDispatcher", + (axis2_ssize_t)AXIS2_HASH_KEY_STRING, (const void *)Axis2Dispatcher_create); + + return AXIS2_SUCCESS; +} + +/** + * Following block distinguish the exposed part of the dll. + */ + +AXIS2_EXPORT int +axis2_get_instance(axis2_module_t **inst, + const axis2_env_t *env) +{ + *inst = Axis2DispatcherModule_create(env); + if(!(*inst)) + { + return AXIS2_FAILURE; + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXPORT int +axis2_remove_instance(axis2_module_t *inst, + const axis2_env_t *env) +{ + axis2_status_t status = AXIS2_FAILURE; + if (inst) + { + status = Axis2DispatcherModule_shutdown(inst, env); + } + return status; +} + +} diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/Axis2Service.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/Axis2Service.cpp new file mode 100644 index 0000000000..046a6e221b --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/Axis2Service.cpp @@ -0,0 +1,506 @@ +/* + * 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) +#pragma warning(disable: 4091) +#endif + +#include <axis2_svc_skeleton.h> +#include <axis2_array_list.h> +#include <axis2_log_default.h> +#include <axis2_error_default.h> +#include <axiom.h> +#include <stdio.h> + +#include <sdo_axiom.h> +using commonj::sdo::DataObjectPtr; +using commonj::sdo::DataFactoryPtr; +using commonj::sdo::DataObjectList; +using commonj::sdo::PropertyList; +using commonj::sdo_axiom::AxiomHelper; + +#include "tuscany/sca/util/Exceptions.h" +#include "WSServiceProxy.h" +#include "model/WSReferenceBinding.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/CompositeService.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/model/WSDLDefinition.h" +#include "tuscany/sca/model/WSDLOperation.h" +#include "tuscany/sca/model/WSDLInterface.h" +#include "tuscany/sca/model/Interface.h" +#include "tuscany/sca/core/TuscanyRuntime.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/util/Utils.h" +#include "Axis2Utils.h" + +using namespace tuscany::sca; +using namespace tuscany::sca::ws; +using namespace tuscany::sca::model; + +int AXIS2_CALL +Axis2Service_free(axis2_svc_skeleton_t *svc_skeleton, + const axis2_env_t *env); + +/* + * This method invokes the right service method + */ +axiom_node_t* AXIS2_CALL +Axis2Service_invoke(axis2_svc_skeleton_t *svc_skeleton, + const axis2_env_t *env, + axiom_node_t *node, + axis2_msg_ctx_t *msg_ctx); + +int AXIS2_CALL Axis2Service_init(axis2_svc_skeleton_t *svc_skeleton, + const axis2_env_t *env); + +axis2_svc_skeleton_t * +axis2_Axis2Service_create(axis2_env_t *env) +{ + axis2_svc_skeleton_t *svc_skeleton = NULL; + svc_skeleton = (axis2_svc_skeleton_t *) AXIS2_MALLOC((env)->allocator, + sizeof(axis2_svc_skeleton_t)); + + + svc_skeleton->ops = (axis2_svc_skeleton_ops_t *) AXIS2_MALLOC( + (env)->allocator, sizeof(axis2_svc_skeleton_ops_t)); + + svc_skeleton->func_array = NULL; + + svc_skeleton->ops->free = Axis2Service_free; + svc_skeleton->ops->init = Axis2Service_init; + svc_skeleton->ops->invoke = Axis2Service_invoke; + /*svc_skeleton->ops->on_fault = Axis2Service_on_fault;*/ + + return svc_skeleton; +} + +int AXIS2_CALL +Axis2Service_init(axis2_svc_skeleton_t *svc_skeleton, + const axis2_env_t *env) +{ + // This method never seems to be called - an old Axis2C artifact? + + svc_skeleton->func_array = axis2_array_list_create(env, 0); + return AXIS2_SUCCESS; +} + +int AXIS2_CALL +Axis2Service_free(axis2_svc_skeleton_t *svc_skeleton, + const axis2_env_t *env) +{ + /*if(svc_skeleton->func_array) + { + AXIS2_ARRAY_LIST_FREE(svc_skeleton->func_array, env); + svc_skeleton->func_array = NULL; + }*/ + + if(svc_skeleton->ops) + { + AXIS2_FREE((env)->allocator, svc_skeleton->ops); + svc_skeleton->ops = NULL; + } + + if(svc_skeleton) + { + AXIS2_FREE((env)->allocator, svc_skeleton); + svc_skeleton = NULL; + } + return AXIS2_SUCCESS; +} + +/** + * Initialize the Tuscany runtime + */ + +static string systemRoot = ""; +static string componentName = ""; +static string serviceName = ""; +static TuscanyRuntime* tuscanyRuntime = NULL; +static CompositeService* compositeService = NULL; + +void initTuscanyRuntime(const axis2_env_t *env, const char* root, const char *component, const char* service) +{ + AXIS2_LOG_INFO((env)->log, "Axis2Service init, root: %s, component: %s, service: %s\n", root, component, service); + try + { + + bool newInitParams = false; + + if(systemRoot != root) + { + systemRoot = root; + newInitParams = true; + } + + if(componentName != component) + { + componentName = component; + newInitParams = true; + } + + if(serviceName != service) + { + serviceName = service; + newInitParams = true; + } + + if(tuscanyRuntime == NULL) + { + AXIS2_LOG_INFO((env)->log, "Creating new Tuscany runtime\n"); + tuscanyRuntime = new TuscanyRuntime(componentName, systemRoot); + tuscanyRuntime->start(); + } + else if(tuscanyRuntime != NULL && newInitParams) + { + AXIS2_LOG_INFO((env)->log, "Restarting Tuscany runtime\n"); + tuscanyRuntime->stop(); + tuscanyRuntime->setDefaultComponentName(componentName); + tuscanyRuntime->setSystemRoot(systemRoot); + tuscanyRuntime->start(); + } + + if(compositeService == NULL) + { + Composite* composite = (Composite*)SCARuntime::getInstance()->getDefaultComponent()->getType(); + compositeService = (CompositeService*)composite->findComponent(serviceName); + } + else + { + if(newInitParams) + { + Composite* composite = SCARuntime::getInstance()->getDefaultComponent()->getComposite(); + compositeService = (CompositeService*)composite->findComponent(serviceName); + } + } + } + catch(TuscanyRuntimeException &ex) + { + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "%s has been caught: %s\n", ex.getEClassName(), ex.getMessageText()); + } +} + + +/* + * This method invokes the target service method + */ +axiom_node_t* AXIS2_CALL +Axis2Service_invoke(axis2_svc_skeleton_t *svc_skeleton, + const axis2_env_t *env, + axiom_node_t *node, + axis2_msg_ctx_t *msg_ctx) +{ + if (node) + { + if (AXIOM_NODE_GET_NODE_TYPE(node, env) == AXIOM_ELEMENT) + { + axiom_element_t *element = NULL; + element = (axiom_element_t *)AXIOM_NODE_GET_DATA_ELEMENT(node, env); + if (element) + { + string op_name = ""; + axis2_bool_t rest = AXIS2_MSG_CTX_GET_DOING_REST(msg_ctx, env); + if (rest) + { + axis2_endpoint_ref_t *endpoint_ref = AXIS2_MSG_CTX_GET_FROM(msg_ctx, env); + if (endpoint_ref) + { + const axis2_char_t *address = AXIS2_ENDPOINT_REF_GET_ADDRESS(endpoint_ref, env); + if (address) + { + axis2_char_t **url_tokens = axis2_parse_request_url_for_svc_and_op(env, address); + if (url_tokens) + { + if (url_tokens[1]) + { + op_name = url_tokens[1]; + } + if (NULL != url_tokens[1]) + AXIS2_FREE(env->allocator, url_tokens[1]); + if (NULL != url_tokens[0]) + AXIS2_FREE(env->allocator, url_tokens[0]); + AXIS2_FREE(env->allocator, url_tokens); + } + } + } + } + else + { + // This gets the operation name from the root element name - this is correct for DocLit Wrapped style + op_name = AXIOM_ELEMENT_GET_LOCALNAME(element, env); + } + + if (op_name != "") + { + // Get the Tuscany system root and composite service name from the Axis2 + // service parameters + char* rootParam = Axis2Utils::getAxisServiceParameterValue(env, msg_ctx, "TuscanySystemRoot"); + if (rootParam == NULL) + rootParam = ""; + + char* serviceParam = Axis2Utils::getAxisServiceParameterValue(env, msg_ctx, "TuscanyService"); + if (serviceParam != NULL) + { + AXIS2_LOG_INFO((env)->log, "Axis2Service invoke called with system root: %s, service name: %s, operation name: %s", rootParam, serviceParam, op_name.c_str()); + + // Service is of the form "component name"/"composite service name" + string component, service; + Utils::rTokeniseString("/", serviceParam, component, service); + + initTuscanyRuntime(env, rootParam, component.c_str(), service.c_str()); + } + else { + + // Use the default system root and component, the service is + // derived from the target address + axis2_endpoint_ref_t *endpoint_ref = NULL; + endpoint_ref = AXIS2_MSG_CTX_GET_FROM(msg_ctx, env); + axis2_char_t *address = NULL; + address = (axis2_char_t*) AXIS2_ENDPOINT_REF_GET_ADDRESS(endpoint_ref, env); + axis2_char_t **url_tokens = NULL; + url_tokens = axis2_parse_request_url_for_svc_and_op(env, address); + string service(url_tokens[0]); + + AXIS2_LOG_INFO((env)->log, "Axis2Service invoke called with system root: %s, service name: %s, operation name: %s", rootParam, service.c_str(), op_name.c_str()); + + initTuscanyRuntime(env, rootParam, "", service.c_str()); + } + + if(!compositeService) + { + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "Axis2Service_invoke: Tuscany initialisation failed"); + return 0; + } + + DataFactoryPtr dataFactory = compositeService->getComposite()->getDataFactory(); + if (dataFactory == 0) + { + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "Axis2Service_invoke: CompositeService has no SCA implementation"); + return 0; + } + + // Get the WS binding and the WSDL operation + Composite* composite = compositeService->getComposite(); + Reference* reference = compositeService->getReference(); + WSReferenceBinding* binding = (WSReferenceBinding*)reference->getBinding(); + WSDLOperation wsdlOperation; + + string wsdlNamespace = binding->getWSDLNamespaceURL(); + if (wsdlNamespace != "") + { + + // Lookup the WSDL model from the composite, keyed on the namespace + // (the wsdl will have been loaded at startup) + WSDLDefinition* wsdlDefinition = composite->findWSDLDefinition(wsdlNamespace); + if (wsdlDefinition == 0) + { + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "WSDL description %s not found\n", wsdlNamespace.c_str()); + string msg = "WSDL not found for " + wsdlNamespace; + throw SystemConfigurationException(msg.c_str()); + } + + // Find the target operation in the wsdl port type. + try { + wsdlOperation = wsdlDefinition->findOperation( + binding->getServiceName(), + binding->getEndpointName(), + op_name.c_str()); + } + catch(SystemConfigurationException &ex) + { + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "SystemConfigurationException has been caught: %s\n", ex.getMessageText()); + throw; + } + + } + else + { + Interface* iface = reference->getType()->getInterface(); + if (iface != NULL && + iface->getInterfaceTypeQName() == WSDLInterface::typeQName) + { + WSDLInterface* wsdlInterface = (WSDLInterface*)iface; + wsdlNamespace = wsdlInterface->getNamespaceURI(); + + if (wsdlNamespace != "") + { + + WSDLDefinition* wsdl = composite->findWSDLDefinition(wsdlNamespace); + if (wsdl == 0) + { + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "WSDL description %s not found\n", wsdlNamespace.c_str()); + string msg = "WSDL not found for " + wsdlNamespace; + throw SystemConfigurationException(msg.c_str()); + } + + try + { + wsdlOperation = wsdl->findOperation(wsdlInterface->getName(), op_name.c_str()); + } + catch(SystemConfigurationException &ex) + { + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "SystemConfigurationException has been caught: %s\n", ex.getMessageText()); + throw; + } + } + } + } + + if (wsdlNamespace == "") + { + // Create a default document literal wrapped WSDL operation + wsdlNamespace = compositeService->getName(); + wsdlOperation = WSDLOperation(); + wsdlOperation.setOperationName(op_name.c_str()); + wsdlOperation.setSoapAction(wsdlNamespace+ "#" +op_name); + wsdlOperation.setEndpoint(""); + wsdlOperation.setSoapVersion(WSDLOperation::SOAP11); + wsdlOperation.setDocumentStyle(true); + wsdlOperation.setWrappedStyle(true); + wsdlOperation.setEncoded(false); + wsdlOperation.setInputType(wsdlNamespace + "#" + op_name); + wsdlOperation.setOutputType(wsdlNamespace + "#" + op_name + "Response"); + } + + // Convert the input AXIOM node to an SDO DataObject + axiom_node_t* body = AXIOM_NODE_GET_PARENT(node, env); + char* str = NULL; + str = AXIOM_NODE_TO_STRING(body, env); + if (str) + { + AXIS2_LOG_INFO((env)->log, "Axis2Service invoke has request OM: %s\n", str); + } + + // Convert the SOAP body to an SDO DataObject + AxiomHelper* axiomHelper = AxiomHelper::getHelper(); + DataObjectPtr inputBodyDataObject = NULL; + + try + { + inputBodyDataObject = axiomHelper->toSdo(body, dataFactory); + } + catch(SDORuntimeException &ex) + { + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "Axis2Service_invoke: SDORuntimeException thrown: %s", ex.getMessageText()); + } + + if(!inputBodyDataObject) + { + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "Axis2Service_invoke: Could not convert received Axiom node to SDO"); + /** TODO: return a SOAP fault here */ + return 0; + } + + // Get the first body part representing the doc-lit-wrapped wrapper element + DataObjectPtr inputDataObject = NULL; + PropertyList bpl = inputBodyDataObject->getInstanceProperties(); + if (bpl.size()!=0) + { + if (bpl[0].isMany()) + { + DataObjectList& parts = inputBodyDataObject->getList((unsigned int)0); + inputDataObject = parts[0]; + } + else + { + inputDataObject = inputBodyDataObject->getDataObject(bpl[0]); + } + } + if (inputDataObject == NULL) + { + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "Axis2Service_invoke: Could not convert body part to SDO"); + return 0; + } + + // Dispatch to the WS proxy + WSServiceProxy* proxy = (WSServiceProxy*)binding->getServiceProxy(); + + DataObjectPtr outputDataObject = proxy->invoke(wsdlOperation, inputDataObject); + + if(!outputDataObject) + { + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "Axis2Service_invoke: Failure whilst invoking CompositeService"); + + /** TODO: return a SOAP fault here */ + return 0; + } + + // Convert the output DataObject to an Axiom node + axiom_node_t* outputNode = axiomHelper->toAxiomNode(outputDataObject, + wsdlOperation.getOutputTypeUri().c_str(), wsdlOperation.getOutputTypeName().c_str()); + + AxiomHelper::releaseHelper(axiomHelper); + + str = AXIOM_NODE_TO_STRING(outputNode, env); + if (str) + { + AXIS2_LOG_INFO((env)->log, "Axis2Service invoke has response OM : %s\n", str); + } + + + //LOGEXIT(1, "Axis2Service_invoke"); + return outputNode; + } + } + } + } + + AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "Axis2Service_invoke: invalid OM parameters in request"); + //LOGERROR(0, "Axis2Service service ERROR: invalid OM parameters in request\n"); + + /** TODO: return a SOAP fault here */ + return 0; +} + + +extern "C" +{ + +/** + * Following block distinguish the exposed part of the dll. + */ + +AXIS2_EXPORT int axis2_get_instance(axis2_svc_skeleton **inst, + axis2_env_t *env) +{ + *inst = axis2_Axis2Service_create(env); + if(!(*inst)) + { + return AXIS2_FAILURE; + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXPORT int axis2_remove_instance(axis2_svc_skeleton_t *inst, + axis2_env_t *env) +{ + axis2_status_t status = AXIS2_FAILURE; + if (inst) + { + status = AXIS2_SVC_SKELETON_FREE(inst, env); + } + return status; +} +} diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/Axis2Utils.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/Axis2Utils.cpp new file mode 100644 index 0000000000..7a30ab2994 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/Axis2Utils.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$ */ + +#if defined(WIN32) || defined (_WINDOWS) +#pragma warning(disable: 4786) +#pragma warning(disable: 4091) +#endif +#include "Axis2Utils.h" + +#include <axis2_svc_ctx.h> +#include <axis2_defines.h> + +#include "tuscany/sca/util/Logging.h" + +using namespace tuscany::sca; +using namespace tuscany::sca::ws; + + +/* Static utility method to retrieve service parameters from the service.xml file + * Get an odd linking error if this method (or the header's it requires) are in + * a different class. + */ +char* Axis2Utils::getAxisServiceParameterValue(const axis2_env_t *env, axis2_msg_ctx_t *msg_ctx, char* parameterName) +{ + struct axis2_svc *svc = NULL; + struct axis2_op_ctx *op_ctx = NULL; + struct axis2_svc_ctx *svc_ctx = NULL; + axis2_param_t *param = NULL; + char* paramValue = NULL; + + LOGENTRY(1, "Axis2Utils::getAxisServiceParameterValue"); + + op_ctx = AXIS2_MSG_CTX_GET_OP_CTX(msg_ctx, env); + svc_ctx = AXIS2_OP_CTX_GET_PARENT(op_ctx, env); + svc = AXIS2_SVC_CTX_GET_SVC(svc_ctx, env); + if(NULL == svc) + { + return NULL; + } + + param = AXIS2_SVC_GET_PARAM(svc, env, parameterName); + if(!param) + { + LOGERROR_1(1,"Axis parameter %s cannot be found", parameterName); + } + else + { + paramValue = (char*) AXIS2_PARAM_GET_VALUE(param, env); + } + + LOGEXIT(1, "Axis2Utils::getAxisServiceParameterValue"); + return paramValue; +} + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/Axis2Utils.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/Axis2Utils.h new file mode 100644 index 0000000000..4e8b069010 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/Axis2Utils.h @@ -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$ */ + +#ifndef tuscany_sca_extension_ws_axis2utils_h +#define tuscany_sca_extension_ws_axis2utils_h + +#include <axis2_env.h> +#include <axis2_msg_ctx.h> + + +namespace tuscany +{ + namespace sca + { + namespace ws + { + + class Axis2Utils + { + public: + static char* getAxisServiceParameterValue(const axis2_env_t *env, axis2_msg_ctx_t *msg_ctx, char* parameterName); + }; + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_extension_ws_axis2utils_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/WSReferenceBindingExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/WSReferenceBindingExtension.cpp new file mode 100644 index 0000000000..2cf5e5d8e1 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/WSReferenceBindingExtension.cpp @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + + +#include "WSReferenceBindingExtension.h" +#include "model/WSReferenceBinding.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/core/SCARuntime.h" + + +extern "C" +{ + #if defined(WIN32) || defined(_WINDOWS) + __declspec(dllexport) + #endif + void tuscany_sca_extension_initialize() + { + tuscany::sca::ws::WSReferenceBindingExtension::initialize(); + } +} + +namespace tuscany +{ + namespace sca + { + namespace ws + { + // =================================================================== + // Constructor for the WSReferenceBinding class. + // =================================================================== + WSReferenceBindingExtension::WSReferenceBindingExtension() + { + LOGENTRY(1, "WSReferenceBindingExtension::constructor"); + LOGEXIT(1, "WSReferenceBindingExtension::constructor"); + } + + // =================================================================== + // Destructor for the WSReferenceBindingExtension class. + // =================================================================== + WSReferenceBindingExtension::~WSReferenceBindingExtension() + { + LOGENTRY(1, "WSReferenceBindingExtension::destructor");; + LOGEXIT(1, "WSReferenceBindingExtension::destructor"); + } + + const string WSReferenceBindingExtension::extensionName("ws"); + const string WSReferenceBindingExtension::typeQName("http://www.osoa.org/xmlns/sca/1.0#WebServiceBinding"); + + // =================================================================== + // loadModelElement - load the info from binding.ws + // =================================================================== + ReferenceBinding* WSReferenceBindingExtension::getReferenceBinding(Composite *composite, Reference* reference, DataObjectPtr scdlBinding) + { + string bindingType = scdlBinding->getType().getName(); + if (bindingType == "WebServiceBinding") + { + string uri = scdlBinding->getCString("uri"); + string endpoint = scdlBinding->getCString("endpoint"); + commonj::sdo::DataObjectList& soap = scdlBinding->getList("soapbinding"); + string version; + if (soap.size()!=0) + { + version = soap.getCString(0); + } + else + { + version = ""; + } + + WSReferenceBinding* serviceBinding = new WSReferenceBinding(reference, uri, endpoint, version); + + return serviceBinding; + } + else + { + return NULL; + } + } + + void WSReferenceBindingExtension::initialize() + { + LOGENTRY(1, "WSReferenceBindingExtension::initialize");; + SCARuntime::getInstance()->registerReferenceBindingExtension(new WSReferenceBindingExtension()); + LOGEXIT(1, "WSReferenceBindingExtension::initialize");; + } + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/WSReferenceBindingExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/WSReferenceBindingExtension.h new file mode 100644 index 0000000000..c7972fe15a --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/WSReferenceBindingExtension.h @@ -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. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_extension_ws_wsreferencebindingextension_h +#define tuscany_sca_extension_ws_wsreferencebindingextension_h + +#include "tuscany/sca/extension/ReferenceBindingExtension.h" + +namespace tuscany +{ + namespace sca + { + namespace ws + { + + class WSReferenceBindingExtension : public ReferenceBindingExtension + { + public: + /** + * Default constructor + */ + WSReferenceBindingExtension(); + + /** + * Destructor + */ + virtual ~WSReferenceBindingExtension(); + + /** + * return the name of the extension + */ + virtual const string& getExtensionName() {return extensionName;} + + /** + * return the QName of schema elemant for this implementation extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#binding.ws") + */ + virtual const string& getExtensionTypeQName() {return typeQName;} + + virtual ReferenceBinding* getReferenceBinding(Composite* composite, Reference *reference, DataObjectPtr scdlBinding); + + static void initialize(); + + private: + static const string extensionName; + static const string typeQName; + + }; + + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_extension_ws_wsreferencebindingextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/WSServiceProxy.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/WSServiceProxy.cpp new file mode 100644 index 0000000000..960c91ed60 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/WSServiceProxy.cpp @@ -0,0 +1,587 @@ +/* + * 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 "WSServiceProxy.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Exceptions.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/ComponentType.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/ServiceBinding.h" +#include "tuscany/sca/model/WSDLDefinition.h" +#include "tuscany/sca/model/WSDLInterface.h" +#include "tuscany/sca/model/WSDLOperation.h" +#include "model/WSReferenceBinding.h" + +#include "commonj/sdo/SDO.h" +using namespace commonj::sdo; + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace ws + { + + // ============================ + // Constructor: Create a proxy + // ============================ + WSServiceProxy::WSServiceProxy(Reference* reference) + : ServiceProxy(reference) + { + LOGENTRY(1,"WSServiceProxy::constructor"); + + // Get the target service wrapper + WSReferenceBinding* referenceBinding = (WSReferenceBinding*)reference->getBinding(); + serviceWrapper = referenceBinding->getTargetServiceBinding()->getServiceWrapper(); + + // Define the SOAP Body type and element to allow a SOAP body to + // be loaded in a DataObject + DataFactoryPtr dataFactory = reference->getComponent()->getComposite()->getDataFactory(); + try { + const Type& bodyType = dataFactory->getType("http://www.w3.org/2003/05/soap-envelope", "Body"); + } catch (SDORuntimeException e) + { + + // Define the SOAP 1.2 Body type + dataFactory->addType("http://www.w3.org/2003/05/soap-envelope", "RootType", false, false, false); + dataFactory->addType("http://www.w3.org/2003/05/soap-envelope", "Body", false, true, false); + dataFactory->addPropertyToType( + "http://www.w3.org/2003/05/soap-envelope", "RootType", + "Body", + "http://www.w3.org/2003/05/soap-envelope", "Body", + false, false, true); + + // Define the SOAP 1.1 Body type + dataFactory->addType("http://schemas.xmlsoap.org/soap/envelope/", "RootType", false, false, false); + dataFactory->addType("http://schemas.xmlsoap.org/soap/envelope/", "Body", false, true, false); + dataFactory->addPropertyToType( + "http://schemas.xmlsoap.org/soap/envelope/", "RootType", + "Body", + "http://schemas.xmlsoap.org/soap/envelope/", "Body", + false, false, true); + } + + LOGEXIT(1,"WSServiceProxy::constructor"); + } + + // ========== + // Destructor + // ========== + WSServiceProxy::~WSServiceProxy() + { + LOGENTRY(1,"WSServiceProxy::destructor"); + LOGEXIT(1,"WSServiceProxy::destructor"); + } + + /// + /// This method will be called to process an operation invocation. + /// + DataObjectPtr WSServiceProxy::invoke(const WSDLOperation& wsdlOperation, DataObjectPtr inputDataObject) + { + LOGENTRY(1,"WSServiceProxy::invoke"); + + Reference* reference = getReference(); + Component* component = reference->getComponent(); + Composite* composite = component ->getComposite(); + + WSReferenceBinding* referenceBinding = (WSReferenceBinding*)reference->getBinding(); + DataFactoryPtr dataFactoryPtr = reference->getComponent()->getComposite()->getDataFactory(); + + bool documentStyle = wsdlOperation.isDocumentStyle(); + bool wrappedStyle = wsdlOperation.isWrappedStyle(); + + const char* outputTypeURI = wsdlOperation.getOutputTypeUri().c_str(); + const char* outputTypeName = wsdlOperation.getOutputTypeName().c_str(); + + LOGINFO_2(4, "WSServiceProxy has got WSDLOperation with inputType: %s#%s", + wsdlOperation.getInputTypeUri().c_str(), + wsdlOperation.getInputTypeName().c_str()); + LOGINFO_2(4, "WSServiceProxy has got WSDLOperation with outputType: %s#%s", + outputTypeURI, + outputTypeName); + LOGINFO_2(4, "WSServiceProxy has got WSDLOperation with documentStyle=%d and wrapped=%d", + documentStyle, + wrappedStyle); + + if (documentStyle) + { + if (wrappedStyle) + { + + // Create new Operation object and set parameters and return value + Operation operation(wsdlOperation.getOperationName().c_str()); + + // Go through the input data object to set the operation parameters + PropertyList pl = inputDataObject->getInstanceProperties(); + + for(int i=0; i<pl.size(); i++) + { + const char* name = pl[i].getName(); + + switch (pl[i].getTypeEnum()) + { + case Type::BooleanType: + { + bool* boolData = new bool; + *boolData = inputDataObject->getBoolean(pl[i]); + operation.addParameter(boolData); + } + break; + case Type::ByteType: + { + char* byteData = new char; + *byteData = inputDataObject->getByte(pl[i]); + operation.addParameter(byteData); + } + break; + case Type::BytesType: + { + int len = inputDataObject->getLength(pl[i]); + char* bytesData = new char[len+1]; + int bytesWritten = inputDataObject->getBytes(pl[i], bytesData, len); + // Ensure the bytes end with the null char. Not sure if this is neccessary + if(bytesWritten <= len) + { + bytesData[bytesWritten] = 0; + } + else + { + bytesData[len] = 0; + } + operation.addParameter(&bytesData); + } + break; + case Type::CharacterType: + { + // This code should work but won't be used as there is no mapping from an XSD type to the SDO CharacterType + wchar_t* charData = new wchar_t; + *charData = inputDataObject->getCharacter(pl[i]); + operation.addParameter(charData); + } + break; + case Type::DoubleType: + { + long double* doubleData = new long double; + *doubleData = inputDataObject->getDouble(pl[i]); + operation.addParameter(doubleData); + } + break; + case Type::FloatType: + { + float* floatData = new float; + *floatData = inputDataObject->getFloat(pl[i]); + operation.addParameter(floatData); + } + break; + case Type::IntegerType: + { + long* intData = new long; + *intData = inputDataObject->getInteger(pl[i]); + operation.addParameter(intData); + } + break; + case Type::ShortType: + { + short* shortData = new short; + *shortData = inputDataObject->getShort(pl[i]); + operation.addParameter(shortData); + } + break; + case Type::StringType: + { + string* stringData; + if(inputDataObject->isSet(pl[i])) + { + stringData = new string(inputDataObject->getCString(pl[i])); + } + else + { + // The data is not set, so pass an empty string as the parameter + stringData = new string(); + } + operation.addParameter(stringData); + } + break; + case Type::DataObjectType: + { + DataObjectPtr dataObjectData = inputDataObject->getDataObject(pl[i]); + if(!dataObjectData) + { + LOGINFO_1(4, "SDO DataObject parameter named %s was null", name); + } + operation.addParameter(&dataObjectData); + } + break; + case Type::OpenDataObjectType: + { + /* + * This code deals with xsd:any element parameters + * Get each element as a DataObject and add in to the parameter list + */ + + DataObjectList& dataObjectList = inputDataObject->getList(pl[i]); + + for(int j=0; j<dataObjectList.size(); j++) + { + DataObjectPtr dataObjectData = dataObjectList[j]; + if(!dataObjectData) + { + + // Add a null DataObject ptr + LOGINFO_2(4, "SDO OpenDataObject parameter named %s[%d] was null", name, j); + operation.addParameter(&dataObjectData); + } + else + { + + SequencePtr sequence = dataObjectData->getSequence(); + if (sequence->size()!=0) + { + // Add a text element + if (sequence->isText(0)) + { + string* stringData = new string(sequence->getCStringValue(0)); + operation.addParameter(stringData); + } + else + { + // Add a complex element DataObject + DataObjectPtr dob = sequence->getDataObjectValue(0); + if(!dob) + { + LOGINFO_1(4, "SDO DataObject parameter named %s was null", name); + } + operation.addParameter(&dob); + } + } + else + { + // Empty content, add an empty string + LOGINFO_2(4, "SDO OpenDataObject parameter named %s[%d] was empty", name, j); + string* stringData = new string(""); + operation.addParameter(stringData); + } + } + } + } + break; + case Type::DateType: + LOGERROR_1(0, "SDO DateType parameters are not yet supported (%s)", name); + return NULL; + case Type::LongType: + LOGERROR_1(0, "SDO LongType (int64_t) parameters are not yet supported (%s)", name); + return NULL; + break; + case Type::UriType: + LOGERROR_1(0, "SDO UriType parameters are not yet supported (%s)", name); + return NULL; + break; + case Type::BigDecimalType: + LOGERROR_1(0, "SDO BigDecimalType parameters are not yet supported (%s)", name); + return NULL; + break; + case Type::BigIntegerType: + LOGERROR_1(0, "SDO BigIntegerType parameters are not yet supported (%s)", name); + return NULL; + break; + default: + LOGERROR_1(0, "Unknown SDO type parameter named %s has been found. Unknown types are not yet supported", name); + return NULL; + } + } + + try + { + + // Call into the target service wrapper + serviceWrapper->invoke(operation); + + // Set the data in the outputDataObject to be returned + DataObjectPtr outputDataObject; + try { + + // Create the output wrapper + const Type& rootType = dataFactoryPtr->getType(outputTypeURI, "RootType"); + const Property& prop = rootType.getProperty(outputTypeName); + const Type& outputType = prop.getType(); + outputDataObject = dataFactoryPtr->create(outputType); + } + catch (SDORuntimeException e) + { + try + { + + // Create the output wrapper + const Type& outputType = dataFactoryPtr->getType(outputTypeURI, outputTypeName); + outputDataObject = dataFactoryPtr->create(outputType); + } + catch (SDORuntimeException e) + { + // The output wrapper type is not known, create an open DataObject + outputDataObject = dataFactoryPtr->create(Type::SDOTypeNamespaceURI, "OpenDataObject"); + } + } + + setOutputData(operation, outputDataObject, dataFactoryPtr); + + LOGEXIT(1,"WSServiceProxy::invoke"); + + return outputDataObject; + + } + catch(SDORuntimeException &ex) + { + // TODO: Return more error information than just a null DataObject + LOGERROR_2(0, "%s has been caught: %s\n", ex.getEClassName(), ex.getMessageText()); + return NULL; + } + catch(TuscanyRuntimeException &ex) + { + // TODO: Return more error information than just a null DataObject + LOGERROR_2(0, "%s has been caught: %s\n", ex.getEClassName(), ex.getMessageText()); + return NULL; + } + } + else + { + LOGERROR(0, "CompositeServices with non-wrapped document style WSDL Operations are not yet supported"); + LOGEXIT(1,"WSServiceProxy::invoke"); + return NULL; + } + } + else + { + // RPC style + LOGERROR(0, "CompositeServices with RPC style WSDL Operations are not yet supported"); + return NULL; + } + } + + + void WSServiceProxy::setOutputData(Operation& operation, DataObjectPtr outputDataObject, DataFactoryPtr dataFactoryPtr) + { + // Go through data object to set the return value + PropertyList pl = outputDataObject->getType().getProperties(); + + if(pl.size() == 0) + { + if(outputDataObject->getType().isOpenType() && outputDataObject->getType().isDataObjectType()) + { + /* + * This code deals with returning xsd:any elements + */ + DataObjectList& l = outputDataObject->getList("return"); + Operation::ParameterType resultType = operation.getReturnType(); + switch(resultType) + { + case Operation::BOOL: + { + l.append(*(bool*)operation.getReturnValue()); + break; + } + case Operation::SHORT: + { + l.append(*(short*)operation.getReturnValue()); + break; + } + case Operation::INT: + { + l.append(*(long*)operation.getReturnValue()); + break; + } + case Operation::LONG: + { + l.append(*(long*)operation.getReturnValue()); + break; + } + case Operation::USHORT: + { + l.append(*(short*)operation.getReturnValue()); + break; + } + case Operation::UINT: + { + l.append(*(long*)operation.getReturnValue()); + break; + } + case Operation::ULONG: + { + l.append(*(long*)operation.getReturnValue()); + break; + } + case Operation::FLOAT: + { + l.append(*(float*)operation.getReturnValue()); + break; + } + case Operation::DOUBLE: + { + l.append(*(long double*)operation.getReturnValue()); + break; + } + case Operation::LONGDOUBLE: + { + l.append(*(long double*)operation.getReturnValue()); + break; + } + case Operation::CHARS: + { + l.append(*(char**)operation.getReturnValue()); + break; + } + case Operation::STRING: + { + l.append((*(string*)operation.getReturnValue()).c_str()); + break; + } + case Operation::DATAOBJECT: + { + l.append(*(DataObjectPtr*)operation.getReturnValue()); + break; + } + default: + { + string msg = "Unsupported parameter type"; + msg += resultType; + throw msg.c_str(); + } + } + } + else + { + LOGINFO(4, "No return values are defined"); + } + } + else { + + // Should only be one return value.. This goes through all return values + for(int i=0; i<pl.size(); i++) + { + const char* name = pl[i].getName(); + + Operation::ParameterType resultType = operation.getReturnType(); + switch(resultType) + { + case Operation::BOOL: + { + outputDataObject->setBoolean(pl[i], *(bool*)operation.getReturnValue()); + break; + } + case Operation::SHORT: + { + outputDataObject->setShort(pl[i], *(short*)operation.getReturnValue()); + break; + } + case Operation::INT: + { + outputDataObject->setInteger(pl[i], *(int*)operation.getReturnValue()); + break; + } + case Operation::LONG: + { + outputDataObject->setInteger(pl[i], *(long*)operation.getReturnValue()); + break; + } + case Operation::USHORT: + { + outputDataObject->setInteger(pl[i], *(unsigned short*)operation.getReturnValue()); + break; + } + case Operation::UINT: + { + outputDataObject->setInteger(pl[i], *(unsigned int*)operation.getReturnValue()); + break; + } + case Operation::ULONG: + { + outputDataObject->setInteger(pl[i], *(unsigned long*)operation.getReturnValue()); + break; + } + case Operation::FLOAT: + { + outputDataObject->setFloat(pl[i], *(float*)operation.getReturnValue()); + break; + } + case Operation::DOUBLE: + { + outputDataObject->setDouble(pl[i], *(double*)operation.getReturnValue()); + break; + } + case Operation::LONGDOUBLE: + { + outputDataObject->setDouble(pl[i], *(long double*)operation.getReturnValue()); + break; + } + case Operation::CHARS: + { + if(*(char**)operation.getReturnValue() != NULL) + { + outputDataObject->setCString(pl[i], *(char**)operation.getReturnValue()); + } + else + { + LOGINFO_1(4, "Return value is NULL, so leaving property %s unset", pl[i].getName()); + } + break; + } + case Operation::STRING: + { + outputDataObject->setCString(pl[i], (*(string*)operation.getReturnValue()).c_str()); + break; + } + case Operation::DATAOBJECT: + { + + if(*(DataObjectPtr*)operation.getReturnValue() != NULL) + { + outputDataObject->setDataObject(pl[i], *(DataObjectPtr*)operation.getReturnValue()); + } + else + { + LOGINFO_1(4, "Return value is NULL, so leaving property %s unset", pl[i].getName()); + } + + break; + } + default: + { + string msg = "Unsupported parameter type"; + msg += resultType; + throw msg.c_str(); + } + } + } + } + } + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/WSServiceProxy.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/WSServiceProxy.h new file mode 100644 index 0000000000..82ab4385f2 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/WSServiceProxy.h @@ -0,0 +1,96 @@ +/* + * 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_ws_wsserviceproxy_h +#define tuscany_sca_extension_ws_wsserviceproxy_h + +#include "tuscany/sca/core/ServiceProxy.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/WSDLOperation.h" +#include "model/WSReferenceBinding.h" +#include "commonj/sdo/SDO.h" + +using namespace tuscany::sca::model; + +using commonj::sdo::DataObjectPtr; +using commonj::sdo::DataFactoryPtr; + +namespace tuscany +{ + namespace sca + { + namespace ws + { + + /** + * Holds a proxy for a given component and reference. + * The proxy which is held inside a ServiceProxy will be specific to the programming + * interface expected by the client. In this particular case the client is an Axis2 + * Web service skeleton. + */ + class WSServiceProxy : public 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. + */ + WSServiceProxy(Reference* reference); + + /** + * Create a new service proxy for a service. The proxy will contain a pointer to + * the target ServiceWrapper. + * @param reference The service on the target component. + * @param target The wrapper of the target service. + */ + WSServiceProxy(Service* service); + + /** + * Destructor. + */ + virtual ~WSServiceProxy(); + + /** + * Invoke the specified operation + */ + DataObjectPtr invoke(const WSDLOperation& wsdlOperation, DataObjectPtr inputDataObject); + + private: + + void setOutputData(Operation& operation, DataObjectPtr outputDataObject, DataFactoryPtr dataFactoryPtr); + + /** + * The target service wrapper + */ + ServiceWrapper* serviceWrapper; + + }; + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_extension_ws_wsserviceproxy_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/model/WSReferenceBinding.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/model/WSReferenceBinding.cpp new file mode 100644 index 0000000000..23ecc133e8 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/model/WSReferenceBinding.cpp @@ -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$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/ws/model/WSReferenceBinding.h" +#include "tuscany/sca/core/ServiceProxy.h" +#include "tuscany/sca/ws/WSServiceProxy.h" + +namespace tuscany +{ + namespace sca + { + namespace ws + { + + // Constructor + WSReferenceBinding::WSReferenceBinding(Reference* reference, const string& uri, const string& endpoint, const string&version) + : ReferenceBinding(reference, uri), endpoint(endpoint), soapVersion(version) + { + parseEndpoint(); + } + + void WSReferenceBinding::parseEndpoint() + { + // Endpoint is of the form: <wsdl-namepace-uri>#wsdl.endpoint(<service-name>/<endpoint-name>) + string::size_type hash = endpoint.find("#"); + if (hash != string::npos) + { + // Found a hash + + // Namepace is the part before the # + wsdlNamespaceURL = endpoint.substr(0, hash); + + + if ( (hash+1) < endpoint.length()) + { + // Check the next part is wsdl.endpoint( + int ending = hash+15; + string check = endpoint.substr(hash+1, 14); + if (check.compare("wsdl.endpoint(") == 0) + { + // Find the matching ) + int endBracket = endpoint.find(")",ending); + if (endBracket-1 > ending+1) + { + string serviceAndEndpoint = endpoint.substr(ending, endBracket-ending); + // Look for a '/' + string::size_type slash = serviceAndEndpoint.find("/"); + if (slash != string::npos) + { + serviceName = serviceAndEndpoint.substr(0, slash); + + if ( (slash+1) < serviceAndEndpoint.length()) + { + endpointName = serviceAndEndpoint.substr(slash+1); + } + else + { + endpointName = ""; + } + + } + else + { + // No '/' so all of it is the service name + serviceName = serviceAndEndpoint; + endpointName = ""; + + } + } + else + { + // Nothing between the () + serviceName = ""; + endpointName = ""; + } + } + else + { + // not the correct characters after the #, ignore the rest + serviceName = ""; + endpointName = ""; + } + + } + else + { + // Nothing after the hash + serviceName = ""; + endpointName = ""; + } + } + else + { + // No hash at all + wsdlNamespaceURL = endpoint; + serviceName = ""; + endpointName = ""; + } + } + + // Destructor + WSReferenceBinding::~WSReferenceBinding() + { + } + + void WSReferenceBinding::configure(ServiceBinding *binding) + { + targetServiceBinding = binding; + + serviceProxy = new WSServiceProxy(getReference()); + } + + ServiceProxy* WSReferenceBinding::getServiceProxy() + { + return serviceProxy; + } + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/model/WSReferenceBinding.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/model/WSReferenceBinding.h new file mode 100644 index 0000000000..90e28e326b --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/axis2c/src/tuscany/sca/ws/model/WSReferenceBinding.h @@ -0,0 +1,153 @@ +/* + * 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_ws_model_wsreferencebinding_h +#define tuscany_sca_extension_ws_model_wsreferencebinding_h + +#include "tuscany/sca/model/ReferenceBinding.h" + +using namespace tuscany::sca::model; + +#include <string> +using std::string; + +namespace tuscany +{ + namespace sca + { + namespace ws + { + /** + * Information about a web service binding for service or a reference. + */ + class WSReferenceBinding : public ReferenceBinding + { + public: + + /** + * Constructor. + * @param uri The uri of the binding. + * @param endpoint The definition of the endpoint to which the entrypoint + * or external service is to be bound. This is of the form + * "namespace"#endpoint("service"/"endpoint") + */ + WSReferenceBinding(Reference* reference, const string&uri, const string& endpoint, const string& version); + + /** + * Destructor. + */ + virtual ~WSReferenceBinding(); + + /** + * Returns the type of binding. + */ + virtual string getType() { return "http://www.osoa.org/xmlns/sca/1.0#WebServiceBinding"; }; + + /** + * Configure this binding from a service binding. + */ + virtual void configure(ServiceBinding* serviceBinding); + + /** + * Create a proxy representing the reference to the + * client component. + */ + virtual ServiceProxy* getServiceProxy(); + + /** + * Return the part of the endpoint definition describing the wsdl + * namespace. + * @return The wsdl namespace. + */ + string getWSDLNamespaceURL() const { return wsdlNamespaceURL; }; + + /** + * Return the service part of the endpoint definition. + * @return The service to use. + */ + string getServiceName() const { return serviceName; }; + + /** + * Return the endpoint name part of the endpoint definition. + * @return The endpoint name to use. + */ + string getEndpointName() const { return endpointName; }; + + /** + * Return the SOAP version. + * @return The SOAP version to use. + */ + string getSOAPVersion() const { return soapVersion; }; + + /** + * Returns the target service binding. + */ + ServiceBinding* getTargetServiceBinding() const { return targetServiceBinding; }; + + private: + + /** + * Parse the endpoint specification. + */ + void parseEndpoint(); + + /** + * The full endpoint string. + */ + string endpoint; + + /** + * Namespace from the endpoint. + */ + string wsdlNamespaceURL; + + /** + * Service name from the endpoint. + */ + string serviceName; + + /** + * Endpoint name from the endpoint. + */ + string endpointName; + + /** + * SOAP version. + */ + string soapVersion; + + /** + * The proxy representing the reference to the client + * component. + */ + ServiceProxy* serviceProxy; + + /** + * The service binding of the target + */ + ServiceBinding* targetServiceBinding; + }; + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_extension_ws_model_wsreferencebinding_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/deploy.bat b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/deploy.bat new file mode 100644 index 0000000000..0722342b03 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/deploy.bat @@ -0,0 +1,73 @@ +@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 extdir=%deploydir%\extensions +set wsextdir=%extdir%\ws +set svcextdir=%wsextdir%\service +set svcsdir=%svcextdir%\services +set srcdir=%rootdir%\runtime\extensions\ws\service\axis2c\src + +if . == .%2 ( +echo input directory not specified +goto usage +) +set inpath=%2 +echo %inpath% + +if not exist %deploydir% mkdir %deploydir% +if not exist %extdir% mkdir %extdir% +if not exist %wsextdir% mkdir %wsextdir% +if not exist %svcextdir% mkdir %svcextdir% +if not exist %svcextdir%\bin mkdir %svcextdir%\bin +if not exist %svcextdir%\lib mkdir %svcextdir%\lib + +set libname=tuscany_sca_ws_service + +del %svcextdir%\bin\%libname%.* +del %svcextdir%\lib\%libname%.* + +copy %inpath%\%libname%.lib %svcextdir%\lib +copy %inpath%\%libname%.dll %svcextdir%\bin + +if exist %inpath%\%libname%.pdb copy %inpath%\%libname%.pdb %svcextdir%\bin + +if not exist %svcsdir% mkdir %svcsdir% +if not exist %svcsdir%\tuscany mkdir %svcsdir%\tuscany + +copy %srcdir%\axis2.xml %svcextdir% +copy %srcdir%\deploy.cmd %svcextdir% +copy %srcdir%\services.xml %svcsdir%\tuscany +copy %inpath%\%libname%.dll %svcsdir%\tuscany +if exist %inpath%\%libname%.pdb copy %inpath%\%libname%.pdb %svcsdir%\tuscany + +goto end +:usage +echo Usage: deploy <sca-root> <build-output> +:end + +endlocal diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/deploymodule.bat b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/deploymodule.bat new file mode 100644 index 0000000000..246728b6b2 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/service/deploymodule.bat @@ -0,0 +1,69 @@ +@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 extdir=%deploydir%\extensions +set wsextdir=%extdir%\ws +set svcextdir=%wsextdir%\service +set modsdir=%svcextdir%\modules +set srcdir=%rootdir%\runtime\extensions\ws\service\axis2c\src + +if . == .%2 ( +echo input directory not specified +goto usage +) +set inpath=%2 +echo %inpath% + +if not exist %deploydir% mkdir %deploydir% +if not exist %extdir% mkdir %extdir% +if not exist %wsextdir% mkdir %wsextdir% + +set libname=tuscany_sca_ws_dispatcher + +del %svcextdir%\bin\%libname%.* +del %svcextdir%\lib\%libname%.* + +copy %inpath%\%libname%.lib %svcextdir%\lib +copy %inpath%\%libname%.dll %svcextdir%\bin + +if exist %inpath%\%libname%.pdb copy %inpath%\%libname%.pdb %svcextdir%\bin + + +if not exist %modsdir% mkdir %modsdir% +if not exist %modsdir%\tuscany mkdir %modsdir%\tuscany + +copy %srcdir%\module.xml %modsdir%\tuscany +copy %inpath%\%libname%.dll %modsdir%\tuscany +if exist %inpath%\%libname%.pdb copy %inpath%\%libname%.pdb %modsdir%\tuscany + +goto end +:usage +echo Usage: deploy <sca-root> <build-output> +:end + +endlocal diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/xsd/sca-binding-webservice.xsd b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/xsd/sca-binding-webservice.xsd new file mode 100644 index 0000000000..2c1c2abbcc --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ws/xsd/sca-binding-webservice.xsd @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.osoa.org/xmlns/sca/1.0" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + elementFormDefault="qualified"> + + <element name="binding.ws" type="sca:WebServiceBinding" substitutionGroup="sca:binding"/> + <complexType name="WebServiceBinding"> + <complexContent> + <extension base="sca:Binding"> + <sequence> + <element name="soapbinding" type="sca:SOAPBinding" minOccurs="0" maxOccurs="unbounded"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> + </sequence> + <attribute name="endpoint" type="anyURI" use="optional" /> + <attribute name="location" type="anyURI" use="optional" /> + <attribute name="conformanceURIs" type="sca:ConformanceURIList" use="optional" /> + <attribute name="interfaceMapping" type="string" use="optional" /> + <anyAttribute namespace="##any" processContents="lax" /> + </extension> + </complexContent> + </complexType> + + <complexType name="SOAPBinding"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> + </sequence> + <attribute name="name" type="NCName" use="optional" /> + <attribute name="version" type="string" use="optional" /> + <anyAttribute namespace="##any" processContents="lax" /> + </complexType> + + <simpleType name="ConformanceURIList"> + <list itemType="anyURI"/> + </simpleType> +</schema> |