Search code examples
javasap-commerce-cloudhybris-data-hub

Generate a final class from -items.xml in Hybris


Final class in java means its not extendable by any other class. How do we do it in hybris while defining data-model in -Items.xml ?


Solution

  • SAP Hybris platform does not support generation of the final data-model classes OOTB (Out Of The Box). You cannot override that mechanism, but you are allowed to modify generated class located in the src directory. If you want a final data-model class (e.g. Foo), you can manually add this modifier.

    <itemtypes>
        <itemtype code="Foo" jaloclass="org.example.Foo">
            <attributes>
                <!-- attributes -->
            </attributes>
        </itemtype>
    </itemtypes>
    

    File structure:

    • src/org/example/Foo ← you can mark this class as final
    • gensrc/org/example/GeneratedFoo ← you cannot modify this class

    (class Foo extends GeneratedFoo)

    All extensions with types which extend Foo will fail during build phase.


    SAP Hybris platform allows only to set an abstract modifier by using an abstract attribute equal to true:

    <itemtypes>
        <itemtype code="Foo" abstract="true">
            <attributes>
                <!-- attributes -->
            </attributes>
        </itemtype>
    </itemtypes>