Extension Interfaces Feature
Warning Advanced feature.
This feature enables a user to specify sets of generated xbean interfaces that will extend user interfaces ( extension interfaces ). Also, generated implementation classes will also implement the methods in the extension interfaces, they will delegate to a user handler.
This feature is useful for extending the xbeans with methods unrelated to the properties in the schema type it represents. For example to a
PurchaseOrder type a
float getTotalAmount() method can be added, which will calculate the total amount of the ordered items.
Or this feature will enable the xbean objects to represent other interfaces.
Given a schema that generates for example
xsd.company.CompanyDocument xbean, a user might want it to extend his own interface
The .xsdconfig file that will enable this is:
The for attribute can accept a list of xbean java interfaces (separated by space) or * to include all of them in the extension. Why the java names of the xbeans, when all we have at the beginning is schema files? Because there are java xbeans generated also for anonymous types, and we believe that the java names is a more cleaner solution than inventing an expression language for specifying all the anonymous/implied schema types.
The generated xbean interface
xsd.company.CompanyDocument will extend
myPachage.Foo interface. In our example the interface
myPackage.Foo contains only one method:
In the xbean implementation class
xsd.company.impl.CompanyDocumentImpl methods will get generated to implement the extension interface and they will delegate to the extension handler methods.
myPackage.FooHandler has to contain a public static method with the same name as the interface method, with the first parameter of type XmlObject, followed by the parameters of the interface method:
This method will be executed every time the foo method on
xsd.company.CompanyDocument will be called.
Because of the circular dependency building all the pieces can be a little tricky. (An implementation using JAM will improve the building process.)
- scomp .xsd files to xmltypes.jar ( .xsdconfig files might be included but they should not contain an
- write and compile the extension interfaces and the handler classes using xbean.jar and xmltypes.jar
- add the
extensionelement to the .xsdconfig file
- run scomp again with .xsd and .xsdconfig files setting xmltypes.jar and compiled extension classes on the classpath