You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Mark Trumbo <ma...@rogers.com> on 2006/08/24 11:09:02 UTC
addMethodToType?
Given some function
int SomePropertyPlusTwoFunction(DataObjectPtr dc) { return dc->getInteger("SomeProperty") + 2; }
I would like to write
myDataFactory->addMethodToType(uri, "SomePropertyPlusTwo",
"MyTypeWithSomeProperty",
"SomePropertyPlusTwo", intType,
SomePropertyPlusTwoFunction);
which would associate the function SomePropertyPlusTwoFunction with the name SomePropertyPlusTwo and then
dc->getValue("SomePropertyPlusTwo");
which would invoke the function SomePropertyPlusTwoFunction
Everything else would behave as though this were a read-only attribute -- queries, serialization, etc -- but instead returning data using a name as a key, the key would be associated with a function. Conceptually, the intention is to a const member function that takes no arguments, which is almost indistinguishable from read-only data.
Is there already a way to do what I want to do?
If not, is having such a facility inconsistent in any way with the rest of SDO?
If not, is any one working on this?
If not, I will.
Re: addMethodToType?
Posted by Pete Robbins <ro...@googlemail.com>.
Interesting! Are you looking at the C++ code? Assuming you are, some
comments inline.
On 24/08/06, Mark Trumbo <ma...@rogers.com> wrote:
>
> Given some function
>
> int SomePropertyPlusTwoFunction(DataObjectPtr dc) { return
> dc->getInteger("SomeProperty") + 2; }
>
> I would like to write
>
> myDataFactory->addMethodToType(uri, "SomePropertyPlusTwo",
> "MyTypeWithSomeProperty",
> "SomePropertyPlusTwo", intType,
> SomePropertyPlusTwoFunction);
>
> which would associate the function SomePropertyPlusTwoFunction with the
> name SomePropertyPlusTwo and then
so this is a new method on DataFactory adding a "pseudo-property" to a type.
I assume the "intType" is the type of the value returned by the named
function?
dc->getValue("SomePropertyPlusTwo");
>
> which would invoke the function SomePropertyPlusTwoFunction
and this is a new method on DataObject? You'd need one method for each type
I think. Or... would you just code
dc->getInteger(<pseudo-property-name>);
Everything else would behave as though this were a read-only attribute --
> queries, serialization, etc -- but instead returning data using a name as a
> key, the key would be associated with a function. Conceptually, the
> intention is to a const member function that takes no arguments, which is
> almost indistinguishable from read-only data.
So would you expect the serialization to include
<sometypeelement SomePropertyPlusTwo=23 >
in other words this is added as a "real property" as well. Would you expect
to be able to set the property using
dc->setInteger("SomePropertyPlusTwo", 3) ... or whatever the syntax is!
> Is there already a way to do what I want to do?
I don't think so
If not, is having such a facility inconsistent in any way with the rest of
> SDO?
I guess the SDO spec folk would be better able to answer this. I think it's
quite an intersting idea.
If not, is any one working on this?
not that I know of
If not, I will.
feel free to experiment ;-)
Cheers,
--
Pete
Re: addMethodToType?
Posted by Frank Budinsky <fr...@ca.ibm.com>.
Hi Mark,
I would say that an approach more consistent with the SDO spec would be to
simply create a readonly property, "SomePropertyPlusTwo", and then using
some "implementation-specific" API, provide the value-producing
implementation code for the property. The SDO spec basically says that
setting readonly properties is implementation dependent. I think that
generalizing that to include setting the property to the "result of a
function", as opposed to "some specific value" is quite reasonable.
In the Java implementation of SDO you can already do this kind of thing,
by generating a static implementation class for the SDO type and then
providing your desired implementation code in the generated get() method.
I gather from your examples, however, that you're using the C++
implementation so I don't believe that's possible yet. Maybe you don't
really want generated classes anyway? It might be interesting to provide a
way to register an implementation method with a dynamic reaonly property,
regardless.
Perhaps some kind of API in the Tuscany C++ implementation that let's you
register a function with a readonly property would be a more
spec-consistent way to do this. For example:
Property* somePropertyPlusTwo = ...
extendedTypeHelper->registerPropertyImplementation(somePropertyPlusTwo,
SomePropertyPlusTwoFunction);
Maybe someone on the Tuscany C++ team knows of a better place to hook in
this kind of thing into the existing implementation.
Frank
Mark Trumbo <ma...@rogers.com> wrote on 08/24/2006 05:09:02 AM:
> Given some function
>
> int SomePropertyPlusTwoFunction(DataObjectPtr dc) { return
> dc->getInteger("SomeProperty") + 2; }
>
> I would like to write
>
> myDataFactory->addMethodToType(uri, "SomePropertyPlusTwo",
> "MyTypeWithSomeProperty",
> "SomePropertyPlusTwo", intType,
> SomePropertyPlusTwoFunction);
>
> which would associate the function SomePropertyPlusTwoFunction with
> the name SomePropertyPlusTwo and then
>
> dc->getValue("SomePropertyPlusTwo");
>
> which would invoke the function SomePropertyPlusTwoFunction
>
> Everything else would behave as though this were a read-only
> attribute -- queries, serialization, etc -- but instead returning
> data using a name as a key, the key would be associated with a
> function. Conceptually, the intention is to a const member function
> that takes no arguments, which is almost indistinguishable from
> read-only data.
>
> Is there already a way to do what I want to do?
>
> If not, is having such a facility inconsistent in any way with the
> rest of SDO?
>
> If not, is any one working on this?
>
> If not, I will.
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org