JEX - Java Extension SourceForge.net Logo

Table of Contents

Announce
Introduction
About
Installation
Examples
Structures
Changes Log
To Do List
Acknowlegments
References

Introduction

Abstract

In simple words, JEX is a redefinition of Java using an XML syntax. This allows programmers to extend their favorite language. It also simplifies compilers, IDEs and code generators.

License Information

The JEX project is available in source code form (.ZIP). JEX packages are made available under the Gnu Public License (GPL).

Download

Latest version is Alpha 2.1, available on SourceForge.net

Programming with JEX

JEX (Java Extension) is a programming language based upon Java with built-in extensibility. With JEX, a project is an XML document describing the various libraries, classes, methods, etc... JEX provides a set of XSLT transformations to generate the Java class files following the JVM specification. A JEX programmer can write JEX projects or work at a higher level and provide a XSLT transformation to translate down to the JEX specification (defined by a XML Schema).

About

Concept

Many years ago, after learning several programming languages, I noticed that too often no matter which language I was using, I was missing some feature found on another language. For example, Java misses the overloading of operators or generics of Ada. It also misses the enumerated types of C/C++ or Ada. Programming with these limitations can be done at the cost of more complex code, harder to read, and write without errors. Imagine going back to an exception-unaware language!
I realized a few years ago that XML could be the solution to making a language extensible at will. For instance, the following piece of Java code:

System.out.println("Hello, World");

				
could be rewritten as:

<invoke>
	<target field-ref="java.lang.System.out"/>
	<method method-ref="println(java.lang.String)"/>
	<literal type-ref="java.lang.String">Hello, World</literal>
</invoke>

				
Of course, this XML code is way too long to enter by hand. But, using modern IDEs capabilities can make it a lot easier. A possible extension to JEX could be in the internationalization area. In this example the definition of a literal could be modified like such:

<literal typeref="java.lang.String" string-ref="hello-world"/>

				
and somewhere in the project, a dictionary of literals would contain:

<local-literal id="hello-world">
	<en>Hello, World</en>
	<fr>Bonjour, le Monde</fr>
</local-literal>

				
The programmer defining the extension, also defines a (XSLT) transformation to get back to the standard specification of JEX.
By applying a series of transformations, a project gets from a high level - with project- or company-specific extensions - down to the standard level defined by JEX. When a programmer is hired, he has to learn the company-defined extensions then, when assigned to a project, he needs to learn the extensions defined for this project.

An Example: Design Patterns

You can check the Visitor pattern provided as an example. Here is a visitor applied to classes A and B:

<visitor id="V" name="V" parent-ref="java.lang.Object" visibility="public">
	<field id="V-out" type-ref="java.io.PrintStream" name="out"/>
	<exception type-ref="java.io.IOException"/>
	<visit-for type-ref="A">
		<invoke-statement function-ref="java.io.PrintStream-println-int-">
			<access field-ref="V-out">
				<visitor-ref/>
			</access>
			<access field-ref="A-a"/>
		</invoke-statement>
	</visit-for>
	<visit-for type-ref="B">
		<invoke-statement function-ref="java.io.PrintStream-println-int-">
			<access field-ref="V-out">
				<visitor-ref/>
			</access>
			<access field-ref="A-a"/>
		</invoke-statement>
		<invoke-statement function-ref="java.io.PrintStream-println-int-">
			<access field-ref="V-out">
				<visitor-ref/>
			</access>
			<access field-ref="B-b"/>
		</invoke-statement>
	</visit-for>
</visitor>

				
The "visitor-for" elements will be used to generate the appropriate method in the visited classes. Here is the generated method for A:

<method type-ref="void" name="visitV" id="visit-V-A">
	<parameter name="visitor" type-ref="V" id="VIS-N1010E-VISITOR"/>
	<exception type-ref="java.io.IOException"/>
	<body>
		<invoke-statement function-ref="java.io.PrintStream-println-int-">
			<access field-ref="V-out">
				<access variable-ref="VIS-N1010E-VISITOR"/>
			</access>
			<access field-ref="A-a"/>
		</invoke-statement>
	</body>
</method>

				
The visitor is invoked by:

<invoke-visitor visitor-ref="V" visit-for="B">
	<access variable-ref="V-main-v"/>
	<allocate type-ref="B"/>
</invoke-visitor>

				
Or, in Java:

v.visitV(new B());

				
This implementation of the Visitor pattern is just an example. Several providers can compete to offer the best implementation. Multiple implementation can also co-exist and be used from the same project.
Note: this example also comes with a simple UML Class Diagram.

Architecture


JVM/CLASS <---> JVM/XML <---> JEX-/XML <--- JEX+/XML <--- [User Defined]
            ^             ^                     ^
            |             |                     |
            |---jvm.xml---|                Java/Eclipse

				

Instructions

- outdated -
Use drag and drop to convert, transform, verify a XML file.
run 'build.bat' to build jvm.xml-dependent dtd entries, and compile the Java classes.

Disassembling and reassembling

You can disassemble an existing Java class file as follows (from the examples directory):
1compile HelloWorld.java
2run 'convert HelloWorld.class'
3run 'transform HelloWorld.jvm'

Compiling a JEX project

To compile a JEX project into Java class files, do the following:
1run 'build HelloWorld.jex'

Installation

Requirements

JEX is being developed with and for a Java 1.4 environment. The batch files (that just launch java classes) are defined for Windows, but easy to translate for Unix/Linux (volunteers raise your hand...).
I use Xerces for XML validation. The default Crimson parser doesn't seem to handle XML validation.
Note:Some batch files expect to find the JDK under /j2sdk1.4.1.

Download

Two packages are made available for download here:
jex-projectSources and documentation
jex-libThe external tools needed to run the JEX environment (Xerces and Xalan)
The libraries should be under <jre>/lib/endorsed

Limitations

At this point, I don't intend to handle older JVM versions. JEX currently produces class files for version 48.0.
Inner classes are not handled just yet.
Plenty more, this is Alpha version.

Examples

HelloWorld

Sources:
Java.zip file containing HelloWorld.java
JEXHelloWorld.jex
The HelloWorld example is more complicated than usual to demonstrate the definition of local variables or fields, and exception handling.

Test

Sources:
Java.zip file containing pak/A.java, pak/B.java and pak/V.java
JEXTest.jex
The Test example demonstrates multiple classes, packages and most importantly the use of a JLE (design patterns in this case).

Eclipse

Sources:
Java.zip file containing Eclipse.java
JEXEclipse.jex
The Eclipse example is used to demonstrate the conversion of an existing Java project into JEX.

Structures

JEX Language Extension

A JEX project is a XML file looking like:

<project
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="jex:ext!/patterns/schema.xsd"
>
	<documentation>
		<uml-diagram height="15cm" width="20cm">
			<uml-title>Class Diagram of Test</uml-title>

			<uml-class id="u-A" type-ref="A" line="1" column="1">
				<uml-field field-ref="A-a"/>
				<uml-method method-ref="A-main"/>
			</uml-class>

			<uml-relation type="generalization">
				<uml-extremity type="start" element-ref="u-A"/>
				<uml-extremity type="end" element-ref="u-B"/>
			</uml-relation>
		</uml-diagram>
	</documentation>
	<code>
		<package id="pak" name="pak">
			<type id="A" parent-ref="java.lang.Object" name="A" visibility="public">
				...
			</type>
			<visitor id="V" name="V" parent-ref="java.lang.Object" visibility="public">
				...
			</visitor>
		</package>
	</code>
	<externals>
		<package id="java" name="java">
			<package id="java.io" name="io">
				...
			</package>
		</package>
	</externals>
	<standard name="Java 1.4">
		<basic-type id="void" name="void" signature="V"/>
		<basic-type id="int" name="int" signature="I">
			<operator id="int-pluseq-int" type-ref="int" name="+=" isAssigning="true" eval="add">
				<parameter type-ref="int"/>
			</operator>
		</basic-type>
	</standard>
</project>

				
The XML Schema definition is located by the xsi:noNamespaceSchemaLocation attribute of the root element. Its value jex:ext!/patterns/schema.xsd refers to the JEX Language extension (JLE) it is based upon. Here the schema is located in /extensions/patterns.
A JLE is composed of the following files:
extension.jleThe high level description of the extension
schema.xsdThe XML Schema associated with the extension
validation.xsltThe XSLT transformation used to verify the compliance of a XML fragment.
transform-*.xsltA set of transformations that can be applied to a JEX project refering to this extension.
In this example, the /extensions/patterns is including extension files from the /extensions/patterns/visitor extension (more to come...).
The standard extensions are defined under /resources/jex:
jex+The high level definition of JEX
jex-The low level definition of JEX (assembly level)
jvmThe redefinition of Java .class files into XML.

Building a JEX project

To build a project from the examples directory, use the following command:

build <jex-file> [-target <target-id>] [-root <root-path>] [-res <res-url>] [-path <path>]
    jex-file:
        a XML file with attribute xsi:noNamespaceSchemaLocation refering to a JLE
    target-id:
        the target to reach (by default, go all the way to .class files)
    root-path:
        the path to JEX root ('..' by default, from the examples directory)
    res-url:
        the url to JEX resource directory ('file:../res' by default, from the examples directory)
    path:
        the transformation path to be followed ('down' by default, to compile)

				
Example:
build Test.jex
Synonym of:
build Test.jex -path down -root .. -res file:../res
In this example the following transformations will be applied successively:
1/extensions/patterns/transform-down.xslt (including /extensions/patterns/visitor/transform-down.xslt)
2/resources/jex/jex+/transform-down.xslt
3/resources/jex/jex-/transform-down.xslt
The result XML document (with schema /resources/jex/jvm/schema.xsd) is then assembled to produce the Java .class file.
Before each transformation, the input XML file is validated against the schema and against the JLE's validation.
You can follow a different generation path, like:
build Test.jex -path doc
to produce a documentation.
Example:
build Test.jex -path uml,down
In this example the following transformations will be applied successively:
1/extensions/patterns/transform-down.xslt (including /extensions/patterns/visitor/transform-down.xslt)
2/resources/jex/jex+/transform-uml.xslt
Generates a UML diagram (as SVG file). Copy the "$JEX_ROOT$/res/jex/jex+/doc" directory into the "examples" directory and rename the Test.jex.out file to Test.svg to view it with Adobe SVG Viewer.

Converting an Eclipse project

To convert an Eclipse (Java) project to JEX, open the contextual menu of the project from the resource perspective. Then select 'Convert to JEX', the JEX project will have the name of the project with the .jex extension, in the project's root directory. You can then build it with: 'build <project-name>.jex'.
Note: it works on the provided Eclipse.zip project. You can try on any (small) project but remember that many features are not defined yet: for instance only a small subset of operators are defined for now.

Changes Log

2003-03-12 - Alpha 2.1

Changes from Alpha 2.0:
1Convertion of existing Eclipse Java projects, now works better (very tricky)

2003-02-05 - Alpha 2.0

Changes from Alpha 1.3:
1Added optional Eclipse support (as plug-in), including convertion of existing Eclipse Java projects
2Corrected the schemas to better support expandability
3Added some rudimentary UML support (use SVG)

2003-01-18 - Alpha 1.3

Changes from Alpha 1.2:
1Fixed URI problems (splitting JLEs and introduction of the jex: protocol)
2Addition of the Visitor design pattern

2003-01-03 - Alpha 1.2

Changes from Alpha 1.1:
1Intoduction of JLE (JEX Language Extensions)
2Reorganized transformation process
3Removed SVG from documentation - too early to use SVG :-(

2003-01-03 - Alpha 1.1

Changes from Alpha 1.0:
1Replaced DTDs with XML Schemas
2Removed dependency to MSXML (for XML validation)
3Reorganized validation/verification process (drop any file to verify on the 'verify' link)
4Improving documentation (use of HTML and SVG)

To Do List

Current version: 2003-03-12 - Alpha 2.1

There is plenty left to do!
Among others things:
1Decompiler (XSLT transformation from JEX- to JEX+) - [Complex]
3Transformation to Java from JEX+ (XSLT transformation) - [Simple]
4Implement inner classes - [Simple]
5Develop the documentation - [Medium]
8Find some kind of Compiler Test Suite Java sources, and transform them to JEX - [Depends]
9Define a navigator/editor using a JSP-based server (to share sources) - [Navigator:Medium, Editor:Complex]
Things on their way:
1Decompiler - started, only the structure is decompiled, the code remains
2Transformation from Java to JEX+ - using Eclipse The Great! Doesn't work yet...
6Add UML diagrams (use of SVG) - class diagrams first, and then...
7Implement some Design Pattern (Singleton and Visitor to start with) - [Medium]
10Integration with Eclipse - just started... so many possibilities
Things done:
7Added the Visitor Design Pattern

Acknowlegments

Apache

This product includes software developed by the Apache Software Foundation (http://www.apache.org/).
xalanxalan.jar and xml-apis.jar from version 2.4.1
xercesxercesImpl.jar from version 2.2.1

Eclipse

This product uses software developed by Eclipse.org (http://eclipse.org/).

References

JEX
Idea
Java
JVM
XML
XSLT
Xerces
Xalan
Eclipse
Various links

Copyright (c) 2002-2003 Patrick Bernard(java2k@sbcglobal.net). All Rights Reserved.

Valid XHTML 1.0!Valid CSS!