You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by MosheElisha <mo...@gmail.com> on 2011/09/18 06:26:52 UTC

How to declare an attribute required and non-primitive?

I have a web sercice method that recieves an object. One of the attributes is
"interval" which is an integer.

I would like to make this atribute required but without providing any
default value - I want the user to be required to explicitly set a value.

If I use int interval - the attribute is exposed as int and if the user does
not explicitly set the attribute, a zero (Java default for primitive int)
will be sent.

If I use Integer interval - the attribute is exposed as Integer and is
declared optional in the WSDL so the user can't see it is required before
sending the request.

If I use Integer interval with @XmlElement(required = true) or
@XmlElement(nillable = false) - the attribute is exposed as int.

The attribute can have any integer - negative, zero and positive so I can't
use a default value to indicate that the attribute was not explicitly set.

I can use BigInteger interval with @XmlElement(required = true) but than we
are missing the advantages of using the core type Integer.

I would like to expose the attribute as Integer so I will get null if the
user did not set the attribute and at the same time I would like the WSDL to
expose that the attribute is required so users will know it is required
simply by looking at the WSDL.

--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-declare-an-attribute-required-and-non-primitive-tp4815370p4815370.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to declare an attribute required and non-primitive?

Posted by MosheElisha <mo...@gmail.com>.
Great! Using "@XmlElement(required = true)" and the "-b <binding-name>"
option kept the element required (minOccurs="1") and exposed it as an
Integer to the client.

Thanks!

--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-declare-an-attribute-required-and-non-primitive-tp4815370p4876761.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to declare an attribute required and non-primitive?

Posted by Daniel Kulp <dk...@apache.org>.
On Tuesday, September 20, 2011 10:06:27 PM MosheElisha wrote:
> When I use the org.apache.cxf.tools.wsdlto.WSDLToJava tool on my WSDL the
> client is generated with "int interval" and I would like it to be generated
> with "Integer interval"

Try creating a jaxb binding file that looks something like:

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
               jaxb:version="2.0">
      <jaxb:globalBindings>
        <jaxb:javaType name="java.lang.Integer"
                       xmlType="xsd:int" />
      </jaxb:globalBindings>
</jaxb:bindings>

and pass that to wsdl2java with the -b flag.



-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Talend - http://www.talend.com

Re: How to declare an attribute required and non-primitive?

Posted by MosheElisha <mo...@gmail.com>.
When I use the org.apache.cxf.tools.wsdlto.WSDLToJava tool on my WSDL the
client is generated with "int interval" and I would like it to be generated
with "Integer interval"

--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-declare-an-attribute-required-and-non-primitive-tp4815370p4825153.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to declare an attribute required and non-primitive?

Posted by Daniel Kulp <dk...@apache.org>.
> If I use Integer interval with @XmlElement(required = true) or
> @XmlElement(nillable = false) - the attribute is exposed as int.

Isn't this what you want?   In the wsdl, it would look like a required "int" 
that the user must specify.   If they don't specify it, you would get null for 
the Integer object.  (although you COULD turn on schema validation in which 
case it would throw a fault back to the user)

Dan



On Saturday, September 17, 2011 9:26:52 PM MosheElisha wrote:
> I have a web sercice method that recieves an object. One of the attributes
> is "interval" which is an integer.
> 
> I would like to make this atribute required but without providing any
> default value - I want the user to be required to explicitly set a value.
> 
> If I use int interval - the attribute is exposed as int and if the user does
> not explicitly set the attribute, a zero (Java default for primitive int)
> will be sent.
> 
> If I use Integer interval - the attribute is exposed as Integer and is
> declared optional in the WSDL so the user can't see it is required before
> sending the request.
> 
> If I use Integer interval with @XmlElement(required = true) or
> @XmlElement(nillable = false) - the attribute is exposed as int.
> 
> The attribute can have any integer - negative, zero and positive so I can't
> use a default value to indicate that the attribute was not explicitly set.
> 
> I can use BigInteger interval with @XmlElement(required = true) but than we
> are missing the advantages of using the core type Integer.
> 
> I would like to expose the attribute as Integer so I will get null if the
> user did not set the attribute and at the same time I would like the WSDL to
> expose that the attribute is required so users will know it is required
> simply by looking at the WSDL.
> 
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/How-to-declare-an-attribute-required-and-no
> n-primitive-tp4815370p4815370.html Sent from the cxf-user mailing list
> archive at Nabble.com.
-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Talend - http://www.talend.com