You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Mauro Molinari <ma...@cardinis.com> on 2007/11/15 16:03:25 UTC

Optional elements of primitive type

Hello all!
I'm writing a WSDL with an operation with an optional parameter:

Suppose this is the input:

<xsd:element name="somma">
   <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="a" type="xsd:int" minOccurs="0" />
        <xsd:element name="b" type="xsd:int"/>
      </xsd:sequence>
    </xsd:complexType>
</xsd:element>

Or, alternatively, this:

<xsd:element name="somma">
   <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="a" type="xsd:int" nillable="true" />
        <xsd:element name="b" type="xsd:int"/>
      </xsd:sequence>
    </xsd:complexType>
</xsd:element>

WSDL2Java generates (using -uw):

public returnType myOperation(int a, int b);

while I would expect:

public returnType myOperation(Integer a, int b);

because a could be null!!!
The same happens with return types.

Looking at the source code of the generated type Somma, I see that the 
parser sets a to Integer.MIN_VALUE if it is absent (case #1) or nil 
(case #2): but why Axis2 uses this strange convention (MIN_VALUE = nil) 
instead of the much more natural null = nil?

I guess something similar happens with other primitive types (double, 
for instance)...

Thanks in advance!

-- 
Mauro Molinari
Software Developer
mauro.molinari@cardinis.com

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


Re: Optional elements of primitive type

Posted by Mauro Molinari <ma...@cardinis.com>.
I have created a JIRA for this:
https://issues.apache.org/jira/browse/AXIS2-3353

Cheers.

-- 
Mauro Molinari
Software Developer
mauro.molinari@cardinis.com

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


Re: Optional elements of primitive type

Posted by Mauro Molinari <ma...@cardinis.com>.
Any hint for this?
I just noticed that nil booleans are mapped to boolean false in Java, 
instead of a null Boolean reference :-(

Thanks in advance!

-- 
Mauro Molinari
Software Developer
mauro.molinari@cardinis.com

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


Re: Optional elements of primitive type

Posted by Mauro Molinari <ma...@cardinis.com>.
Amila Suriarachchi ha scritto:
> As I remember there were some alternatives to this and this is what we did.
> Idea was to keep the variable type as int since it is convenitent to use.
> 
> As you have told when it comes to boolean there is a problem.
> In programming we use a boolean to keep two states. So Are we really
> going to handle three states with the booleans.
> 
> thanks,
> Amila.

Well, I think that one of the benefits of using Integer, Double, 
Boolean, etc. instead of int, double, boolean etc. is that an Integer, 
Double, Boolean can also be null.
"null" can have a lot of meanings, even for a boolean parameter.

Also C# in .NET 2.0 improved against .NET 1.1 by allowing to specify 
null for simple types when corresponding elements are marked as nillable.

I think that WSDL2Java should, at least, give you the option to use the 
wrapper classes instead of the primitive types when (and only when) this 
is necessary (i.e.: when an element in the WSDL is defined as nillable 
or when it is marked with minOccurs="0"+maxOccurs="1"). IMHO, this 
option should also be on by default...

Amila, since this is a strong need for us, do you think you could do 
something? Should I open a JIRA? Is there any hope to have this feature 
in a new nightly build?

Thanks in advance!

-- 
Mauro Molinari
Software Developer
mauro.molinari@cardinis.com

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


Re: Optional elements of primitive type

Posted by Amila Suriarachchi <am...@gmail.com>.
On Nov 15, 2007 8:33 PM, Mauro Molinari <ma...@cardinis.com> wrote:
> Hello all!
> I'm writing a WSDL with an operation with an optional parameter:
>
> Suppose this is the input:
>
> <xsd:element name="somma">
>    <xsd:complexType>
>       <xsd:sequence>
>         <xsd:element name="a" type="xsd:int" minOccurs="0" />
>         <xsd:element name="b" type="xsd:int"/>
>       </xsd:sequence>
>     </xsd:complexType>
> </xsd:element>
>
> Or, alternatively, this:
>
> <xsd:element name="somma">
>    <xsd:complexType>
>       <xsd:sequence>
>         <xsd:element name="a" type="xsd:int" nillable="true" />
>         <xsd:element name="b" type="xsd:int"/>
>       </xsd:sequence>
>     </xsd:complexType>
> </xsd:element>
>
> WSDL2Java generates (using -uw):
>
> public returnType myOperation(int a, int b);
>
> while I would expect:
>
> public returnType myOperation(Integer a, int b);
>
> because a could be null!!!
> The same happens with return types.
>
> Looking at the source code of the generated type Somma, I see that the
> parser sets a to Integer.MIN_VALUE if it is absent (case #1) or nil
> (case #2): but why Axis2 uses this strange convention (MIN_VALUE = nil)
> instead of the much more natural null = nil?
As I remember there were some alternatives to this and this is what we did.
Idea was to keep the variable type as int since it is convenitent to use.

As you have told when it comes to boolean there is a problem.
In programming we use a boolean to keep two states. So Are we really
going to handle three states with the booleans.

thanks,
Amila.
> I guess something similar happens with other primitive types (double,
> for instance)...
>
> Thanks in advance!
>
> --
> Mauro Molinari
> Software Developer
> mauro.molinari@cardinis.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>



-- 
Amila Suriarachchi,
WSO2 Inc.

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