Author: jsdelfino
Date: Thu Sep 21 17:31:13 2006
New Revision: 448748
URL: http://svn.apache.org/viewvc?view=rev&rev=448748
Log:
Added SDO support to the Ruby component type. SDO DataObjects get presented to
a Ruby script as Ruby rexml documents.
Modified:
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.cpp
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.h
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
Modified:
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.cpp
URL:
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.cpp?view=diff&rev=448748&r1=448747&r2=448748
==============================================================================
---
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.cpp
(original)
+++
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.cpp
Thu Sep 21 17:31:13 2006
@@ -80,7 +80,7 @@
// ----------------------
// Get the component
// ----------------------
- Component* component = reference->getComponent();
+ component = reference->getComponent();
string name = reference->getType()->getName();
// Get the service wrapper
@@ -105,7 +105,7 @@
// ----------------------
// Get the component
// ----------------------
- Component* component = service->getComponent();
+ component = service->getComponent();
string name = service->getType()->getName();
// Get the service wrapper
@@ -210,6 +210,44 @@
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 = new DataObjectPtr;
+ 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());
@@ -284,6 +322,23 @@
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:
Modified:
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.h
URL:
http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.h?view=diff&rev=448748&r1=448747&r2=448748
==============================================================================
---
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.h
(original)
+++
incubator/tuscany/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.h
Thu Sep 21 17:31:13 2006
@@ -95,6 +95,11 @@
* The Ruby value of the proxy
*/
VALUE proxyValue;
+
+ /**
+ * The component owning the proxy
+ */
+ Component* component;
/**
* The Ruby proxy class
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=448748&r1=448747&r2=448748
==============================================================================
---
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
Thu Sep 21 17:31:13 2006
@@ -205,6 +205,23 @@
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");
@@ -274,6 +291,42 @@
bool* data = new bool;
*data = false;
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 = new DataObjectPtr;
+ 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:
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=448748&r1=448747&r2=448748
==============================================================================
---
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
Thu Sep 21 17:31:13 2006
@@ -38,6 +38,7 @@
{
bool RubyImplementation::initialized = false;
+ VALUE RubyImplementation::xmlDocumentClass = 0;
// Constructor
RubyImplementation::RubyImplementation(Composite* composite, const
string& module, const string& className, const string& script)
@@ -57,14 +58,25 @@
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 != "")
{
- string path = getComposite()->getRoot() + '/' + script;
- rb_require((char *)path.c_str());
+ // Use rb_eval_string for now as it provides better error
reporting
+ string path = "require(\"" + getComposite()->getRoot() +
"/" + script +"\")";
+ //rb_require((char *)path.c_str());
+ rb_eval_string(path.c_str());
}
// Load the Ruby implementation class
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=448748&r1=448747&r2=448748
==============================================================================
---
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
Thu Sep 21 17:31:13 2006
@@ -85,6 +85,11 @@
* Returns the Ruby implementation class
*/
VALUE getImplementationClass() const { return
implementationClass; }
+
+ /**
+ * Returns the Ruby REXML::Document class
+ */
+ static VALUE getXMLDocumentClass() { return xmlDocumentClass;
}
private:
@@ -109,14 +114,19 @@
string script;
/**
+ * The Ruby implementation class
+ */
+ VALUE implementationClass;
+
+ /**
* True if the Ruby runtime has been initialized
*/
static bool initialized;
/**
- * The Ruby implementation class
- */
- VALUE implementationClass;
+ * The Ruby REXML::Document class.
+ */
+ static VALUE xmlDocumentClass;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]