Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility of inheritance plugin with "-episode" #123

Closed
Vampire opened this issue Nov 18, 2020 · 8 comments
Closed

Compatibility of inheritance plugin with "-episode" #123

Vampire opened this issue Nov 18, 2020 · 8 comments

Comments

@Vampire
Copy link

Vampire commented Nov 18, 2020

I tried to do something like shown at https://dzone.com/articles/reusing-generated-jaxb-classes, with the difference, that the imported schema uses inheritance:implements tags to define interfaces for some of the classes.
But it seems this does not work properly.
The other way around, having inheritance:implements in the importing schema works.
When translating the imported schema with the inheritance:implements tags, the episode file is generated.
If I then want to translate the importing schema, giving the episode file as binding, I get complaints like these:

[ERROR] compiler was unable to honor this implements customization. It is attached to a wrong place, or its inconsistent with other bindings.
  line 372 of file:/.../imported.xsd

[ERROR] (the above customization is attached to the following location in the schema)
  line 366 of file:/.../imported.xsd

Is this not supported?
Can it be supported?
Can I do something differently to make it work?

@mattrpav
Copy link
Collaborator

Can you share your code? We do episodes+inheritance. We place the inheritance rules in a jaxb-bindings file instead of the schema, and we use catalogs for namespace replacement.

@Vampire
Copy link
Author

Vampire commented Feb 22, 2021

Find attached a showcase.zip that demoes the problem.
Just unpack it and execute gradlew showcase in it.

@laurentschoelens
Copy link
Collaborator

@Vampire thanks for the share.
In case you want to know, I managed to make your showcase works with the following adjustements :

  1. Remove inheritance from foo.xsd
    <xs:simpleType name="foo">
        <xs:restriction base="xs:string">
            <xs:enumeration value="FOO"/>
            <xs:enumeration value="BAR"/>
        </xs:restriction>
    </xs:simpleType>
  1. Create the foo.xjb binding file with inheritance customization
<jaxb:bindings
        xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
        jaxb:extensionBindingPrefixes="inheritance"
        jaxb:version="2.1">

    <jaxb:bindings schemaLocation="foo.xsd" node="/xsd:schema">
        <jaxb:bindings node="xsd:simpleType[@name='foo']">
            <inheritance:implements>baz.Baz</inheritance:implements>
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>
  1. Add the following arg to XJC task for foo build

"binding"("file" to "foo.xjb")

I got the following generated with in bar-dest ObjectFactory refering to bar
image

@Vampire
Copy link
Author

Vampire commented Aug 30, 2023

Thanks for the work-around.
It would still be nice if it worked with the inline definition, because having it in an extra file decreases readability and maintainability imho.
But at least if we need to have this constellation, I now have a work-around in the backhand, thanks.
Currently, I only had it while playing around and the actual case where he have it, inheritance is not used so far. :-)

@laurentschoelens
Copy link
Collaborator

Thanks for the work-around.
It would still be nice if it worked with the inline definition, because having it in an extra file decreases readability and maintainability imho.
But at least if we need to have this constellation, I now have a work-around in the backhand, thanks.
Currently, I only had it while playing around and the actual case where he have it, inheritance is not used so far. :-)

@Vampire you're welcome

I found that in jaxb-annotate of highsource with same problem : highsource/jaxb2-annotate-plugin#49

Seems like @highsource did know what could be done to solve the problem (but not giving hint on it - and sadly no more there to tell 😔) and also provide the same workaround as I do.

I'll have to debug to see if something's jumps out from the code. In the meantime, you still can use the workaround provided

@laurentschoelens
Copy link
Collaborator

Hi @Vampire,

Just made a PR in jaxb-ri to fix the above common problem with episode / inlined-plugin-customization in xsd.

@laurentschoelens
Copy link
Collaborator

Hi @Vampire

This is part of the release in 4.0.2 of jaxb-tools

Could you give it a try ?

We will backport this in v2 too soon

@laurentschoelens
Copy link
Collaborator

Fixed by highsource/jaxb-tools#425

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants