highsource / jaxb2-basics

Useful plugins and tools for JAXB2.
BSD 2-Clause "Simplified" License
109 stars 54 forks source link

Inheritance extends not working for bindings on multiple schemas (but implements works) #90

Closed chibicitiberiu closed 6 years ago

chibicitiberiu commented 6 years ago

Hello, I have a bunch of schemas for which I want to generate java classes. Whoever made the schemas used the 'chameleon schema' technique. Basically the same class is defined in every schema where it is used. In order to be able to use these classes, I created a bindings.xjb file which has a bunch of rules like this:

<jxb:bindings schemaLocation="*">
    <jxb:bindings node="//xs:complexType[@name='SomeClass']" multiple="true" required="false">
        <inheritance:implements>path.to.my.Interface</inheritance:implements>
    </jxb:bindings>
    ....

Now I needed to replace that interface with an abstract class, so I did the following:

<jxb:bindings node="//xs:complexType[@name='SomeClass']" multiple="true" required="false">
    <inheritance:extends>path.to.my.AbstractClass</inheritance:extends>
</jxb:bindings>

With this change, I am getting this error: [xjc] [ERROR] compiler was unable to honor this inheritance:extends customization. It is attached to a wrong place, or its inconsistent with other bindings.

I suspect the issue is that I am binding to multiple schemas (using schemaLocation="*" and the multiple="true" flag). I used the inheritance:extends with other types which aren't bound to multiple schemas, and I haven't had any issue with those.

highsource commented 6 years ago

It can be that you're binding to schemas which are not effectively compiled. I have also never seen schemaLocation="*".

I'll need a minimal reproducing test project for this. Please add it under https://github.com/highsource/jaxb2-basics/tree/master/tests and send me a pull request. I'll look into it then.

chibicitiberiu commented 6 years ago

This schemaLocation="*" might actually be the issue. I can't find any information about it, but strangely, it worked so far (until I tried to use the extends).

highsource commented 6 years ago

@chibicitiberiu I'm closing this as you did not provide a minimal reproducing test project.