This document explains the mechanisms available to extend ADB and possibly adopt it to compile schemas to support other languages.
ADB was written with future extensibility in mind, with a clear and flexible way to extend or modify its functionality. Available mechanisms to extend ADB and possibly adopt it to compile schemas to support other languages are described below.
The configuration for the ADB framework is in the schema-compile.properties file found in the org.apache.axis2.schema package. This properties file has the following important properties
This is the writer class. This is used by the schema compiler to write the beans and should implement the org.apache.axis2.schema.writer.BeanWriter interface. The schema compiler delegates the bean writing task to the specified instance of the BeanWriter.
This specifies the template to be used in the BeanWriter. The BeanWriter author is free to use any mechanism to write the classes but the default mechanism is to use a xsl template. This property may be left blank if the BeanWriter implementation does not use a template.
This is the type map to be used by the schema compiler. It should be an implementation of the org.apache.axis2.schema.typemap.TypeMap interface. The default typemap implementation encapsulates a hashmap with type QName to Class name string mapping.
The first, most simple tweak for the code generator could be to switch to plain bean generation. The default behavior of the ADB framework is to generate ADBBeans, but most users, if they want to use ADB as a standalone compiler, would prefer to have plain java beans. This can in fact be done by simply changing the template used.
The template for plain java beans is already available in the org.apache.axis2.schema.template package. To make this work replace the /org/apache/axis2/databinding/schema/template/ADBBeanTemplate.xsl with the /org/apache/axis2/databinding/schema/template/PlainBeanTemplate.xsl in the schema-compile.properties.
Congratulations! You just tweaked ADB to generate plain java beans.
To generate custom formats, the templates need to be modified. The schema for the xml generated by the JavaBeanWriter is available in the source tree under the Other directory in the codegen module. Advanced users with knowledge of XSLT can easily modify the templates to generate code in their own formats.
To generate code for another language, there are two main components that need to be written.
Implement the BeanWriter interface for this class. A nice example is the org.apache.axis2.schema.writer.JavaBeanWriter which has a lot of reusable code. In fact if the target language is object-oriented (such as C# or even C++), one would even be able to extend the JavaBeanWriter itself.
Implement the TypeMap interface for this class. The org.apache.axis2.schema.typemap.JavaTypeMap class is a simple implementation for the typemap where the QName to class name strings are kept inside a hashmap instance. This technique is fairly sufficient and only the type names would need to change to support another language.
Surprisingly, this is all that needs to be done to have other language support for ADB. Change the configuration and you are ready to generate code for other languages!
This tweaking guide is supposed to be a simple guideline for anyone who wishes to dig deep into the mechanics of the ADB code generator. Users are free to experiment with it and modify the schema compiler accordingly to their needs. Also note that the intention of this section is not to be a step by step guide to custom code generation. Anyone who wish to do so would need to dig into the code and get their hands dirty!