[JDEV] <x/> namespace registration

Eric Bowersox ebowersox at corp.webb.net
Tue Jan 18 13:29:13 CST 2000


> Are we going to do any namespace registration for the x tag?  
> I'm trying
> to figure out the direction for providing access to <x/> tags in
> Net::Jabber and realized that a module for each namespace would be the
> nicest, but then we would have little rampant modules running around.
> 
> Are we going to police this namespace in anyway?  If we don't then the
> probability of a Client getting confused by an <x xmlns="x:bob"/> that
> it supports and an <x xmlns="x:bob"/> that it doesn't support is high.

My guess is, the namespaces for <x> tags should probably follow a convention
similar to Java package names.  For instance, we would be able to use an
extension tag something like:

	<x xmlns="net:webb:cwxml:whatever">
	  <!-- some Webb-specific data here -->
	</x>

This would be what we might use for some sort of CommunityWare/XML data that
piggybacks onto Jabber messages.  You, on the other hand, could define the
following:

	<x xmlns="com:ti:what:ever">
	  <!-- some TI-specific data here -->
	</x>

And that would be data specific to your organization.  The advantage to this
system is the same as the Java package system: the DNS and trademark laws
serve to separate your stuff from somebody else's stuff, so it's pretty much
self-policing.  (There's other syntaxes for XML namespaces that might also
be used instead.)  Naturally, just as Sun reserves "java.*" package names,
we reserve "jabber:*" namespace names...

As for implementation, for the Webb Jabber Java Extensible Client Interface
(aka the "java-webb" module in CVS), I defined extensions as being a special
type of packet.  You can create a new packet class that represents a
specific extension type, and register it (or, actually, its "creator" class)
with the JabberConnection object.  Then, when a MessagePacket comes in, you
can examine each of its extensions (with the getExtension(int) or
getExtensions() methods) and see if any of them is an instance of your
extension class:

	Enumeration enum = message_packet.getExtensions();
	while (enum.hasMoreElements())
	{ // look for extensions we're interested in
	  Packet ext = (Packet)(enum.nextElement());
	  if (ext instanceof SomeCommunityWareXMLExtension)
	  { // do something appropriate
	  } // end if

	} // end while

Unknown extension types are always turned into RawPackets, which let you
peek at their XML structure through the getTreeRoot() method.

					Eric




More information about the JDev mailing list