Java Extension

The XWeaver was originally developed as an aspect weaving environment for C/C++ applications. It was recently being extended to operate upon Java applications. This page explains the approach that was taken for the Java extension.

General Approach

XWeaver was originally aimed at C/C++ applications. The link with C/C++ was however indirect because the weaver operates upon an XML-based model of the C/C++ source code generated by the srcML tool (see the discussion of the XWeaver weaving approach). The XML layer somewhat insulates XWeaver from the C/C++ language and paves the way to extensions of the tool to handle other base languages.

Extension to Java is especially attractive because the syntactical similarity of Java and C++ makes it possible to create an XML-model of Java source code that is close to the srcML model of C++. This allows XWeaver to be extended to operate upon Java code with only minimal changes.

The srcML tool generates the model of C/C++ code by parsing the source code and associating an XML element to each C/C++ syntactical element. Since, from a syntactical point of view, Java can be seen as a near-subset of C/C++, it is possible to construct an XML-based model of Java code that uses (nearly) the same DTD as the srcML model of C/C++ code. The DTD defines the grammar of the language that is used to model the base code. The closer the DTD used for C/C++ is to the DTD used for Java, the smaller is the impact on XWeaver of extending it to Java.

The extension of XWeaver to Java was simplified by the availability of a Java extension for the srcML tool tool. The XML-based model of Java source generated by the srcML tool is very close to the srcML model of C/C++ code. Therefore the XWeaver had only to be modified to handle this srcML model for Java.

Before proceeding, it is perhaps useful to mention that there is a natural extension of the approach proposed above. One could regard the srcML model of C/C++ code and the srcML model of Java code as instances of the same meta-model for describing object-oriented base code. If this were possible, then it would also be possible to construct a weaver that operates at this meta-model level and that can be instantiated for each target language (i.e. for each instance of the meta-model). This approach is shown in the next figure. Its practical feasibility depends on the effective possibility of seeing XML-based representations of different base languages as instances of the same meta-model and on the practical feasibility of constructing a weaver that operates at the level of the meta-model and that can be instantiated for different model instances.


Figure 1: MetaWeavingApproach

The XWeaver Extension

The XWeaver tool consists of a compiler, a locator, and a weaver that applies a set of weaving rules (see the description of the XWeaver architecture). The compiler compiles the AspectX program and generates the locator. The locator identifies the locations in the base code where aspect transformations are required. The weaver implements the required transformations by calling upon the weaving rules.

The extension to Java requires some limited extensions of the AspectX language to handle Java-specific constructs. The impact on the compiler is however very limited owing to the similarity of the srcML models of the C/C++ and Java source code.

The extension to Java also requires the addition of new weaving rules to handle the Java-specific weaving problems but the weaver component itself does not need to be modified. This is a consequence of the way XWeaver was designed as an extensible aspect weaving tool that implements self-contained weaving rules. Each weaving rule handles one particular code transformation problem and the weaver is designed to be independent of the weaving rules (it acts as a sort of interpreter for the weaving rules).