Author: jsdelfino
Date: Tue Sep 12 01:16:00 2006
New Revision: 442515
URL: http://svn.apache.org/viewvc?view=rev&rev=442515
Log:
Complete introspection of a Ruby component. Create references and properties
for all public attributes of the component implementation class.
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/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.cpp
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.cpp
incubator/tuscany/cpp/sca/samples/RubyCalculator/sample.calculator/CalculatorImpl.rb
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=442515&r1=442514&r2=442515
==============================================================================
---
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 Sep 12 01:16:00 2006
@@ -85,7 +85,7 @@
void ComponentType::addPropertyType(const string& name,
const string& type,
bool many,
- DataObjectPtr defaultValue)
+ DataObjectPtr* defaultValue)
{
// Create a Type in the Properties dataFactory
DataFactoryPtr factory = getPropertyDataFactory();
@@ -206,19 +206,22 @@
true);
// Set the default for a dataType
- try
+ if (defaultValue!=NULL)
{
- const Type& propType = factory->getType(typeUri.c_str(),
typeName.c_str());
- if (propType.isDataType())
+ try
{
- factory->setDefault("org/osoa/sca", "Properties",
- name.c_str(),
- (char*)defaultValue->getCString(""));
+ const Type& propType =
factory->getType(typeUri.c_str(), typeName.c_str());
+ if (propType.isDataType())
+ {
+ factory->setDefault("org/osoa/sca", "Properties",
+ name.c_str(),
+ (char*)(*defaultValue)->getCString(""));
+ }
+ }
+ catch (SDOTypeNotFoundException&)
+ {
+ // cout << "setting default failed" <<endl;
}
- }
- catch (SDOTypeNotFoundException&)
- {
- // cout << "setting default failed" <<endl;
}
}
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=442515&r1=442514&r2=442515
==============================================================================
---
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 Sep 12 01:16:00 2006
@@ -126,7 +126,7 @@
SCA_API virtual void addPropertyType(const string& name,
const string& type,
bool many,
- commonj::sdo::DataObjectPtr defaultValue);
+ commonj::sdo::DataObjectPtr* defaultValue);
/**
* Return the SDO data factory which has the types of the
properties defined
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=442515&r1=442514&r2=442515
==============================================================================
---
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 Sep 12 01:16:00 2006
@@ -560,12 +560,9 @@
//TODO need to add support for complex properties, need
the SDO
// folks to help understand how to do this...
- DataObjectPtr defaultValue;
- if (props[i]->isSet("value")) {
- defaultValue = props[i]->getDataObject("value");
- }
+ DataObjectPtr defaultValue =
props[i]->getDataObject("value");
- componentType->addPropertyType(name, type, many,
defaultValue);
+ componentType->addPropertyType(name, type, many,
&defaultValue);
}
}
Modified:
incubator/tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.cpp
URL:
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.cpp?view=diff&rev=442515&r1=442514&r2=442515
==============================================================================
---
incubator/tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.cpp
(original)
+++
incubator/tuscany/cpp/sca/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.cpp
Tue Sep 12 01:16:00 2006
@@ -31,7 +31,7 @@
// Constructor
CPPReferenceBinding::CPPReferenceBinding(Reference* reference)
- : ReferenceBinding(reference, ""), serviceProxy(NULL)
+ : ReferenceBinding(reference, ""), serviceProxy(NULL),
targetServiceBinding(NULL)
{
}
Modified:
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp
URL:
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp?view=diff&rev=442515&r1=442514&r2=442515
==============================================================================
---
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp
(original)
+++
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp
Tue Sep 12 01:16:00 2006
@@ -88,13 +88,17 @@
{
Reference* reference = refiter->second;
RubyServiceProxy* proxy =
(RubyServiceProxy*)reference->getBinding()->getServiceProxy();
- VALUE proxyValue = proxy->getProxyValue();
- string varName = "@" + refiter->first;
- rb_iv_set(instance, varName.c_str(), proxyValue);
+ if (proxy != NULL)
+ {
+ VALUE proxyValue = proxy->getProxyValue();
+ string varName = "@" + refiter->first;
+ rb_iv_set(instance, varName.c_str(), proxyValue);
+ }
refiter++;
}
- // TODO Set all the properties
+ // Set all the configured properties
+ //TODO
// Get the ID of the specified method
ID method = rb_intern(operation.getName().c_str());
Modified:
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp
URL:
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp?view=diff&rev=442515&r1=442514&r2=442515
==============================================================================
---
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp
(original)
+++
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp
Tue Sep 12 01:16:00 2006
@@ -44,6 +44,15 @@
: 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)
{
@@ -54,7 +63,7 @@
// Load the specified Ruby script
if (script != "")
{
- string path = composite->getRoot() + '/' + script;
+ string path = getComposite()->getRoot() + '/' + script;
rb_require((char *)path.c_str());
}
@@ -64,10 +73,30 @@
// Create a default service
ServiceType* defaultServiceType = new ServiceType(this, "",
NULL, NULL);
addServiceType(defaultServiceType);
- }
- RubyImplementation::~RubyImplementation()
- {
+ // 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)
@@ -95,20 +124,6 @@
reference->setBinding(binding);
refiter++;
}
- }
-
- // Override this method to add reference types as they are needed
- ReferenceType* RubyImplementation::findReferenceType(const string&
referenceName)
- {
- ReferenceType* referenceType =
ComponentType::findReferenceType(referenceName);
-
- if (referenceType == NULL)
- {
- referenceType = new ReferenceType(this, referenceName,
NULL, NULL, ReferenceType::ONE_ONE);
- addReferenceType(referenceType);
- }
-
- return referenceType;
}
} // End namespace ruby
Modified:
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h
URL:
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h?view=diff&rev=442515&r1=442514&r2=442515
==============================================================================
---
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h
(original)
+++
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h
Tue Sep 12 01:16:00 2006
@@ -86,14 +86,12 @@
*/
VALUE getImplementationClass() const { return
implementationClass; }
+ private:
+
/**
- * Find an existing reference type on this component type.
- * @param referenceName The name of the reference type to find.
- * @return The found reference type, or 0 if not found.
+ * Load the Ruby implementation class
*/
- SCA_API virtual ReferenceType* findReferenceType(const string&
referenceName);
-
- private:
+ void loadClass();
/**
* Name of the Ruby module.
Modified:
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.cpp
URL:
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.cpp?view=diff&rev=442515&r1=442514&r2=442515
==============================================================================
---
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.cpp
(original)
+++
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.cpp
Tue Sep 12 01:16:00 2006
@@ -31,7 +31,7 @@
// Constructor
RubyReferenceBinding::RubyReferenceBinding(Reference* reference)
- : ReferenceBinding(reference, ""), serviceProxy(NULL)
+ : ReferenceBinding(reference, ""), serviceProxy(NULL),
targetServiceBinding(NULL)
{
}
Modified:
incubator/tuscany/cpp/sca/samples/RubyCalculator/sample.calculator/CalculatorImpl.rb
URL:
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/samples/RubyCalculator/sample.calculator/CalculatorImpl.rb?view=diff&rev=442515&r1=442514&r2=442515
==============================================================================
---
incubator/tuscany/cpp/sca/samples/RubyCalculator/sample.calculator/CalculatorImpl.rb
(original)
+++
incubator/tuscany/cpp/sca/samples/RubyCalculator/sample.calculator/CalculatorImpl.rb
Tue Sep 12 01:16:00 2006
@@ -19,6 +19,8 @@
class CalculatorImpl
+ attr_writer :divideService
+
def initialize()
print "Ruby - CalculatorImpl.initialize\n"
end
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]