ADB Tweaking Guide

Introduction

ADB is written with future extensions in mind, with a clear and flexible way to extend or modify it's functionality. This document explains available mechanisms to extend ADB and possibly adopt it to compile schemas to support other languages.

Know the Configuration

The configuration for the ADB framework is in the schema-compile.properties file found in the org.apache.axis2.databinding.schema package. This properties file has the following important properties

  • schema.bean.writer.class

    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 inteface. The schema compiler delegates the bean writing task to the specified instance of the BeanWriter.

  • schema.bean.writer.template

    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 require a template.

  • schema.bean.typemap

    This is the type map to be used by the schema compiler. it should be an implementation of the org.apache.axis2.schema.typemap interface. The default typemap implementation encapsulates a hashmap with type QName to Class name string mapping.

The First Tweak - Generate Plain Java Beans

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 love to have plain java beans. This can infact 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.

Congratualtions! 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 availble 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.

A More Advanced Tweak - Generate Code for Another Language

To generate code for another language, there are two main components are to be written.

  • The BeanWriter

    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. Infact if the language is OOP based (such as C# or even C++), one would even be able to extend the JavaBeanWriter itself.

  • The TypeMap

    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.

Surprisngly this is enough to have other language support for ADB. Change the configuration and you are ready to generate code for other lanuages!

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 experiment with it and modify the schema compiler accordingly to their needs.