[jdom-interest] NamespaceStack and XMLOutputter subclasses

Elliotte Rusty Harold elharo at metalab.unc.edu
Wed Oct 25 12:49:44 PDT 2000


Currently XMLOutputter uses a non-public internal class called
NamespaceStack to keep track of which namespaces have been declared
where. This is fine. However, an instance of this class is passed as an
argument to the protected printElement() method; i.e.:

  protected void printElement(Element element, Writer out, 
   int indentLevel, NamespaceStack namespaces) 
   throws IOException {

However, since NamespaceStack is non-public no other class can override
this method to change the output. I'm thinking about a possible
solution. I'd prefer not to make NamespaceStack public. But maybe we can
make the version of the method that takes the NamespaceStack argument
private like this:

  private void printElement(Element element, Writer out, 
   int indentLevel, NamespaceStack namespaces) 
   throws IOException {

Then we'd add the following protected method that calls the private
method:

  protected void printElement(Element element, Writer out, 
   int indentLevel)  throws IOException {

    NamespaceStack ns = new NamespaceStack()
    // code to add the namespaces from element onto the stack
    printElement(element, out, indentLevel, ns)

  }

What I don't like about this is that it makes it relatively difficult
for subclassers to handle namespaces themselves. Thoughts?

-- 
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+ 
|               Java I/O (O'Reilly & Associates, 1999)               |
|            http://metalab.unc.edu/javafaq/books/javaio/            |
|   http://www.amazon.com/exec/obidos/ISBN=1565924851/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://metalab.unc.edu/javafaq/ | 
|  Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/     |
+----------------------------------+---------------------------------+



More information about the jdom-interest mailing list