You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using jaxb-rich-contract-plugin in conjunction with the -XInheritance arg of the jaxb-plugins plugin. This allows for having a common interface class for all items in a choice when this cannot be achieved with extension in the xsd (e.g. if some/all of them already extend something else).
Look at com.kscs.jaxb2.contract.test.JavadocAnnotations.ChoiceOfElementsTwo
This is working OK due to the presence of the common Transport super type in the xsd.
publicstaticclassChoiceOfElementsTwoimplementsCloneable {
protectedTransporttransport;
...
publicstaticclassBuilder<_B >implementsBuildable {
protectedfinal_B_parentBuilder;
protectedfinalJavadocAnnotations.ChoiceOfElementsTwo_storedValue;
// transport is a Transport.Builderprivatecom.kscs.jaxb2.contract.test.Transport.Builder<JavadocAnnotations.ChoiceOfElementsTwo.Builder<_B>> transport;
...
publicJavadocAnnotations.ChoiceOfElementsTwo.Builder<_B> withTransport(finalTransporttransport) {
this.transport = ((transport == null)?null:newcom.kscs.jaxb2.contract.test.Transport.Builder<>(this, transport, false));
returnthis;
}
publicJavadocAnnotations.ChoiceOfElementsTwo.Builder<_B> withBike(finalBikebike) {
this.transport = ((bike == null)?null:newBike.Builder<>(this, bike, false));
returnthis;
}
Look at com.kscs.jaxb2.contract.test.ReservedWordsSingleChoice
Using Object as the common type. This works but withObject(Object object) is not clear or type safe.
publicclassReservedWordsSingleChoiceimplementsCloneable {
protectedObjectobject;
...
publicstaticclassBuilder<_B >implementsBuildable {
protectedfinal_B_parentBuilder;
protectedfinalReservedWordsSingleChoice_storedValue;
// object is NOT a builder, but as Object is the super type for everything it compilesprivateObjectobject;
publicReservedWordsSingleChoice.Builder<_B> withObject(finalObjectobject) {
this.object = object;
returnthis;
}
publicReservedWordsSingleChoice.Builder<_B> withImport(finalImport_import) {
this.object = ((_import == null)?null:newImport.Builder<>(this, _import, false));
returnthis;
}
Look at com.kscs.jaxb2.contract.test.InheritanceSingleChoice
This one won't compile.
bind the choice items to the Reserved interface using -XInheritance plugin and set it as the base type for the choice:
publicclassInheritanceSingleChoiceimplementsCloneable {
protectedReservedreserved;
...
publicstaticclassBuilder<_B >implementsBuildable {
protectedfinal_B_parentBuilder;
protectedfinalInheritanceSingleChoice_storedValue;
// NOT a builder classprivateReservedreserved;
publicInheritanceSingleChoice.Builder<_B> withReserved(finalReservedreserved) {
this.reserved = reserved;
returnthis;
}
publicInheritanceSingleChoice.Builder<_B> withImport(finalImport_import) {
// Does not compile as reserve is not a builder/buildablethis.reserved = ((_import == null)?null:newImport.Builder<>(this, _import, false));
returnthis;
}
I appreciate that -XInheritance is not yours but it is very useful for adding marker interfaces to choice items to make the builder methods much clearer when there is no common supertype in the xsd.
I think my original PR changed it so the builder had a field like this + some other changes to the constructors.
privateBuildablereserved;
Given that my original PR broke some of your use cases it is difficult for me to try to fix this without breaking them again. I would be grateful if you could have a look to see if this can be fixed in a way that satisfies your cases and mine.
Tested on v4.2.0.0
The text was updated successfully, but these errors were encountered:
master...at055612:jaxb2-rich-contract-plugin:inheritance-and-choice
I am using jaxb-rich-contract-plugin in conjunction with the
-XInheritance
arg of the jaxb-plugins plugin. This allows for having a common interface class for all items in a choice when this cannot be achieved with extension in the xsd (e.g. if some/all of them already extend something else).This used to work after this PR https://github.com/mklemm/jaxb-rich-contract-plugin/pull/53/files#diff-056f4b958f99f841eae8c7cbe0de52fd4e08bada6ab322fe43b3b639976bf600 but is now broken after some of that was backed out.
On my branch, build the test module.
Look at
com.kscs.jaxb2.contract.test.JavadocAnnotations.ChoiceOfElementsTwo
This is working OK due to the presence of the common Transport super type in the xsd.
binding:
Generated code:
Look at
com.kscs.jaxb2.contract.test.ReservedWordsSingleChoice
Using Object as the common type. This works but
withObject(Object object)
is not clear or type safe.binding:
Generated code:
Look at
com.kscs.jaxb2.contract.test.InheritanceSingleChoice
This one won't compile.
bind the choice items to the
Reserved
interface using-XInheritance
plugin and set it as the base type for the choice:Generated code:
I appreciate that
-XInheritance
is not yours but it is very useful for adding marker interfaces to choice items to make the builder methods much clearer when there is no common supertype in the xsd.I think my original PR changed it so the builder had a field like this + some other changes to the constructors.
Given that my original PR broke some of your use cases it is difficult for me to try to fix this without breaking them again. I would be grateful if you could have a look to see if this can be fixed in a way that satisfies your cases and mine.
Tested on v4.2.0.0
The text was updated successfully, but these errors were encountered: