tangentum technologies    
 

Deutsch

   
   
 
    Writing XJBC

Chapter 3. Writing XJBC

XJBC is an XML-based assembly language. It is optimized for efficient automated processing. Caused by its inheritence from XML, XJBC isn't as easy to read and write by humans as conventional assembler or high-level languages.

But by its nature, XJBC is systematically defined from the ground up. Knowing the system behind it heavily eases reading and writing it. Much of the peculiarities of XJBC are also directly inherited from the format of Java class-files, and can't be factored out.

If you get used to XJBC you may see, that reading and writing it isn't as hard as predicted. Writing transformations of XJBC have to be reliable, and therefore mustn't be complicated at all! As you may see later, XJBC delivers on this promise.

3.1. Defining classes and interfaces

As with Java class-files, a single document of XJBC exactly contains the definition of a single Java class or a single Java interface.

3.1.1. Classes

The base format of a class is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<class type="class-name" package="package-name"
          xmlns="http://www.xjbc.org/JBCSchema020715">

  <!-- class-members are defined here -->

</class>
where "class-name" is the simple name of the class, and "package-name" is the name of the package, i.e. the fully-qualified name of the class would be "package-name.class-name".

As an example take the class org.xjbc.sax.JBCReader. It's definition would be something like

<?xml version="1.0" encoding="UTF-8"?>
<class type="JBCReader" package="org.xjbc.sax"
          xmlns="http://www.xjbc.org/JBCSchema020715">

  <!-- members of the class are defined here -->

</class>

Use of XML namespaces: As of version 0.1, definitions written in XJBC have to be marked with the namespace identified by the URI http://www.xjbc.org/JBCSchema020715. This is done with the attribute

xmlns="http://www.xjbc.org/JBCSchema020715"
as shown in the previous examples.

With this explicit namespace the documents become strongly typed, enabling XJBC documents to co-exist with other kinds of XML documents in the same system without harmful interference. Even new and incompatible versions of XJBC will use different namespace URIs and wouldn't interfere with original XJBC documents also. XJBC is therefore a reliable way to define classes, interfaces, and operations on them, i.e. transformations.

3.1.2. Interfaces

Definitions of interfaces are correspondingly defined, but instead of using the element name "class", the name of the element has to be "interface". For example the definition of the "tagging" interface java.io.Serializable in XJBC is:

<?xml version="1.0" encoding="UTF-8"?>
<interface type="Serializable" package="java.io"
              xmlns="http://www.xjbc.org/JBCSchema020715"/>

3.1.3. Anonymous packages

To define classes or interfaces of anonymous packages, simply give the empty string as the name of the package, as was already shown for "HelloWorld":

<?xml version="1.0" encoding="UTF-8"?>
<class type="HelloWorld" package=""
          xmlns="http://www.xjbc.org/JBCSchema020715">

  <!-- definition of main-method here -->

</class>
To explicitly give an empty "package"-attribute seems to be superflous, but as we will later see in the chapter about types and their definitions, there is a simple system behind it.