highsource / jaxb2-basics

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

Interface inheritance not working for complexTypes with mixed=true #70

Closed leikingo closed 8 years ago

leikingo commented 8 years ago

Hi.

I'm having an issue with attaching a custom interface to a complexContent element which is set to mixed=true.

I modified the cxf sample project to reproduce the error.

<xs:complexType name="FaultType">
    <xs:complexContent mixed="true">
      <xs:extension base="xs:anyType">
        <xs:attribute name="id" type="xs:anyURI" use="required"/>
        <xs:anyAttribute processContents="lax"/>
      </xs:extension>
    </xs:complexContent>
</xs:complexType>

The binding file:

<jaxb:bindings schemaLocation="schema.xsd" node="/xsd:schema">
    <jaxb:schemaBindings>
        <jaxb:package name="org.jvnet.jaxb2_commons.tests.cxf.schema"/>
    </jaxb:schemaBindings>      
    <jaxb:bindings node="//xsd:complexType[@name='FaultType']">
        <inheritance:implements>org.sample.test.MyInterface</inheritance:implements>
    </jaxb:bindings>
</jaxb:bindings>

And the simple interface:

public interface MyInterface {
    default void sayHello(){
      System.out.println("Hello world");
    }   
}

When I try the compilation I get the following error:

[WARNING] Exception in thread "main" org.apache.cxf.tools.common.ToolException: file:/C:/tmp/jaxb2-basics-sample-cxf-0.11.0/src/main/resources/bindings.xjb [42,28]: compiler was unable to honor this inheritance:implements customization. It is attached to a wrong place, or its inconsistent with other bindings.
[WARNING] file:/C:/tmp/jaxb2-basics-sample-cxf-0.11.0/src/main/resources/schema.xsd [43,2]: (the above customization is attached to the following location in the schema)

The interesting thing is, when I remove the attribute "mixed=true" from the complexContent in the xsd, everything works fine. Unfortunately I need this flag to allow simple string and xml content.

Do you have any idea what's causing this error? All the other custom interfaces like Copy2, Equals2 work even with mixed set to true.

Thanks

highsource commented 8 years ago

Mixed types are a quite weird in XJC. The problem is that customization does not gets attached to where the plugin expects it. Try attaching it to other elemenets like complexContent etc.

Would you consider adding a test case (complex type named issueGH70Type and customization) here:

https://github.com/highsource/jaxb2-basics/blob/master/tests/issues/src/main/resources/schema.xsd

I'd be grateful for a pull request.

Equals2 and HashCode2 are nonproblematic because they don't come via customization, they are added to all of the types. The problem here is customization.

leikingo commented 8 years ago

I was expecting this. Too bad but thanks for the quick response. I created a pull request with the changes (hopefully correct since I was not able to run a build...)

highsource commented 8 years ago

Thank you for the PR!

highsource commented 8 years ago

Seems like XJC attaches the same customization twice - once to the type and once to the property.

leikingo commented 8 years ago

So maybe there is a way to specify the binding more precise, thus the property gets ignored?

highsource commented 8 years ago

Nope. The binding is duplicated by XJC. I'll just mark implements and extends customizations on properties as acknowledged and just ignore them.

highsource commented 8 years ago

Here you go.

leikingo commented 8 years ago

Awesome. That was fix! Thanks. Can we expect a release soon?

highsource commented 8 years ago

On it.

leikingo commented 8 years ago

And again: great! Thanks very much!

leikingo commented 8 years ago

Just a side question (sorry I don't know where to ask elsewhere): Is it possible to add the "mixed=true" via bindings? I was thinking about the annotate plugin but I the result would still be protected List<Element> any; and thou I won't be able to access String contents...

highsource commented 8 years ago

I don't think so, not out of the box. You can write a plugin to do whatever you want (including adding mixed properties via customizations), but that's probably not what you're asking.

leikingo commented 8 years ago

Okay...I was expecting this.Too bad. I'll keep the plugin approach in mind but actually this is currently way off my knowledge...

highsource commented 8 years ago

Released.

leikingo commented 8 years ago

Great. I just tried the new release, works! Thanks again. Just to be sure, cause first I tried the wrong version number: version 1.11.1 instead of 0.11.1 is intended?

highsource commented 8 years ago

Yes, my bad. :( I'll rerelease 0.11.1, 1.11.1 should be ignored, can't be removed anymore.

highsource commented 8 years ago

0.11.1 released now. 1.11.1 is marked as PUBLISHED-BY-MISTAKE.

leikingo commented 8 years ago

Great. Currently the artifact is not yet available in maven central, but I think that will just take some time... Thanks again for the great work!

highsource commented 8 years ago

Its should be already:

http://repo1.maven.org/maven2/org/jvnet/jaxb2_commons/jaxb2-basics/0.11.1/

leikingo commented 8 years ago

Interesting...okay, then it must be some kind of sync problem. I searched at mvnrepository.com but this showed only the 0.11.0 (not even the PUBISHED_BY_MISTAKE one...). Sorry, my fault.

highsource commented 8 years ago

mvnreposity.com does not index immediately.