axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glen Daniels <g...@thoughtcraft.com>
Subject Re: [Axis2][OM] Simpler way to get NameSpace
Date Mon, 13 Dec 2004 01:46:02 GMT
Wow, lots of namespace mail indeed!

Here's my take on the matter.  First, I really like the way Axis 1.1 
deals with a lot of this stuff, and I would recommend that folks check 
out that code when continuing forward.  The Axis 1.1 util.Mapping object 
is pretty equivalent to OMNamespace, and it doesn't get very exposed to 
users - they can use it, but they aren't forced to.

As a user of OM, I want the ability to:

1) Resolve namespaces from a given OMElement:

   String getPrefixForNamespace(String uri)
   String getNamespaceForPrefix(String prefix)

2) Translate QNames to and from string representations in a given 
context (OMElement):

   QName getQNameFromString(String prefixedName)

This turns names like "foo:bar" into QName{"http://foo", "bar"}, or 
throws a well-defined exception if the prefix isn't mapped.  If there's 
no prefix on the prefixedName, we need to be able to control whether the 
default namespace gets used or not.

   String getPrefixedName(QName qname,
                          boolean autoAdd,
                          boolean useDefault)

The reverse.  If the namespace of the qname is not in scope, and the 
"autoAdd" argument is true, then getPrefixedName() should add a 
namespace declaration to the current OMElement with a random unused 
prefix (we could also have a form with a preferred prefix).  If 
useDefault is true, then we'll use a non-prefixed name if the namespace 
matches the default namespace.

3) Map namespaces at a given OMElement:

   void registerNamespace(String uri, String prefix)

4) Ensure that we have a consistent view on what is a namespace 
declaration and what is an attribute.  For this XML:

   <foo xmlns:ns1="http://ns1" attr1="bar"/>

EITHER:

getAttributes() returns JUST attr1, and getAllAttributes() returns both 
the ns1 declaration and att1

OR:

getAttributes() returns both attributes.

I prefer the former.  In either case I think we should consistency check 
attributes by noticing if they are namespace declarations when they get 
added.  After this:

   OMAttribute attr = new OMAttribute(new QName(XMLNS, "ns1"),
                                      "http://ns1");
   element.addAttribute(attr);

The element should now have a new namespace mapping, and our code should 
complain if the "ns1" prefix is already mapped in this element.

--Glen

Mime
View raw message