There is a problem (it seems to me) with the way extensions work in XIFF. The problem is that every extension has to have a different namespace.
I can understand why the combination of namespace and the root element name needs to be unique, but it seems a little silly to have to create a new namespace for every message. Why not use the combination of namespace and element name?
Why is this a problem? In my case, I have wrapped the Room class in my own custom ChatRoom class. When a message arrives in the chat room, I check for any extensions in a particular namespace and if they are found I know the message isn’t a normal chat message, but rather one of my custom message types. In this case, I do not need to dispatch a GROUP_MESSAGE event … instead I generate a custom event, set the data field to the extension class, and dispatch this custom event. The code handling the event can then look at the element name to decide what to do.
I want the ChatRoom class to remain ignorant of what all of the extensions are because I don’t want to have to change the ChatRoom each and every time I create a new extension. I want to be able to check whether the message contains ANY one of my extensions by doing a lookup(mycustomns), but I cannot do that because you must currently register all extensions with a unique namespace … this means ChatRoom has to know every single namespace for each extension and every time I add a new one, I have to change ChatRoom.
I wrote all the code such that all my extensions share the same namespace, but when I started testing I discovered that when you register an extension, the ExtensionClassRegistry stores it only by namespace … so if multiple extensions share a namespace, only the last class actually remains in the registry since each new register() call just overwrites the previous one. In trying to avoid changing ExtensionClassRegistry (which is used in other core code), I followed the pattern I noted in some of the built-in extensions … i.e. add an anchor like #myextension to the namespace. But that puts me in the situation I said I didn’t want … now ChatRoom has to know about every extension in order to check for the presence of them in an incoming message … because it has to call getExtensionsByNS() over and over, once with each of the many namespaces.
My belief that multiple extensions could share the same namespace was reinforced by the fact the getExtensionsByNS() returns an Array.