You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by Timothy Dean <td...@gr.com> on 2002/01/03 21:00:20 UTC

[PATCH] Lexus namespace mapping enhancements

Index: XUpdateQueryImpl.java
===================================================================
RCS file:
/home/cvs/xmldb/xupdate/src/org/xmldb/xupdate/lexus/XUpdateQueryImpl.java,v
retrieving revision 1.2
diff -u -r1.2 XUpdateQueryImpl.java
--- XUpdateQueryImpl.java	2001/11/29 22:58:01	1.2
+++ XUpdateQueryImpl.java	2002/01/03 21:49:36
@@ -60,6 +60,7 @@
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Vector;
+import java.util.HashMap;
 
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
@@ -104,8 +105,10 @@
     protected NodeFilter _filter = null;
     /* */
     protected Node _namespace = null;
-    
-    
+
+    protected HashMap _namespaces = null;
+
+
     /**
      * 
      */
@@ -129,6 +132,7 @@
             throw new SAXException( e.getMessage( ) );
         }
         
+        _namespaces = xuParser.getNamespaceMappings();
         _query = xuParser.getCachedQuery( );
         if (_query[0].size()==0) {
             throw new SAXException( "query contains no XUpdateOperation !"
);
Index: XUpdateQueryParser.java
===================================================================
RCS file:
/home/cvs/xmldb/xupdate/src/org/xmldb/xupdate/lexus/XUpdateQueryParser.java,v
retrieving revision 1.2
diff -u -r1.2 XUpdateQueryParser.java
--- XUpdateQueryParser.java	2001/11/29 22:58:01	1.2
+++ XUpdateQueryParser.java	2002/01/03 21:49:51
@@ -62,6 +62,7 @@
 
 import java.util.Hashtable;
 import java.util.Vector;
+import java.util.HashMap;
 
 /**
  * This class parses the query-String by a SAXParser. The SAXEvents are 
@@ -78,6 +79,8 @@
     protected Vector _attributes = null;
     /* The list of all characters for each element. */
     protected Vector _characters = null;
+    /* The list of mappings for namespace prefixes */
+    protected HashMap _namespaces = null;
     /* The Integer representation of each XUpdate-command. */
     protected CommandConstants _consts = null;
     /* A flag indicating whether we are within an XUpdateOperation. */
@@ -93,6 +96,7 @@
         _commands = new Vector();
         _attributes = new Vector();
         _characters = new Vector();
+        _namespaces = new HashMap();
     }
     
     
@@ -182,6 +186,12 @@
      *
      */
     public void startPrefixMapping( String prefix, String uri )  {
+        if ((prefix != null) && (prefix.length() > 0)) {
+            _namespaces.put(prefix, uri);
+        }
+        else {
+            _namespaces.put(null, uri);
+        }
     }
     
     
@@ -244,6 +254,10 @@
      */
     public Vector[] getCachedQuery( ) {
         return new Vector[]{ _commands, _attributes, _characters };
+    }
+
+    public HashMap getNamespaceMappings() {
+       return _namespaces;
     }
 }
 

Re: [PATCH] Lexus namespace mapping enhancements

Posted by Kimbro Staken <ks...@dbxmlgroup.com>.
On Tuesday, January 8, 2002, at 10:52 AM, Timothy M. Dean wrote:
>
> No, I did not call setNamespace in the Lexus implementation of the
> XUpdateQuery interface. My reasons for not making this change were:
>
> 1) At the time I was making this change I had not yet figured out where
> the CVS repository for Lexus was, so I was trying to avoid any Lexus
> changes if possible.
>
> 2) The Xindice implementation (in XUpdateImpl.java) completely overrides
> the execute() method defined by the Lexus implementation (in
> XUpdateQueryImpl.java). Any changes I made to the Lexus superclass in
> order to fix the problem would have had to be duplicated in the XIndice
> implementation.
>
> 3) Making the change in Lexus would probably be best if we could
> refactor Xindice's execute() method a little bit - Not being intimately
> familiar with Xindice or Lexus I was a little hesitant to go that far.
>
> Because I didn't call the setNamespace() method, I used an alternate
> approach to pass the namespace into Lexus - My approach was a bit of a
> hack. I used the fact that the Lexus implementation uses a single static
> XPath instance to evaluate its XPath selection. So, I used the static
> CommandObject.getXPath() method to get that XPath instance, and then set
> the namespace directly on the XPath instance.
>
> Looking back at it now, there are probably a couple of things that be
> refactored a bit to allow my changes to be rolled more directly into
> Lexus rather than doing it completely within Xindice. It would be
> necessary to modify Xindice's implementation of the execute() method so
> that it delegates most of the work back to the Lexus implementation (in
> it's superclass). It looks like the only Xindice-specific needs are to
> do some special checks for "Compressed Nodes" after the query has been
> executed. If we could change the implementation to call super.execute()
> and then do its compressed node checks, then we could move the namespace
> logic into the Lexus superclass, and remove the slight hack I used to
> pass namespace nodes directly to the XPath instance.
>
> If you and the Xindice guys (Kimbro and Tom, I presume) would like me to
> make these further changes, please let me know and I will give it a
> whirl.
>

If you can refactor the code to use more of Lexus without losing anything 
then please do.

BTW, if you're really interested in digging into this we can probably look 
at getting you commit.

> - Tim
>
>
>
Kimbro Staken
XML Database Software, Consulting and Writing
http://www.xmldatabases.org/


RE: [PATCH] Lexus namespace mapping enhancements

Posted by "Timothy M. Dean" <td...@visi.com>.

> -----Original Message-----
> From: Lars Martin [mailto:Lars.Martin@smb-tec.com] 
> On Mon, 7 Jan 2002 09:56:10 -0600
> "Timothy M. Dean" <td...@visi.com> wrote:
> 
> > Lars, I will try to summarize as quickly as possible:
> > 
> > 1) There was no mechanism to specify namespaces programatically for 
> > XUpdate commands. This functionality was defined for XPath 
> queries but 
> > not for XUpdate. While it wasn't absolutely needed in XUpdate, it 
> > seemed like a good thing from a consistency standpoint. The 
> changes to 
> > support this were completely within Xindice and needed no Lexus 
> > updates.
> 
> Ok. Great. But why no changes in Lexus? Are you calling the 
> setNamespace() method in XUpdateQuery.java interface? Or how 
> to you pass this parameter to Lexus?
> 

No, I did not call setNamespace in the Lexus implementation of the
XUpdateQuery interface. My reasons for not making this change were:

1) At the time I was making this change I had not yet figured out where
the CVS repository for Lexus was, so I was trying to avoid any Lexus
changes if possible.

2) The Xindice implementation (in XUpdateImpl.java) completely overrides
the execute() method defined by the Lexus implementation (in
XUpdateQueryImpl.java). Any changes I made to the Lexus superclass in
order to fix the problem would have had to be duplicated in the XIndice
implementation.

3) Making the change in Lexus would probably be best if we could
refactor Xindice's execute() method a little bit - Not being intimately
familiar with Xindice or Lexus I was a little hesitant to go that far.

Because I didn't call the setNamespace() method, I used an alternate
approach to pass the namespace into Lexus - My approach was a bit of a
hack. I used the fact that the Lexus implementation uses a single static
XPath instance to evaluate its XPath selection. So, I used the static
CommandObject.getXPath() method to get that XPath instance, and then set
the namespace directly on the XPath instance.

Looking back at it now, there are probably a couple of things that be
refactored a bit to allow my changes to be rolled more directly into
Lexus rather than doing it completely within Xindice. It would be
necessary to modify Xindice's implementation of the execute() method so
that it delegates most of the work back to the Lexus implementation (in
it's superclass). It looks like the only Xindice-specific needs are to
do some special checks for "Compressed Nodes" after the query has been
executed. If we could change the implementation to call super.execute()
and then do its compressed node checks, then we could move the namespace
logic into the Lexus superclass, and remove the slight hack I used to
pass namespace nodes directly to the XPath instance.

If you and the Xindice guys (Kimbro and Tom, I presume) would like me to
make these further changes, please let me know and I will give it a
whirl.

- Tim


Re: [PATCH] Lexus namespace mapping enhancements

Posted by Lars Martin <La...@smb-tec.com>.
On Mon, 7 Jan 2002 09:56:10 -0600
"Timothy M. Dean" <td...@visi.com> wrote:

> Lars, I will try to summarize as quickly as possible:
> 
> 1) There was no mechanism to specify namespaces programatically for
> XUpdate commands. This functionality was defined for XPath queries but
> not for XUpdate. While it wasn't absolutely needed in XUpdate, it seemed
> like a good thing from a consistency standpoint. The changes to support
> this were completely within Xindice and needed no Lexus updates.

Ok. Great. But why no changes in Lexus? Are you calling the setNamespace()
method in XUpdateQuery.java interface? Or how to you pass this parameter
to Lexus?

> 2) When trying to specify namespaces directly in the XUpdate command,
> the Xindice implementation was using the namespace mappings in the
> target XML documents instead of those within the XUpdate "modifications"
> XML element. This seemed to be incorrect behavior because the one who is
> querying a document shouldn't care what NS prefixes were used when
> storing the document. When querying a document it seemed that only the
> URI's of the document should matter, and that the querying app should be
> able to use whichever NS prefixes it chooses (or even a default NS) to
> make sure it queries with the correct NS URI's. The changes to support
> this were mostly within Xindice, but it was necessary to patch Lexus so
> that NS assignments within the XUpdate query were stored for future
> retrieval by Xindice.

Cool. I already stumbled across this problem when using namespaces in
my XUpdate documents. I always had to use the same namespace prefix but
I wasn't aware of this problem. Really great! Good job!

Kindest regards, Lars.
--
______________________________________________________________________
Lars Martin                             mailto:Lars.Martin@smb-tec.com
SMB GmbH                                        http://www.smb-tec.com


RE: [PATCH] Lexus namespace mapping enhancements

Posted by "Timothy M. Dean" <td...@visi.com>.
Lars, I will try to summarize as quickly as possible:

1) There was no mechanism to specify namespaces programatically for
XUpdate commands. This functionality was defined for XPath queries but
not for XUpdate. While it wasn't absolutely needed in XUpdate, it seemed
like a good thing from a consistency standpoint. The changes to support
this were completely within Xindice and needed no Lexus updates.

2) When trying to specify namespaces directly in the XUpdate command,
the Xindice implementation was using the namespace mappings in the
target XML documents instead of those within the XUpdate "modifications"
XML element. This seemed to be incorrect behavior because the one who is
querying a document shouldn't care what NS prefixes were used when
storing the document. When querying a document it seemed that only the
URI's of the document should matter, and that the querying app should be
able to use whichever NS prefixes it chooses (or even a default NS) to
make sure it queries with the correct NS URI's. The changes to support
this were mostly within Xindice, but it was necessary to patch Lexus so
that NS assignments within the XUpdate query were stored for future
retrieval by Xindice.

Let me know if there are more specific questions.

- Tim


> -----Original Message-----
> From: Lars Martin [mailto:Lars.Martin@smb-tec.com] 
> Sent: Monday, January 07, 2002 3:33 AM
> To: xindice-dev@xml.apache.org
> Cc: xupdate-dev@xmldb.org
> Subject: Re: [PATCH] Lexus namespace mapping enhancements
> 
> 
> 
> Hi Tim,
> 
> I don't have the time to follow this discussion that is 
> already going for a long period. But can you give me a short 
> answer or description what exactly is the problem with 
> namespaces in XUpdate/Lexus/XIndice?!
> 
> I'll try to apply your patch asap.
> 
> Many thanks for your work.
> 
> Regards, Lars.
> 
> 
> 
> On Thu, 3 Jan 2002 14:00:20 -0600
> "Timothy Dean" <td...@gr.com> wrote:
> 
> > Index: XUpdateQueryImpl.java 
> > ===================================================================
> > RCS file: 
> > 
> /home/cvs/xmldb/xupdate/src/org/xmldb/xupdate/lexus/XUpdateQueryImpl.j
> > ava,v
> > retrieving revision 1.2
> > diff -u -r1.2 XUpdateQueryImpl.java
> > --- XUpdateQueryImpl.java	2001/11/29 22:58:01	1.2
> > +++ XUpdateQueryImpl.java	2002/01/03 21:49:36
> > @@ -60,6 +60,7 @@
> >  import java.util.Enumeration;
> >  import java.util.Hashtable;
> >  import java.util.Vector;
> > +import java.util.HashMap;
> >  
> >  import javax.xml.parsers.SAXParser;
> >  import javax.xml.parsers.SAXParserFactory;
> > @@ -104,8 +105,10 @@
> >      protected NodeFilter _filter = null;
> >      /* */
> >      protected Node _namespace = null;
> > -    
> > -    
> > +
> > +    protected HashMap _namespaces = null;
> > +
> > +
> >      /**
> >       * 
> >       */
> > @@ -129,6 +132,7 @@
> >              throw new SAXException( e.getMessage( ) );
> >          }
> >          
> > +        _namespaces = xuParser.getNamespaceMappings();
> >          _query = xuParser.getCachedQuery( );
> >          if (_query[0].size()==0) {
> >              throw new SAXException( "query contains no 
> > XUpdateOperation !" );
> > Index: XUpdateQueryParser.java 
> > ===================================================================
> > RCS file: 
> > 
> /home/cvs/xmldb/xupdate/src/org/xmldb/xupdate/lexus/XUpdateQueryParser
> > .java,v
> > retrieving revision 1.2
> > diff -u -r1.2 XUpdateQueryParser.java
> > --- XUpdateQueryParser.java	2001/11/29 22:58:01	1.2
> > +++ XUpdateQueryParser.java	2002/01/03 21:49:51
> > @@ -62,6 +62,7 @@
> >  
> >  import java.util.Hashtable;
> >  import java.util.Vector;
> > +import java.util.HashMap;
> >  
> >  /**
> >   * This class parses the query-String by a SAXParser. The 
> SAXEvents 
> > are
> > @@ -78,6 +79,8 @@
> >      protected Vector _attributes = null;
> >      /* The list of all characters for each element. */
> >      protected Vector _characters = null;
> > +    /* The list of mappings for namespace prefixes */
> > +    protected HashMap _namespaces = null;
> >      /* The Integer representation of each XUpdate-command. */
> >      protected CommandConstants _consts = null;
> >      /* A flag indicating whether we are within an 
> XUpdateOperation. 
> > */ @@ -93,6 +96,7 @@
> >          _commands = new Vector();
> >          _attributes = new Vector();
> >          _characters = new Vector();
> > +        _namespaces = new HashMap();
> >      }
> >      
> >      
> > @@ -182,6 +186,12 @@
> >       *
> >       */
> >      public void startPrefixMapping( String prefix, String uri )  {
> > +        if ((prefix != null) && (prefix.length() > 0)) {
> > +            _namespaces.put(prefix, uri);
> > +        }
> > +        else {
> > +            _namespaces.put(null, uri);
> > +        }
> >      }
> >      
> >      
> > @@ -244,6 +254,10 @@
> >       */
> >      public Vector[] getCachedQuery( ) {
> >          return new Vector[]{ _commands, _attributes, _characters };
> > +    }
> > +
> > +    public HashMap getNamespaceMappings() {
> > +       return _namespaces;
> >      }
> >  }
> >  
> 
> 
> -- 
> ______________________________________________________________________
> Lars Martin                             mailto:Lars.Martin@smb-tec.com
> SMB GmbH                                        http://www.smb-tec.com
> 
> 


Re: [PATCH] Lexus namespace mapping enhancements

Posted by Lars Martin <La...@smb-tec.com>.
Hi Tim,

I don't have the time to follow this discussion that is already going
for a long period. But can you give me a short answer or description
what exactly is the problem with namespaces in XUpdate/Lexus/XIndice?!

I'll try to apply your patch asap.

Many thanks for your work.

Regards, Lars.



On Thu, 3 Jan 2002 14:00:20 -0600
"Timothy Dean" <td...@gr.com> wrote:

> Index: XUpdateQueryImpl.java
> ===================================================================
> RCS file:
> /home/cvs/xmldb/xupdate/src/org/xmldb/xupdate/lexus/XUpdateQueryImpl.java,v
> retrieving revision 1.2
> diff -u -r1.2 XUpdateQueryImpl.java
> --- XUpdateQueryImpl.java	2001/11/29 22:58:01	1.2
> +++ XUpdateQueryImpl.java	2002/01/03 21:49:36
> @@ -60,6 +60,7 @@
>  import java.util.Enumeration;
>  import java.util.Hashtable;
>  import java.util.Vector;
> +import java.util.HashMap;
>  
>  import javax.xml.parsers.SAXParser;
>  import javax.xml.parsers.SAXParserFactory;
> @@ -104,8 +105,10 @@
>      protected NodeFilter _filter = null;
>      /* */
>      protected Node _namespace = null;
> -    
> -    
> +
> +    protected HashMap _namespaces = null;
> +
> +
>      /**
>       * 
>       */
> @@ -129,6 +132,7 @@
>              throw new SAXException( e.getMessage( ) );
>          }
>          
> +        _namespaces = xuParser.getNamespaceMappings();
>          _query = xuParser.getCachedQuery( );
>          if (_query[0].size()==0) {
>              throw new SAXException( "query contains no XUpdateOperation !"
> );
> Index: XUpdateQueryParser.java
> ===================================================================
> RCS file:
> /home/cvs/xmldb/xupdate/src/org/xmldb/xupdate/lexus/XUpdateQueryParser.java,v
> retrieving revision 1.2
> diff -u -r1.2 XUpdateQueryParser.java
> --- XUpdateQueryParser.java	2001/11/29 22:58:01	1.2
> +++ XUpdateQueryParser.java	2002/01/03 21:49:51
> @@ -62,6 +62,7 @@
>  
>  import java.util.Hashtable;
>  import java.util.Vector;
> +import java.util.HashMap;
>  
>  /**
>   * This class parses the query-String by a SAXParser. The SAXEvents are 
> @@ -78,6 +79,8 @@
>      protected Vector _attributes = null;
>      /* The list of all characters for each element. */
>      protected Vector _characters = null;
> +    /* The list of mappings for namespace prefixes */
> +    protected HashMap _namespaces = null;
>      /* The Integer representation of each XUpdate-command. */
>      protected CommandConstants _consts = null;
>      /* A flag indicating whether we are within an XUpdateOperation. */
> @@ -93,6 +96,7 @@
>          _commands = new Vector();
>          _attributes = new Vector();
>          _characters = new Vector();
> +        _namespaces = new HashMap();
>      }
>      
>      
> @@ -182,6 +186,12 @@
>       *
>       */
>      public void startPrefixMapping( String prefix, String uri )  {
> +        if ((prefix != null) && (prefix.length() > 0)) {
> +            _namespaces.put(prefix, uri);
> +        }
> +        else {
> +            _namespaces.put(null, uri);
> +        }
>      }
>      
>      
> @@ -244,6 +254,10 @@
>       */
>      public Vector[] getCachedQuery( ) {
>          return new Vector[]{ _commands, _attributes, _characters };
> +    }
> +
> +    public HashMap getNamespaceMappings() {
> +       return _namespaces;
>      }
>  }
>  


--
______________________________________________________________________
Lars Martin                             mailto:Lars.Martin@smb-tec.com
SMB GmbH                                        http://www.smb-tec.com