users@jaxb.java.net

Re: trouble editing xjb file in eclipse. does not not about jaxb and xjc types.

From: Andy Davidson <andy_davidson_at_apple.com>
Date: Wed, 30 May 2012 10:42:57 -0700

Hi Wolfgang

I did not explain what we are trying to do very well. We want to create/maintain/edit the xjb file using an XML, DTD, XSD aware editor like eclipse. These editors will make it much faster and easier for catch bugs. We build our project using Maven. For unknown reasons the xjc errors where not showing up in our build logs. I discovered the bugs by running xjc on the command line. You are correct. when run from the command line xjc did a good job of reporting errors. Most of the problems where related file name changes.

Bellow is a more complete example of our actual xjc file. I deleted most of the contents. eclipse does not know what types are allowed. <jaxb:bug>hello world</jaxb:bug> will not cause an error.

eclipse generates a wanring "No grammer constraints (DTD or XML Schema) detected for the document" thats it. As long as the xml is well formed eclipse does not complain.


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings version="2.0"
        targetNamespace="http://www.apple.com/xxx"
            xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
        xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:pos="http://www.Apple.com/xxx"
        jaxb:extensionBindingPrefixes="xjc">

    <!--
        xxx.xjb
        references:
                        http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/2.0/tutorial/doc/JAXBUsing4.html
                        http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd

                        http://jaxb.java.net/2.1.2/docs/vendorCustomizations.html
                        use <xjc:superClass> to to specify the fully qualified name of the Java class that is to be used as the super
                        class of all the generated implementation classes. The <xjc:superClass> customization can only occur within
                         your <jaxb:globalBindings>
                 
        Copyright 2009 Apple Inc.. All rights reserved.
    -->
        <jaxb:globalBindings>
                <xjc:simple />
                <xjc:serializable uid="-1" />
        </jaxb:globalBindings>
        
           <jaxb:bindings schemaLocation="XXXDetails.xsd">
        <!--
            TODO: this is a short term work around, value, should really be a BigDecimal
        -->
        <jaxb:bindings node="//xs:complexType[@name='xxxDetails']//xs:element[@name='value']">
            <jaxb:javaType name="java.lang.Double"
                parseMethod="javax.xml.bind.DatatypeConverter.parseDouble"
                 printMethod="javax.xml.bind.DatatypeConverter.printDouble" />
        </jaxb:bindings>
    </jaxb:bindings>
        …

</jaxb:bindings>

Given xjc process xsd files. I assume that xjc files would start with a proper <schema> tag and not use well formed XML.

Personally I find the xjc related documentation to be very difficult to find and use. My hope is that by adding the meta data to our xjb files that it will be easier for our programmers to figure out how the xjb file works.

Thanks

Andy


On May 30, 2012, at 10:13 AM, Wolfgang Laun wrote:

> On 30/05/2012, Andy Davidson <andy_davidson_at_apple.com> wrote:
>> Hi
>>
>> I started working on a project that uses an xjb bind file. It looks like
>> this file was written a long time ago and has some bugs.
>
> What makes you think so? Please provide xjc version, error messages,
> source file?
>
>> I am using
>> eclipse
>>
>> The original file starts out with
>>
>> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
>> <jaxb:bindings version="2.0"
>> targetNamespace="http://www.apple.com/ist/retail/pos/common/pojo"
>> xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
>> xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> xmlns:pos="http://www.Apple.com/LAVA"
>> jaxb:extensionBindingPrefixes="xjc">
>>
>> <jaxb:
>> <jaxb:globalBindings>
>> <xjc:simple />
>> <xjc:serializable uid="-1" />
>> </jaxb:globalBindings>
>>
>
> Hardly, this isn't even well formed up to the truncated end.
>
>>
>> eclipse has no knowledge about the jaxb types.
>
> There are no JAXB types. Do you mean the XML schema for JAXB binding
> files? If so, why should Eclipse have any knowledge about it?
>
>>
>> How should I convert the file so that eclipse is able to validate it?
>
> Do you have an XML Schema aware plugin for handling XML files?
> Otherwise, just rely on xjc to find the errors. The diagnostics are
> (most of the time) sufficient.
>
>
>>
>> I found a couple of example that looked sort of like
>>
>> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
>> xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
>> jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0"
>> targetNamespace="http://www.apple.com/ist/retail/pos/common/pojo"
>> xmlns:pos="http://www.Apple.com/LAVA">
>>
>>
>> eclipse still has no knowledge about the jaxb types. I assume I need to add
>> a schemaLocation attribute. What should the value be?
>>
>> I am not sure how to set the schemaLocation. I tried adding a
>> xsi:schemaLocation attribute
>>
>> xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb
>> http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
>
> The second URL looks good.
>
>>
>> I also tried adding an import tag.
>> <xs:import namespace="http://java.sun.com/xml/ns/jaxb"
>> schemaLocation="http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd" />
>>
>> Still did not work.
>
> What did not work?
>
>>
>> I have a similar problem with the xjc types.
>
> There's no such thing, or, rather, what do you think that "xjc types" are?
>
> -W
>
>>
>> Any suggestions would be greatly appreciated.
>>
>> Andy
>>
>>
>>