You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by Robert Eric Reeves <ro...@phurnace.com> on 2006/11/09 20:13:55 UTC

JaxMe and Primitives

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>

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: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org


Re: JaxMe and Primitives

Posted by Robert Eric Reeves <ro...@phurnace.com>.
Perfect, Jochen. Thanks for the response.

Robert

Jochen Wiedmann wrote:
> On 11/9/06, Robert Eric Reeves <ro...@phurnace.com> 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: jaxme-dev-unsubscribe@ws.apache.org
>> For additional commands, e-mail: jaxme-dev-help@ws.apache.org
>>
>>
>
>


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


Re: JaxMe and Primitives

Posted by Jochen Wiedmann <jo...@gmail.com>.
On 11/9/06, Robert Eric Reeves <ro...@phurnace.com> 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: jaxme-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: jaxme-dev-help@ws.apache.org
>
>


-- 
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: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org