|
|||
![]() |
|||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||
|
Chapter 3. Writing XJBCXJBC 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 interfacesAs 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. ClassesThe 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>
3.1.2. InterfacesDefinitions 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 packagesTo 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. |
||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||
|
©2003, tangentum.com
All rights reserved.
|
|||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||