You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by stf_polska <st...@o2.pl> on 2007/03/15 02:04:51 UTC

DataObject.set (automatic creation of nested properties)

Hello

After registering the types (with SDOUtil.registerStaticTypes) I am able 
to do this:

DataObject car = DataFactory.INSTANCE.create("some://namespace", "Car");

After that, I am able to set simple properties:

car.set("Color", "Green");

However, when I try with nested ("containment"?) properties:

car.set("RearAxle/Length", "50");

it raises java.lang.NullPointerException. I have to do this first:

car.createDataObject("RearAxle");

Then I can proceed with this:

car.set("RearAxle/Length", "50");

The question is:

How to make DataObject.set (or some other dynamic setters, like 
DataObject.setString) create all the nested properties that are needed?

One could try to parse that path ("RearAxle/Length") by hand, and create 
those properties by hand. But it seems that those could be complicated 
expressions, and in fact I do not know them before runtime. So, if that 
parsing is already done somewhere there in Tuscany internals, I would 
like not to duplicate it.

Thanks.

-- 
     Leave this world better than it was when you were born.

---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-user-help@ws.apache.org


Re: DataObject.set (automatic creation of nested properties)

Posted by Frank Budinsky <fr...@ca.ibm.com>.
SDO set() doesn't work that way. All the steps in a path, except the last 
one, must exist. 

If your use case is simple, then you can just write a loop that calls 
createDataObject() for each name leading up to the last. But it's not a 
generally solvable problem. For example what would you do if the type of 
the "RearAxle" property was an abstract type? You can't create an instance 
of it, so the user would need to specify a concrete subclass. Also, what 
would you do if the property was many valued and the path was something 
like "RearAxle[3]/Length"? You would need to create 3 RearAxle's to make 
it work.

Frank.

stf_polska <st...@o2.pl> wrote on 03/14/2007 09:04:51 PM:

> Hello
> 
> After registering the types (with SDOUtil.registerStaticTypes) I am able 

> to do this:
> 
> DataObject car = DataFactory.INSTANCE.create("some://namespace", "Car");
> 
> After that, I am able to set simple properties:
> 
> car.set("Color", "Green");
> 
> However, when I try with nested ("containment"?) properties:
> 
> car.set("RearAxle/Length", "50");
> 
> it raises java.lang.NullPointerException. I have to do this first:
> 
> car.createDataObject("RearAxle");
> 
> Then I can proceed with this:
> 
> car.set("RearAxle/Length", "50");
> 
> The question is:
> 
> How to make DataObject.set (or some other dynamic setters, like 
> DataObject.setString) create all the nested properties that are needed?
> 
> One could try to parse that path ("RearAxle/Length") by hand, and create 

> those properties by hand. But it seems that those could be complicated 
> expressions, and in fact I do not know them before runtime. So, if that 
> parsing is already done somewhere there in Tuscany internals, I would 
> like not to duplicate it.
> 
> Thanks.
> 
> -- 
>      Leave this world better than it was when you were born.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-user-help@ws.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-user-help@ws.apache.org