Hi

I have added the following patch at the end of this email. It addresses the following, what I think is an issue.

Consider the following query:

//user[identifier="ZEUS20030108132147141"]

The XMLRPC answer is the following:

<?xml version="1.0" encoding="UTF-8" ?>
- <methodResponse>
- <params>
- <param>
- <value>
- <struct>
- <member>
<name>result</name>
<value><?xml version="1.0"?> <result count="1"><user xmlns:src="http://xml.apache.org/xindice/Query"; src:col="/db/users" src:key="[EMAIL PROTECTED]"> <identifier xmlns:src="http://xml.apache.org/xindice/Query";>ZEUS20030108132147141</identifier> <username xmlns:src="http://xml.apache.org/xindice/Query";>[EMAIL PROTECTED]</username> <password xmlns:src="http://xml.apache.org/xindice/Query";>patches</password> <workspaces xmlns:src="http://xml.apache.org/xindice/Query";> <Name xmlns:src="http://xml.apache.org/xindice/Query";>class scWorkspaces</Name> </workspaces></user></result></value>
</member>
</struct>
</value>
</param>
</params>
</methodResponse>


The problem I see with this result for a query is that you are embedding a document withing a document. This means I have three document processing cycles. The first is to process the XMLRPC message. Then I have to process the result value and see how many elements there. And then I have parse each individual item. The patch will convert the resultset into an array of elements that are returned to the user. This makes processing the resultset simpler since the client only needs to iterate the array.

Comments?


Christian Gross Software Engineering Consultant / Trainer http://www.devspace.com North America: 1-450-675-4208 Europe: +41.1.701.1166


*****************************************
diff -r -u java/src/org/apache/xindice/server/rpc/RPCDefaultMessage.java ../xml-xindice.cvs/java/src/org/apache/xindice/server/rpc/RPCDefaultMessage.java
--- java/src/org/apache/xindice/server/rpc/RPCDefaultMessage.java 2003-01-11 16:47:05.000000000 +0100
+++ ../xml-xindice.cvs/java/src/org/apache/xindice/server/rpc/RPCDefaultMessage.java 2002-12-27 19:37:24.000000000 +0100
@@ -83,7 +83,6 @@
public static final String NAMESPACES = "namespaces";
public static final String CONFIGURATION = "configuration";
public static final String META = "meta";
- public static final String COUNT = "count";


public static final String MISSING_COLLECTION_PARAM = "Required parameter 'collection' not found.";
public static final String MISSING_NAME_PARAM = "Required parameter 'name' not found.";
diff -r -u java/src/org/apache/xindice/server/rpc/messages/Query.java ../xml-xindice.cvs/java/src/org/apache/xindice/server/rpc/messages/Query.java
--- java/src/org/apache/xindice/server/rpc/messages/Query.java 2003-01-11 16:47:13.000000000 +0100
+++ ../xml-xindice.cvs/java/src/org/apache/xindice/server/rpc/messages/Query.java 2002-11-22 11:15:35.000000000 +0100
@@ -71,7 +71,6 @@


 import java.util.Enumeration;
 import java.util.Hashtable;
-import java.util.Vector;

    /**
     * Executes a query against a document or collection
@@ -106,7 +105,7 @@
       }

       Hashtable result = new Hashtable();
-      queryWrapper( result, ns);
+      result.put(RESULT, queryWrapper( ns ));
       return result;
    }

@@ -136,34 +135,35 @@
* Adds additional meta data to the query response and turns it into a
* Document.
*
- * @param result The Hashtable that contains the XMLRPC resultset
* @param ns The NodeSet containing the query results.
* @return the result set as an XML document
* @exception Exception
*/
- private void queryWrapper( Hashtable result, NodeSet ns ) throws Exception {
- Vector resultArray = new Vector();
- int count = 0;
- while( ns != null && ns.hasMoreNodes())
- {
- Node n = ns.getNextNode();
- if( n.getNodeType() == Node.DOCUMENT_NODE)
- {
- n = ((Document)n).getDocumentElement();
- }
-
- if( n instanceof DBNode)
- {
- ((DBNode)n).expandSource();
- }
-
- resultArray.addElement( TextWriter.toString( n));
- count ++;
- }
- result.put( COUNT, Integer.toString( count));
- result.put( RESULT, resultArray);
- }
+ private String queryWrapper( NodeSet ns ) throws Exception {
+ // Turn the NodeSet into a document.
+ DocumentImpl doc = new DocumentImpl();
+
+ Element root = doc.createElement( "result" );
+ doc.appendChild( root );
+ int count = 0;
+ while ( ns != null && ns.hasMoreNodes() ) {
+ Node n = ns.getNextNode();


-}
+         if ( n.getNodeType() == Node.DOCUMENT_NODE ) {
+            n = ( ( Document ) n ).getDocumentElement();
+         }
+
+         if ( n instanceof DBNode ) {
+            ( ( DBNode ) n ).expandSource();
+         }

+         root.appendChild( doc.importNode( n, true ) );
+         count++;
+      }
+
+      root.setAttribute( "count", Integer.toString( count ) );

+      return TextWriter.toString( doc );
+   }
+
+}




Reply via email to