radioAe6rt

JXTA Advertisement code generator

leave a comment »

JXTA relies heavily on the concept of advertisements, which are XML documents that describe what you have to offer the network or what you seek to acquire from it. A typical JXTA app will have a number of advertisement types, and each needs to be marshalled to/from XML via code you must supply.

Here is a utility and work-in-progress to create that Java marshalling code based on a declarative XML description of what the advertisement looks like.

To compile (under JSE 5)

javac AdvMill.java

To run

java AdvMill infile

The utility generates from the XML input both the abstract Advertisement Java code and the implementation Advertisement Java code.

A shortcoming of the utility is that it is not smart enough to know how to deal with non-String type properties of the advertisement. So, for example, if an advertisement has a member whose natural type is CodatID, the utility doesn’t know enough to use the IDFactory to take the String representation and produce the native CodatID type. That may be the subject of future work, but for now, the utility does nicely bootstrap creating advertisement code, and in some sense formalizes the description in a bit of XML. Meaning that if you have non-String types in your definition, the impl Adv code will not compile without tweaking.

At some point you not only want to compile the generated code, but also to look at it. Given the tedious nature of outputting the generated code, indenting in the utility quickly became more trouble that it was worth. I found myself running the generated code through astyle for formatting purposes.

Update: The AdvMill.java utility code has been contributed to the JXTA Commons Project.

[tags]jxta,p2p[/tags]

Written by radioae6rt

April 1, 2006 at 2:33 pm

Posted in Internet

Leave a Reply