You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Elena Litani <el...@ca.ibm.com> on 2002/11/26 21:44:28 UTC

NamespaceContext: removing getParentContext?

Last month I've proposed to modify the XNI NamespaceContext to make it
read/write (see email below).

This week when I started making the changes to Xerces, I've realized
that returning read/write NamespaceContext from the  "getParentContext"
method does not make much sense. Normally, the NamespaceContext is
modified in unidirectional way -- moving from parent to child element
adding namespace declarations. I could not find any use case there we
would need to move back to the parent context and modify it
(adding/removing new declarations).

Thus, I suggest removing the getParentContext() and instead add the
following methods:

a) public Enumeration getAllPrefixes().
This is equivalent to the SAX getPrefixes method [1]. This method is
quite usefull since it allows users to find out all declared prefixes,
including ones declared in the parent context.

b) modify description of getURI() method.
The description in the last proposal stated: "This method looks up the
prefix in the current context."
Update to: "This method looks up the prefix in the current context. If
no mapping is found, this methods will continue lookup in the parent
contexts".

c) Add cloneContext() method.
This will allow users to clone the existing context.

d) Add reset() methods: "Resets an object for re-use".


Any concerns?

[1]
http://www.saxproject.org/apidoc/org/xml/sax/helpers/NamespaceSupport.html#getPrefixes()
-- 
Elena Litani / IBM Toronto

-------- Original Message --------
Subject: XNI: making NamesapaceContext read/write
Date: Thu, 17 Oct 2002 13:45:47 -0400
From: Elena Litani <el...@ca.ibm.com>
Reply-To: xerces-j-dev@xml.apache.org
To: xerces-j-dev@xml.apache.org

The following are the only interfaces in the XNI that are read-only:

* NamespaceContext
* XMLResourceIdentifier
* XMLLocator 

Given that XNI now uses NamespaceContext, instead of
start/endPrefixMapping, some components in the pipeline need to be able
to add namespace declarations. Consider, for example, the following
case:
an XNI application adds components down the pipeline that inserts XML
fragment into the document. In this case, the application most likely
needs to update NamespaceContext for appropriate namespace binding
information in the fragment.

I could imagine that for same reasons you might also want to change
XMLLocator and XMLResourceIdentifier.


Thus, I suggest to make the following changes:

NamespaceContext: add 3 read/write and 1 read/only methods
----------------------------------------------------------
 /**
     * Start a new Namespace context.
     * <p>
     * You should push a new context at the beginning
     * of each XML element: the new context will automatically inherit
     * the declarations of its parent context, but it will also keep
     * track of which declarations were made within this context.
     * <p>
     *
     * @see #popContext
     */
    public void pushContext() {}

   /**
     * Revert to the previous Namespace context.
     * <p>
     * You should pop the context at the end of each
     * XML element.  After popping the context, all Namespace prefix
     * mappings that were previously in force are restored.
     * <p>
     * You must not attempt to declare additional Namespace
     * prefixes after popping a context, unless you push another
     * context first.
     *
     * @see #pushContext
     */
    public void popContext() {
    } // popContext()

    /**
     * Declare a Namespace prefix.
     * <p>
     * This method declares a prefix in the current Namespace
     * context; the prefix will remain in force until this context
     * is popped, unless it is shadowed in a descendant context.
     * <p>
     * Note that to declare a default Namespace, use the empty string.  
     * The prefixes "xml" and "xmlns" can't be rebound.
     * <p>
     * Note that you must <em>not</em> declare a prefix after
     * you've pushed and popped another Namespace.
     *
     * @param prefix The prefix to declare, or null for the empty
     *        string.
     * @param uri The Namespace URI to associate with the prefix.
     *
     * @return true if the prefix was legal, false otherwise
     *
     * @see #getURI
     * @see #getDeclaredPrefixAt
     */
    public boolean declarePrefix(String prefix, String uri) {}
    
     /**
     * Look up a prefix and get the currently-mapped Namespace URI.
     * <p>
     * This method looks up the prefix in the current context.
     * Use the empty string ("") for the default Namespace.
     *
     * @param prefix The prefix to look up.
     *
     * @return The associated Namespace URI, or null if the prefix
     *         is undeclared in this context.
     */
    public String getURI(String prefix);

  

XMLResourceIdentifier: add 4 read/write
---------------------------------------
public void setPublicId(String publicId);
public void setExpandedSystemId(String systemId);  
public void setLiteralSystemId(String systemId); 
public void setBaseSystemId(String systemId); 

XMLLocator
-----------
public void setLineNumber();
public void setColumnNumber();



Comments? Suggestions?

Thank you,
-- 
Elena Litani / IBM Toronto

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org