How to use the XML support with JADE

Author: Filippo Quarta(Telecom Italia Lab)

Date: March 10, 2003

Java platform: Sun JDK 1.2 Windows

JADE version 3.0

Java API for XML Processing (e.g. http://java.sun.com/xml/jaxp/index.html)

This tutorial describes how to install and use the XML support with JADE; the XML support permits to use a concrete syntax, for ACLmessage content, based on XML/XML Schema. The XMLCodec.java class implements the Codec interface of JADE (jade.content.lang.Codec) and allows converting back and forth between arrays of byte in XML format and AbsContentElement (abstract descriptor of the message content). Since XMLCodec package uses the package jade.content and its sub-packages, it requires JADE 3.0.

Installation.

In order to install XML support the following steps must be performed:

Compiling

The default JADE Makefile rules don't take the XMLCodec into account. For handling the compilation process of the XMLCodec you have to use the 'build.xml' ant-file located in the XMLCodec directory. The following rules are available:

Configuration and Usage

The current configuration uses Xerces as the default SAX parser. So if you don't want to make any changes you just have to download Xerces from the link provided above and make sure it is added to the classpath when starting (either by including it into the $CLASSPATH environment variable - %CLASSPATH% under windows or by specifing it on the command line).

Here is an example of how you would start the platform to use the xml content language support:

java -classpath ./lib/jade.jar:./lib/iiop.jar:./add-ons/XMLCodec/lib/XMLCodec.jar jade.Boot ( for Unix )
or
java -classpath .\lib\jade.jar;.\lib\iiop.jar;.\add-ons\XMLCodec\lib\XMLCodec.jar jade.Boot ( for Windows )

If you want to use another xml parser you have to specify in the command line the system property org.xml.sax.parser.

When an agent wants to send an XML encoded message, it must register the language with the registerLanguage() method of the ContentManager class. For example (assuming manager is the ContentManager):

manager.registerLanguage(new XMLCodec());

Moreover it is recommended to set the language of the message. For example (assuming ACLmsg is the ACL message):

  

ACLmsg.setLanguage(XMLCodec.NAME);

   

Using XMLCodec, the messages are arrays of byte in XML format; the tags used are those defined in the subsequent XML schema.

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:complexType name="Content" abstract="true">
</xsd:complexType>

<xsd:complexType name="Predicate" abstract="true">
<xsd:complexContent>
<xsd:extension base="Content">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="Action" abstract="true">
<xsd:complexContent>
<xsd:extension base="Content">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="Concept" abstract="true">
<xsd:complexContent>
<xsd:extension base="Content">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:element name="CONTENT_ELEMENT" type="Content"/>
</xsd:schema>

Examples

After setting properly the CLASSPATH, execute the following command to start Sender and Receiver agents:

java jade.Boot receiver:examples.xmlcontent.Receiver sender:examples.xmlcontent.Sender

To see the messages XML format, execute the following command:

java jade.Boot –gui

after, utilize the gui to run receiver and sender agents; utilize the sniffer agent to see the messages.


JADE is a trademark of CSELT. JADE has been developed jointly by CSELT and the Computer Engineering Group of the University of Parma