JAXX Service Provider Interface

From JAXXWiki

The JAXX Service Provider Interface is an SPI that allows you to easily add support for additional tags or data types using a specially-constructed .jar file. As long as the SPI .jar file is in JAXX's classpath, it will automatically find it and initialize the relevant support.

Contents

The Initializer

The entry point for your SPI .jar will be an implementation of the interface jaxx.spi.Initializer. The Initializer interface defines a single method, initialize(), which will be called when your library is loaded. It is responsible for registering the tags and data types you create.

Creating additional tags

To add support for a new tag, you first have to create an implementation of TagHandler. TagHandler is a very simple interface and can be implemented from scratch with minimal effort, or you can subclass an existing implementation such as DefaultObjectHandler or DefaultComponentHandler.

Once you have a TagHandler implementation, you must have your initializer register it using TagManager.registerBean() (for class tags) or TagManager.registerTag() (for other types of tags). The jaxx.DefaultInitializer class registers all of JAXX's built-in tags and it may be useful to look at its source code for examples.

Creating additional data types

To add support for a new data type, you first have to create an implementation of TypeConverter. TypeHandler is responsible for converting Strings (from XML attributes) into their actual type, and for generating the Java code corresponding to these objects.

Once you have a TypeHandler implementation, you must have your initializer register it using TypeManager.registerTypeConverter(). The jaxx.DefaultInitializer class registers all of JAXX's built-in datatypes and it may be useful to look at its source code for examples.

jaxx.properties

The key to this whole process -- what makes your .jar file a JAXX SPI .jar -- is the jaxx.properties file. jaxx.properties must map the key jaxx.initializer to the name of your Initializer implementation.

For example, this is JAXX's main internal jaxx.properties file:

jaxx.initializer = jaxx.DefaultInitializer

The jaxx.properties file must appear in the root directory of the finished .jar file.

Creating an SPI .jar

Once you have created an Initializer, a jaxx.properties file, and whatever TagHandlers and TypeConverters are required, bundle them together into a .jar file. Don't forget that jaxx.properties file must appear in the .jar file's root directory.

Your SPI .jar file is now finished. Make sure it is in the classpath when you run jaxxc (using the JAXX_OPTS environment variable), and your new tags and types will be available for use.