users@jaxb.java.net

Re: How to map xs:integer to java.lang.Integer within jxb:bindings jxb:bindings?

From: removeps <removeps-generic_at_yahoo.com>
Date: Fri, 6 Feb 2009 11:22:48 -0800 (PST)

For my case, it seems the solution is to use xs:int (java type = int in my
case where the attribute is required) instead of xs:integer (java type =
BigInteger), and xs:double (java type = double in my case) instead of
xs:number (java type = BigDecimal). This saves me from having to type
".intValue()" to convert the BigInteger into an int.


The easiest way would be to take the generated Adapter1.java, refactor it
any way you like, and change the customization to one that explicitly
specifies the attributes parseMethod and printMethod in <jxb:javaType>.
These two attribute values consist of <package>.<class>.<method>.

-W

On Thu, Jan 8, 2009 at 5:13 AM, <removeps-groups_at_yahoo.com> wrote:

> How to map xs:integer to java.lang.Integer within jxb:bindings
> jxb:bindings?
>
> On the web there are examples of how to do this within the xsd, using
> xs:annotation and so forth. But I'd like to do it through an external
> bindings file.
>
> Using jxb:globalBindings within jxb:bindings works:
>
> <jxb:bindings version="1.0"
> xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
> <jxb:globalBindings>
> <jxb:javaType name="java.lang.Integer" xmlType="xs:integer"/>
> </jxb:globalBindings>
> <jxb:bindings schemaLocation="mydef.xsd" node="/xs:schema">
> <jxb:schemaBindings>
> <jxb:package name="mypackage"/>
> </jxb:schemaBindings>
> </jxb:bindings>
> </jxb:bindings>
>
> However, it generates a class org.w3._2001.xmlschema.Adapter1.java. I
> would like the file to be mypackage.Adapter1. So I tried:
>
> <jxb:bindings version="1.0"
> xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
> <jxb:bindings schemaLocation="mydef.xsd" node="/xs:schema">
> <jxb:property>
> <jxb:baseType>
> <jxb:javaType name="java.lang.Integer" xmlType="xs:integer"/>
> </jxb:baseType>
> </jxb:property>
> <jxb:schemaBindings>
> <jxb:package name="mypackage"/>
> </jxb:bindings>
> </jxb:bindings>
>
> but xjc gives an error
>
> [ERROR] cvc-complex-type.3.2.2: Attribute 'xmlType' is not allowed to
> appear in element 'jxb:javaType'.
> line 7 of file:...


-- 
View this message in context: http://www.nabble.com/How-to-map-xs%3Ainteger-to-java.lang.Integer-within-jxb%3Abindings-jxb%3Abindings--tp21345571p21879055.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.