xml-xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Radu Preotiuc-Pietro" <ra...@bea.com>
Subject RE: XmlValueNotNillableException
Date Fri, 30 Jul 2004 23:01:12 GMT
Let me try and summarize this.
Issue nr.1: XmlBeans always returns true when isSetXXX() is called for an attribute property,
even when the attribute is not there. this seems like a bug
Issue nr.2: When trying to call setXXX(null) on an item that is non-nillable, an exception
is being thrown if the property corresponds to a global element and no exception is produced
when the property corresponds to a local element.
Issue nr.3: When calling setXXX(null) on a property corresponding to an an optional element/attribute,
an exception is thrown instead of the optional element/attribute being removed. This is not
so clear-cut. I would say that it makes in my opinion sense to have both setNilXXX() and unsetXXX()
to deal with nillable and optional elements. In Schema, these are two different concepts,
in Java of course there is no difference between an unset Java property and a Java property
set to null. Another nice thing about the way the API exists today is that 'set' will always
only affect the contents of a container (element or attribute), whereas 'addNew' and 'unset'
will affect the container directly.
As for copying the address field-by-field, wouldn't it be simpler/more efficient to just use
newPerson.setAddress(oldAddress)? (copy the address as a whole, rather than copying the fields
individualy)

Thanks,
Radu

-----Original Message-----
From: Mike Perham [mailto:Mike.Perham@webifysolutions.com]
Sent: Thursday, July 29, 2004 6:53 AM
To: xmlbeans-user@xml.apache.org
Subject: RE: XmlValueNotNillableException


Another issue which seems to be related.  I have this attribute:

<xs:attribute name="lastPasswordUpdate" type="xs:dateTime"
use="optional"/>

In the related Java bean:

isSetLastPasswordUpdate() always returns true
and
getLastPasswordUpdate() throws XmlValueOutOfRangeException if the value
is unset.

So there is no way for the bean holder to even determine if the value is
set.  Should I be using nil="true" instead?  Can someone write up a Wiki
page on the semantic differences between use="optional", minoccurs="0"
and nil="true"?

-----Original Message-----
From: Kevin Krouse [mailto:kkrouse@bea.com] 
Sent: Tuesday, July 27, 2004 2:04 PM
To: xmlbeans-user@xml.apache.org
Subject: RE: XmlValueNotNillableException

Yes, you should check for null before setting it.  Setting a value of
null is equivalent to having xsi:nil="true" on the element.

________________________________

From: MIDON ALEXIS [mailto:ALEXIS.MIDON@sgam.com]
Sent: Tuesday, July 27, 2004 9:53 AM
To: 'xmlbeans-user@xml.apache.org'
Subject: XmlValueNotNillableException


 
Hello,
 
my schema defines an AddressInfo element. All the sub elements
(streetname, cityname, etc.) are optional.
 
I map this element with an AddressDTO as shown in the following code :
 
 
public static AddressInfo createAddress(AddressDTO dto) {
      AddressInfo address = AddressInfo.Factory.newInstance();

 
      address.setStreetName(dto.getAddress());
      address.setCityName(dto.getCity());
      address.setPostalCode(dto.getZipCode());

      return address;
 }
 
To that point I make no assumptions on the dto field value, ie the
getters could return null (this is the reason why tags are optional)
 
Unfortunately this code throws an unknown (i didn't find out any
javadocs) and unchecked exception :
org.apache.xmlbeans.impl.values.XmlValueNotNillableException
 
My biz fails due to this exception. :(
 
Is it a bug? a bad practice? Did I miss something?
 
Should I test every nullable value before setting the XMLObject ?
 
ex :
      if(dto.getAddress()!=null)
            address.setStreetName(dto.getAddress());
      if(dto.getCityName()!=null)
          address.setCityName(dto.getCity());
      if(dto.getPostalCode()!=null)
          address.setPostalCode(dto.getZipCode());
 
 
 
Thx for your help.
 
 
Alexis

- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/



- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Mime
View raw message