highsource / jaxb2-basics

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

Possibilty to find a fix for fixedValues in ComplexType restriction #166

Open AndreasIgelCC opened 1 year ago

AndreasIgelCC commented 1 year ago

Hi at all,

first, thank you for all your work and this plugin here!

Currently we have the problem in handling that (commonly known) problem with generated Java-Code on Types which restricts a complex type by fixed values. Example:

    <xs:complexType name="complexTypeWithSequence">
        <xs:sequence>
            <xs:element name="a" type="xs:string"/>
            <xs:element name="b" type="xs:long"/>
        </xs:sequence>
                <xs:attribute name="attributeA" type="xs:string" use="optional"/>
    </xs:complexType>
    <xs:complexType name="complexTypeWithSequenceAndConst">
        <xs:complexContent>
            <xs:restriction base="complexTypeWithSequence">
                        <xs:attribute name="attributeA" type="xs:string" use="optional" fixed="exampleConstantValue"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

The generation would create 2 classes: ComplexTypeWithSequence and ComplexTypeWithSequenceAndConst. ComplexTypeWithSequenceAndConst would inherit from ComplexTypeWithSequence, but no getters/setters are generated and the fixed value is totally lost. Same happens when using default instead of fixed. Of course this could be solved by using the globalBinding-option "xjc:treatRestrictionLikeNewType" in jxb-bindings-file But by that all inheritence is lost, even where it is generated correctly.

From my point of view a solution would be best, which has a look on the generated java class and injects an override to the existing parent-class if there is a restriction with default value. But could that kind of problem be solved with a jaxb2-basics-plugin here or does even the idea for solution leads to the correct direction? And if that is the case, could you give a hint how to solve that best?

Best regards, Andreas