You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by aj...@apache.org on 2006/11/21 13:42:48 UTC
svn commit: r477653 - in /incubator/tuscany/cpp/sca:
runtime/core/src/tuscany/sca/model/
runtime/extensions/python/src/tuscany/sca/python/
runtime/extensions/python/src/tuscany/sca/python/model/
samples/PythonCalculator/sample.calculator/
Author: ajborley
Date: Tue Nov 21 04:42:47 2006
New Revision: 477653
URL: http://svn.apache.org/viewvc?view=rev&rev=477653
Log:
Removes the requirement for Python components to have componentType side-files. References, properties (typed as xsd:strings) and a default service are automatically added to the ComponentType object.
Removed:
incubator/tuscany/cpp/sca/samples/PythonCalculator/sample.calculator/CalculatorImpl.componentType
incubator/tuscany/cpp/sca/samples/PythonCalculator/sample.calculator/DivideImpl.componentType
Modified:
incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ComponentType.cpp
incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ComponentType.h
incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp
incubator/tuscany/cpp/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceWrapper.cpp
incubator/tuscany/cpp/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonImplementation.cpp
incubator/tuscany/cpp/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonImplementation.h
Modified: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ComponentType.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ComponentType.cpp?view=diff&rev=477653&r1=477652&r2=477653
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ComponentType.cpp (original)
+++ incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ComponentType.cpp Tue Nov 21 04:42:47 2006
@@ -235,8 +235,30 @@
}
}
+ const Property* ComponentType::findPropertyType(const string& propertyName)
+ {
+ logentry();
+ const Property* property = NULL;
+
+ DataFactoryPtr dataFactory = getPropertyDataFactory();
+ const Type& propertiesType = dataFactory->getType("org/osoa/sca", "Properties");
+
+ try
+ {
+ const Property& prop = propertiesType.getProperty(propertyName);
+ property = ∝
+ }
+ catch(SDOPropertyNotFoundException)
+ {
+ loginfo("Property named %s not found, returning null", propertyName.c_str());
+ }
+ return property;
+ }
+
DataFactoryPtr ComponentType::getPropertyDataFactory()
{
+ logentry();
+
if (!propertyFactory)
{
propertyFactory = DataFactory::getDataFactory();
@@ -248,6 +270,8 @@
void ComponentType::initializeComponent(Component* component)
{
+ logentry();
+
for (SERVICETYPE_MAP::iterator iter = serviceTypes.begin();
iter != serviceTypes.end();
iter++)
Modified: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ComponentType.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ComponentType.h?view=diff&rev=477653&r1=477652&r2=477653
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ComponentType.h (original)
+++ incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ComponentType.h Tue Nov 21 04:42:47 2006
@@ -131,6 +131,13 @@
commonj::sdo::DataObjectPtr* defaultValue);
/**
+ * Find an existing property type on this component type.
+ * @param propertyName The name of the property type to find.
+ * @return The found property, or 0 if not found.
+ */
+ SCA_API virtual const commonj::sdo::Property* findPropertyType(const string& propertyName);
+
+ /**
* Return the SDO data factory which has the types of the properties defined
* in this component type.
* @return The data factory.
Modified: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp?view=diff&rev=477653&r1=477652&r2=477653
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp (original)
+++ incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/model/ModelLoader.cpp Tue Nov 21 04:42:47 2006
@@ -382,8 +382,8 @@
}
}
- // First check that references exist, some component types
- // will create all used references automatically
+ // First check that references and properties exist, some component types
+ // will create all used references & properties automatically
DataObjectList& refs = componentDO->getList("reference");
for (int i=0; i<refs.size(); i++)
{
@@ -395,6 +395,19 @@
throwException(SystemConfigurationException, message.c_str());
}
}
+
+ DataObjectList& props = componentDO->getList("property");
+ for (int pi=0; pi<props.size(); pi++)
+ {
+ string propName = props[pi]->getCString("name");
+ if (!componentType->findPropertyType(propName))
+ {
+ // Configuration error: property is not defined
+ string message = "Undefined property: " + propName;
+ throwException(SystemConfigurationException, message.c_str());
+ }
+ }
+
// Create the component
Component* component = new Component(composite, componentDO->getCString("name"), componentType);
@@ -403,7 +416,6 @@
// ----------
// Properties
// ----------
- DataObjectList& props = componentDO->getList("property");
for (int pi=0; pi<props.size(); pi++)
{
string propName = props[pi]->getCString("name");
Modified: incubator/tuscany/cpp/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceWrapper.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceWrapper.cpp?view=diff&rev=477653&r1=477652&r2=477653
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceWrapper.cpp (original)
+++ incubator/tuscany/cpp/sca/runtime/extensions/python/src/tuscany/sca/python/PythonServiceWrapper.cpp Tue Nov 21 04:42:47 2006
@@ -133,12 +133,6 @@
string msg = "Failed to load module named " + impl->getModule() + " on path " + path;
throwException(SystemConfigurationException, msg.c_str());
}
- //else
- //{
- // addReferences(pythonModule);
- // addProperties(pythonModule);
- //}
-
printPyObject("pythonModule",pythonModule);
}
Modified: incubator/tuscany/cpp/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonImplementation.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonImplementation.cpp?view=diff&rev=477653&r1=477652&r2=477653
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonImplementation.cpp (original)
+++ incubator/tuscany/cpp/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonImplementation.cpp Tue Nov 21 04:42:47 2006
@@ -25,9 +25,13 @@
#include "tuscany/sca/python/model/PythonReferenceBinding.h"
#include "tuscany/sca/model/Component.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"
+using namespace tuscany::sca::model;
+
namespace tuscany
{
namespace sca
@@ -43,11 +47,53 @@
module(module), modulePath(modulePath), className(className), scope(scope)
{
logentry();
+
+ // Create a default service for this componentType
+ ServiceType* defaultServiceType = new ServiceType(this, "", NULL, NULL);
+ addServiceType(defaultServiceType);
}
PythonImplementation::~PythonImplementation()
{
logentry();
+ }
+
+ /**
+ * Overrides the findReferenceType method in ComponentType.
+ * This allows us to create references without needing a componentType file.
+ */
+ ReferenceType* PythonImplementation::findReferenceType(const string& referenceName)
+ {
+ logentry();
+
+ ReferenceType* refType = ComponentType::findReferenceType(referenceName);
+ if(!refType)
+ {
+ // The reference has not yet been created - try creating it
+ refType = new ReferenceType(this, referenceName, NULL, NULL, ReferenceType::ONE_ONE);
+ addReferenceType(refType);
+ }
+
+ return refType;
+ }
+
+ /**
+ * Overrides the findPropertyType method in ComponentType.
+ * This allows us to create properties without needing a componentType file.
+ */
+ const commonj::sdo::Property* PythonImplementation::findPropertyType(const string& propertyName)
+ {
+ logentry();
+
+ const commonj::sdo::Property* prop = ComponentType::findPropertyType(propertyName);
+ if(!prop)
+ {
+ ComponentType::addPropertyType(propertyName, "http://www.w3.org/2001/XMLSchema#string", false, NULL);
+ // Just added it so it should now be available
+ prop = ComponentType::findPropertyType(propertyName);
+ }
+
+ return prop;
}
void PythonImplementation::initializeComponent(Component* component)
Modified: incubator/tuscany/cpp/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonImplementation.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonImplementation.h?view=diff&rev=477653&r1=477652&r2=477653
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonImplementation.h (original)
+++ incubator/tuscany/cpp/sca/runtime/extensions/python/src/tuscany/sca/python/model/PythonImplementation.h Tue Nov 21 04:42:47 2006
@@ -23,6 +23,7 @@
#ifndef tuscany_sca_python_model_pythonimplementation_h
#define tuscany_sca_python_model_pythonimplementation_h
#include "tuscany/sca/model/ComponentType.h"
+#include "commonj/sdo/SDO.h"
#include <map>
using std::map;
@@ -74,6 +75,21 @@
* @param component The component to initialize.
*/
virtual void initializeComponent(Component* component);
+
+ /**
+ * Override the ComponentType::findReferenceType method
+ * to allow Python components to be defined without requiring
+ * a componentType side-file
+ */
+ virtual ReferenceType* findReferenceType(const string& referenceName);
+
+ /**
+ * Override the ComponentType::findPropertyType method
+ * to allow Python components to be defined without requiring
+ * a componentType side-file
+ */
+ virtual const commonj::sdo::Property* findPropertyType(const string& propertyName);
+
/**
* Returns the name of the module.
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org