On 11/9/06, Robert Eric Reeves <[EMAIL PROTECTED]> wrote:
Previously, I was using JAXB 1.04 and had a hack in place to see if fields were set on the JAXB Types. For example, say I have an element with attribute "foo" set to boolean type like so: <xsd:complexType name="elementType"> <xsd:attribute name="foo" type="xsd:boolean" /> </xsd:complexType>
My personal favourite is to have the primitive boolean replaced with on object in such cases: <xsd:attribute name="foo" type="xsd:boolean"> <xsd:annotation><xsd:appinfo> <jaxb:property> <jxb:baseType><jxb:javaType name="java.lang.Boolean"/></jxb:baseType> </jaxb:property> </xsd:appinfo></xsd:annotation> </xsd:attribute> In other words, you would check for null or non-null. Another alternative would be to have isFooSet() method generated. (Don't remember exactly how that is done, look into a JAXB tutorial.) Jochen
When I got a reference to elementType and executed isFoo(), I would get a "false" regardless if foo was set in the XML or not. Luckily, the Sun JAXB implementation of ElementTypeImpl had fields that were protected -- specifically, a "has_Foo" field. So, I just hacked together a JAXBUtil class that sat in the same package as my generated JAXB classes. Then, I would use JAXBUtil to see if the "has_Foo" field was set. Unfortunately, I'm getting the same results with JaxMe, primitives are set to their default. However, the fields in ElementTypeImpl are private. So, my hack no longer works. (Also, the field names are different, but's not a big deal.) I'm in a pickle here because I have to have datatypes set in the XSD (can't use string) because of our existing code. Of course, I can write a perl script to change the fields to protected or public and go back to my previous hack, but that kind of sucks. ***** After comparing the JAXB and JaxMe generated classes, it seems that there is an extra field in the JAXB classes called "has_Foo". Here's what setFoo() looks like: public void setFoo(boolean value) { _Foo = value; has_Foo = true; } Any suggestions would be great. Thanks! Robert --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- My wife Mary and I have been married for forty-seven years and not once have we had an argument serious enough to consider divorce; murder, yes, but divorce, never. (Jack Benny) --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]