You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by Jawad - CitizenPlace <ja...@citizenplace.com> on 2010/09/08 19:05:16 UTC

Tuscany SDO and xsi:nil

  Hi everyone.

I'm having a hard time trying to add xsi:nil=true to some properties in 
the generated instances.

I have read that doing that was as simple as setting the property to null.
Let's consider that I have a DataObjectBase object called "builtObject". 
My property is called "test" and is set to nillable in my XSD.

If I write builtObject.set("test", null), the property is not set as 
expected : if I then call builtObject.isSet("test"), I get 'false' where 
as I should get true as stated in the specification (test=null + 
isSet(test) = true ==> xsi:nil). Logically, the returned XML simply 
ignores the property while I need it to be present and set to null.

I jumped into the source code of SDO and I got to these lines:
  public static void set(DataObject dataObject, String path, Object value)
  {
Property property = dataObject.getType().getProperty(path);
     if (property != null)
         {
             dataObject.set(property, value);
          }
     else
          {
             Accessor.create((EObject)dataObject, path, 
value).setAndRecyle(value);
     }
}

I do not really understand what is the Accessor used for.

-- 
*Jawad, * pour l'équipe CitizenPlace
Tél : +33 9 52 31 26 45
Mobile : +33 6 20 08 16 13
E-mail : jawad@citizenplace.com <ma...@citizenplace.com>

Re: Tuscany SDO and xsi:nil

Posted by Frank Budinsky <fr...@ca.ibm.com>.
Hi Jawad,

It sure sounds like a Tuscany bug to me, which is strange since this is a
pretty basic function and I don't see anything special about your example
that might be causing the problem.

The underlying EMF EStructuralFeature (the base class of the Property
implementation class) is supposed to be "unsettable" for a nillable
property, meaning it can be explicitly set to null. If the feature is not
"unsettable", then set(null) is the same as unset(), which seems to be the
behavior you're seeing.

The only other thing I would try, which might provide more insight, is to
reverse the two set() calls:

                        builtObject.set(myProperty, "");

                        boolean c = builtObject.isSet(myProperty);

                        builtObject.set(myProperty, null);

                        boolean b = builtObject.isSet(myProperty);

This way you can be sure that set(myProperty, null) is unsetting the
property (i.e., the feature has not been made EMF unsettable) as I'm
guessing. Otherwise it would seem that the set(null) call is somehow
silently failing so it's just a NOOP.

Either way, it looks to me like there's some kind of bug in Tuscany.

Frank


Jawad - CitizenPlace <ja...@citizenplace.com> wrote on 09/08/2010 05:04:53
PM:

> [image removed]
>
> Re: Tuscany SDO and xsi:nil
>
> Jawad - CitizenPlace
>
> to:
>
> user
>
> 09/08/2010 05:10 PM
>
> Please respond to user
>
> Hi Frank and thanks for your quick answer.
>
> My XSD looks exactly like your example and, with property as my
> commonj.sdo.Property object representing test, I get test.isNullable
> () = true. In fact, the actual name of my element is numero_cheque
> (I used test as an example of my situation).
> Here is its exact definition: <element nillable="true"
> name="numero_cheque" type="string"></element>
>
> I tried different things and it worked well:
>     Property property =
> ((org.apache.tuscany.sdo.impl.DataObjectImpl) builtObject).getType
> ().get("numero_cheque"); -> returns a valid property object
>     int featureID = builtObject.eDerivedStructuralFeatureID
> (property); -> returns 8
>
> Maybe I'm not getting down to the Accessor.create() code in fact.
>
> Here is my test code and the associated results:
>                         commonj.sdo.Property myProperty =
> ((org.apache.tuscany.sdo.impl.DataObjectImpl) builtObject).getType
> ().getProperty("numero_cheque");
>
>                         boolean nullable = myProperty.isNullable();
>                         boolean openContent = myProperty.isOpenContent();
>                         boolean readOnly = myProperty.isReadOnly();
>
>                         boolean a = builtObject.isSet(myProperty);
>
>                         builtObject.set(myProperty, null);
>
>                         boolean b = builtObject.isSet(myProperty);
>
>                         builtObject.set(myProperty, "");
>
>                         boolean c = builtObject.isSet(myProperty);
>
> And I get:
>     nullable = true
>     openContent = readOnly = false
>     a = b = false
>     c = true
>
> Jawad
>
> Le 08/09/10 20:42, Frank Budinsky a écrit :
> Even though you say that the "test" property is nillable in the XSD,
> the behavior you're describing really sounds like it is not. Are you
> sure the XSD is valid and the element is nillable? The element
> should look something like this:
>
> <xsd:element name="test" type="..." nillable="true"/>
>
> If you're getting down to the Accessor.create() code, it implies
> that there is no property named "test" in the type, which seems to
> imply that there's something wrong with your metadata.
>
> Frank
>
> Jawad - CitizenPlace <ja...@citizenplace.com> wrote on 09/08/2010
01:05:16 PM:
>
> > [image removed]
> >
> > Tuscany SDO and xsi:nil
> >
> > Jawad - CitizenPlace
> >
> > to:
> >
> > user
> >
> > 09/08/2010 01:06 PM
> >
> > Please respond to user
> >
> > Hi everyone.
> >
> > I'm having a hard time trying to add xsi:nil=true to some properties
> > in the generated instances.
> >
> > I have read that doing that was as simple as setting the property to
null.
> > Let's consider that I have a DataObjectBase object called
> > "builtObject". My property is called "test" and is set to nillablein my
XSD.
> >
> > If I write builtObject.set("test", null), the property is not set as
> > expected : if I then call builtObject.isSet("test"), I get 'false'
> > where as I should get true as stated in the specification (test=null
> > + isSet(test) = true ==> xsi:nil). Logically, the returned XML
> > simply ignores the property while I need it to be present and set to
null.
> >
> > I jumped into the source code of SDO and I got to these lines:
> >  public static void set(DataObject dataObject, String path, Object
value)
> >  {
> > Property property = dataObject.getType().getProperty(path);
> >     if (property != null)
> >         {
> >             dataObject.set(property, value);
> >          }
> >     else
> >          {
> >             Accessor.create((EObject)dataObject, path,
> > value).setAndRecyle(value);
> >     }
> > }
> >
> > I do not really understand what is the Accessor used for.
>
> > --
> > Jawad, pour l?équipe CitizenPlace
> > Tél : +33 9 52 31 26 45
> > Mobile : +33 6 20 08 16 13
> > E-mail : jawad@citizenplace.com
>
> --
> Jawad, pour l?équipe CitizenPlace
> Tél : +33 9 52 31 26 45
> Mobile : +33 6 20 08 16 13
> E-mail : jawad@citizenplace.com

Re: Tuscany SDO and xsi:nil

Posted by Jawad - CitizenPlace <ja...@citizenplace.com>.
  Hi Frank and thanks for your quick answer.

My XSD looks exactly like your example and, with property as my 
commonj.sdo.Property object representing test, I get test.isNullable() = 
true. In fact, the actual name of my element is numero_cheque (I used 
test as an example of my situation).
Here is its exact definition: <element nillable="true" 
name="numero_cheque" type="string"></element>

I tried different things and it worked well:
     Property property = ((org.apache.tuscany.sdo.impl.DataObjectImpl) 
builtObject).getType().get("numero_cheque"); -> returns a valid property 
object
     int featureID = builtObject.eDerivedStructuralFeatureID(property); 
-> returns 8

Maybe I'm not getting down to the Accessor.create() code in fact.

Here is my test code and the associated results:
                         commonj.sdo.Property myProperty = 
((org.apache.tuscany.sdo.impl.DataObjectImpl) 
builtObject).getType().getProperty("numero_cheque");

                         boolean nullable = myProperty.isNullable();
                         boolean openContent = myProperty.isOpenContent();
                         boolean readOnly = myProperty.isReadOnly();

                         boolean a = builtObject.isSet(myProperty);

                         builtObject.set(myProperty, null);

                         boolean b = builtObject.isSet(myProperty);

                         builtObject.set(myProperty, "");

                         boolean c = builtObject.isSet(myProperty);

And I get:
     nullable = true
     openContent = readOnly = false
     a = b = false
     c = true

Jawad

Le 08/09/10 20:42, Frank Budinsky a écrit :
>
> Even though you say that the "test" property is nillable in the XSD, 
> the behavior you're describing really sounds like it is not. Are you 
> sure the XSD is valid and the element is nillable? The element should 
> look something like this:
>
> <xsd:element name="test" type="..." nillable="true"/>
>
> If you're getting down to the Accessor.create() code, it implies that 
> there is no property named "test" in the type, which seems to imply 
> that there's something wrong with your metadata.
>
> Frank
>
> Jawad - CitizenPlace <ja...@citizenplace.com> wrote on 09/08/2010 
> 01:05:16 PM:
>
> > [image removed]
> >
> > Tuscany SDO and xsi:nil
> >
> > Jawad - CitizenPlace
> >
> > to:
> >
> > user
> >
> > 09/08/2010 01:06 PM
> >
> > Please respond to user
> >
> > Hi everyone.
> >
> > I'm having a hard time trying to add xsi:nil=true to some properties
> > in the generated instances.
> >
> > I have read that doing that was as simple as setting the property to 
> null.
> > Let's consider that I have a DataObjectBase object called
> > "builtObject". My property is called "test" and is set to nillable 
> in my XSD.
> >
> > If I write builtObject.set("test", null), the property is not set as
> > expected : if I then call builtObject.isSet("test"), I get 'false'
> > where as I should get true as stated in the specification (test=null
> > + isSet(test) = true ==> xsi:nil). Logically, the returned XML
> > simply ignores the property while I need it to be present and set to 
> null.
> >
> > I jumped into the source code of SDO and I got to these lines:
> >  public static void set(DataObject dataObject, String path, Object 
> value)
> >  {
> > Property property = dataObject.getType().getProperty(path);
> >     if (property != null)
> >         {
> >             dataObject.set(property, value);
> >          }
> >     else
> >          {
> >             Accessor.create((EObject)dataObject, path,
> > value).setAndRecyle(value);
> >     }
> > }
> >
> > I do not really understand what is the Accessor used for.
>
> > --
> > Jawad, pour l'équipe CitizenPlace
> > Tél : +33 9 52 31 26 45
> > Mobile : +33 6 20 08 16 13
> > E-mail : jawad@citizenplace.com
>

-- 
*Jawad, * pour l'équipe CitizenPlace
Tél : +33 9 52 31 26 45
Mobile : +33 6 20 08 16 13
E-mail : jawad@citizenplace.com <ma...@citizenplace.com>

Re: Tuscany SDO and xsi:nil

Posted by Frank Budinsky <fr...@ca.ibm.com>.
Even though you say that the "test" property is nillable in the XSD, the
behavior you're describing really sounds like it is not. Are you sure the
XSD is valid and the element is nillable? The element should look something
like this:

      <xsd:element name="test" type="..." nillable="true"/>

If you're getting down to the Accessor.create() code, it implies that there
is no property named "test" in the type, which seems to imply that there's
something wrong with your metadata.

Frank

Jawad - CitizenPlace <ja...@citizenplace.com> wrote on 09/08/2010 01:05:16
PM:

> [image removed]
>
> Tuscany SDO and xsi:nil
>
> Jawad - CitizenPlace
>
> to:
>
> user
>
> 09/08/2010 01:06 PM
>
> Please respond to user
>
> Hi everyone.
>
> I'm having a hard time trying to add xsi:nil=true to some properties
> in the generated instances.
>
> I have read that doing that was as simple as setting the property to
null.
> Let's consider that I have a DataObjectBase object called
> "builtObject". My property is called "test" and is set to nillable in my
XSD.
>
> If I write builtObject.set("test", null), the property is not set as
> expected : if I then call builtObject.isSet("test"), I get 'false'
> where as I should get true as stated in the specification (test=null
> + isSet(test) = true ==> xsi:nil). Logically, the returned XML
> simply ignores the property while I need it to be present and set to
null.
>
> I jumped into the source code of SDO and I got to these lines:
>  public static void set(DataObject dataObject, String path, Object value)
>  {
> Property property = dataObject.getType().getProperty(path);
>     if (property != null)
>         {
>             dataObject.set(property, value);
>          }
>     else
>          {
>             Accessor.create((EObject)dataObject, path,
> value).setAndRecyle(value);
>     }
> }
>
> I do not really understand what is the Accessor used for.

> --
> Jawad, pour l?équipe CitizenPlace
> Tél : +33 9 52 31 26 45
> Mobile : +33 6 20 08 16 13
> E-mail : jawad@citizenplace.com