dizzzz / jing-trang

Automatically exported from code.google.com/p/jing-trang
Other
0 stars 0 forks source link

Add option to not use xs:extension #53

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. java -jar E:\trang-20081028\trang.jar temp.rnc temp.xsd
2. This produces temp.xsd.
3. E:\jaxb-ri\bin\xjc -p org.tempuri.model temp.xsd

Problem 1.
Error "A class/interface with the same name "org.tempuri.model.Baz" is already 
in use. 
Use a class customization to resolve this conflict. This is caused because both 
the 
named pattern "baz and element "baz" appears in xsd as xs:complexType and 
xs:element.
I can work around this issue by renaming the named pattern to "bazRef" or 
something.

Problem 2.
Data binder like xjc produces class called BazRef, which contains single 
instance of 
Baz.

Problem 3.
Data binder like xjc produces Bar class which inherits BazRef class. This is 
expected 
of xjc because the xsd is saying bar extends ns1:bazRef. Class inheritance 
represents 
is-a relationship, but my original rnc schema simply said bar element contains 
a 
single baz element.

  <xs:element name="bar">
    <xs:complexType>
      <xs:complexContent>
        <xs:extension base="ns1:bazRef">
          <xs:sequence>
            <xs:element maxOccurs="unbounded" ref="ns1:quux"/>
          </xs:sequence>
          <xs:attribute name="barattr" use="required"/>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>
  </xs:element>

What is the expected output? What do you see instead?
What I would like is a simple xs:sequence of the elements. See attached 
sequence.xsd.
If it is desirable to produce xs:extension, could you add a command line option 
to 
pick xs:sequence?

  <xs:element name="bar">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="ns1:baz"/>
    <xs:element maxOccurs="unbounded" ref="ns1:quux"/>
        <xs:attribute name="barattr" use="required"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

This produces a Java class similar to what I specified in my original schema. 
See 
Bar2.java.
As you can see I am using xsd mostly to feed my schema to code generators. The 
simpler 
the xsd, the better result I would have.

What version of the product are you using? On what operating system?
My Trang version is 20081028.
My xjc version is hudson-jaxb-ri-2.1-661.

Original issue reported on code.google.com by eed3s...@gmail.com on 20 Nov 2008 at 4:52

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks.  Make sense.

For ease of reference, here's temp.rnc:

default namespace = "http://tempuri.org/"
namespace inherit = inherit

start = element topLevel { foo, bar }

foo = element foo {
    attribute fooattr { text},
    bazRef
}

bar = element bar {
    attribute barattr { text },
    bazRef,
    quux+
}

bazRef = element baz {
    attribute bazattr { text },
    text
}

quux = element quux {
    attribute quuxattr { text },
    text
}

Original comment by jjc.jclark.com on 20 Nov 2008 at 5:22

JGFMK commented 4 years ago

https://www.solidsyntax.be/2013/12/07/howto-use-jaxb-class-customization-avoid-xsd-conflicts/ https://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.5/tutorial/doc/JAXBUsing4.html