jochen      2005/05/21 14:23:52

  Modified:    src/java/org/apache/xmlrpc/parser Tag: b20050512_streaming
                        TypeParserImpl.java RecursiveTypeParserImpl.java
               src/test/org/apache/xmlrpc/test Tag: b20050512_streaming
                        BaseTest.java
               src/java/org/apache/xmlrpc/common Tag: b20050512_streaming
                        TypeFactoryImpl.java
  Added:       src/java/org/apache/xmlrpc/parser Tag: b20050512_streaming
                        ExtParser.java NodeParser.java
               src/java/org/apache/xmlrpc/serializer Tag:
                        b20050512_streaming NodeSerializer.java
                        ExtSerializer.java
  Removed:     src/test/org/apache/xmlrpc/test Tag: b20050512_streaming
                        MiniTest.java
  Log:
  Added support for DOM documents.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.2   +1 -1      
ws-xmlrpc/src/java/org/apache/xmlrpc/parser/Attic/TypeParserImpl.java
  
  Index: TypeParserImpl.java
  ===================================================================
  RCS file: 
/home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/parser/Attic/TypeParserImpl.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- TypeParserImpl.java       12 May 2005 01:58:50 -0000      1.1.2.1
  +++ TypeParserImpl.java       21 May 2005 21:23:51 -0000      1.1.2.2
  @@ -64,7 +64,7 @@
        public void startDocument() throws SAXException {
        }
   
  -     protected boolean isEmpty(char[] pChars, int pStart, int pLength) {
  +     protected static boolean isEmpty(char[] pChars, int pStart, int 
pLength) {
                for (int i = 0;  i < pLength;  i++) {
                        if (!Character.isWhitespace(pChars[pStart+i])) {
                                return false;
  
  
  
  1.1.2.3   +0 -1      
ws-xmlrpc/src/java/org/apache/xmlrpc/parser/Attic/RecursiveTypeParserImpl.java
  
  Index: RecursiveTypeParserImpl.java
  ===================================================================
  RCS file: 
/home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/parser/Attic/RecursiveTypeParserImpl.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- RecursiveTypeParserImpl.java      13 May 2005 00:18:21 -0000      1.1.2.2
  +++ RecursiveTypeParserImpl.java      21 May 2005 21:23:51 -0000      1.1.2.3
  @@ -18,7 +18,6 @@
   import javax.xml.namespace.QName;
   
   import org.apache.ws.commons.util.NamespaceContextImpl;
  -import org.apache.xmlrpc.XmlRpcException;
   import org.apache.xmlrpc.common.TypeFactory;
   import org.apache.xmlrpc.common.XmlRpcExtensionException;
   import org.apache.xmlrpc.common.XmlRpcStreamConfig;
  
  
  
  No                   revision
  
  Index: RecursiveTypeParserImpl.java
  ===================================================================
  RCS file: 
/home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/parser/Attic/RecursiveTypeParserImpl.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- RecursiveTypeParserImpl.java      13 May 2005 00:18:21 -0000      1.1.2.2
  +++ RecursiveTypeParserImpl.java      21 May 2005 21:23:51 -0000      1.1.2.3
  @@ -18,7 +18,6 @@
   import javax.xml.namespace.QName;
   
   import org.apache.ws.commons.util.NamespaceContextImpl;
  -import org.apache.xmlrpc.XmlRpcException;
   import org.apache.xmlrpc.common.TypeFactory;
   import org.apache.xmlrpc.common.XmlRpcExtensionException;
   import org.apache.xmlrpc.common.XmlRpcStreamConfig;
  
  
  
  No                   revision
  
  Index: RecursiveTypeParserImpl.java
  ===================================================================
  RCS file: 
/home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/parser/Attic/RecursiveTypeParserImpl.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- RecursiveTypeParserImpl.java      13 May 2005 00:18:21 -0000      1.1.2.2
  +++ RecursiveTypeParserImpl.java      21 May 2005 21:23:51 -0000      1.1.2.3
  @@ -18,7 +18,6 @@
   import javax.xml.namespace.QName;
   
   import org.apache.ws.commons.util.NamespaceContextImpl;
  -import org.apache.xmlrpc.XmlRpcException;
   import org.apache.xmlrpc.common.TypeFactory;
   import org.apache.xmlrpc.common.XmlRpcExtensionException;
   import org.apache.xmlrpc.common.XmlRpcStreamConfig;
  
  
  
  1.1.2.1   +157 -0    
ws-xmlrpc/src/java/org/apache/xmlrpc/parser/Attic/ExtParser.java
  
  
  
  
  1.1.2.1   +49 -0     
ws-xmlrpc/src/java/org/apache/xmlrpc/parser/Attic/NodeParser.java
  
  
  
  
  No                   revision
  No                   revision
  1.1.2.1   +41 -0     
ws-xmlrpc/src/java/org/apache/xmlrpc/serializer/Attic/NodeSerializer.java
  
  
  
  
  1.1.2.1   +43 -0     
ws-xmlrpc/src/java/org/apache/xmlrpc/serializer/Attic/ExtSerializer.java
  
  
  
  
  No                   revision
  No                   revision
  1.1.2.3   +83 -0     
ws-xmlrpc/src/test/org/apache/xmlrpc/test/Attic/BaseTest.java
  
  Index: BaseTest.java
  ===================================================================
  RCS file: 
/home/cvs/ws-xmlrpc/src/test/org/apache/xmlrpc/test/Attic/BaseTest.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- BaseTest.java     21 May 2005 02:37:08 -0000      1.1.2.2
  +++ BaseTest.java     21 May 2005 21:23:51 -0000      1.1.2.3
  @@ -16,6 +16,7 @@
   package org.apache.xmlrpc.test;
   
   import java.io.IOException;
  +import java.io.StringReader;
   import java.text.DecimalFormat;
   import java.text.NumberFormat;
   import java.util.Arrays;
  @@ -23,6 +24,9 @@
   import java.util.Iterator;
   import java.util.Map;
   
  +import javax.xml.namespace.QName;
  +import javax.xml.parsers.DocumentBuilderFactory;
  +
   import org.apache.xmlrpc.XmlRpcException;
   import org.apache.xmlrpc.client.XmlRpcClient;
   import org.apache.xmlrpc.client.XmlRpcClientConfig;
  @@ -30,6 +34,10 @@
   import org.apache.xmlrpc.common.XmlRpcExtensionException;
   import org.apache.xmlrpc.server.PropertyHandlerMapping;
   import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
  +import org.w3c.dom.Document;
  +import org.w3c.dom.Element;
  +import org.w3c.dom.Node;
  +import org.xml.sax.InputSource;
   
   import junit.framework.TestCase;
   
  @@ -215,6 +223,40 @@
                        }
                        return result;
                }
  +             /** Returns the sum of all "int" nodes in <code>pNode</code>.
  +              * @param pNode The node being counted.
  +              * @return The sum of the values of all "int" nodes.
  +              */
  +             public int nodeParam(Node pNode) {
  +                     if (pNode.getNodeType() != Node.DOCUMENT_NODE) {
  +                             throw new IllegalStateException("Expected 
document node, got " + pNode);
  +                     }
  +                     Element e = ((Document) pNode).getDocumentElement();
  +                     if (!ROOT_TAG.equals(e.getLocalName()) || 
!INT_URI.equals(e.getNamespaceURI())) {
  +                             throw new IllegalStateException("Expected root 
element 'root', got "
  +                                                                             
                + new QName(e.getNamespaceURI(), e.getLocalName()));
  +                     }
  +                     return count(pNode);
  +             }
  +             private int count(Node pNode) {
  +                     if (INT_TAG.equals(pNode.getLocalName())  &&  
INT_URI.equals(pNode.getNamespaceURI())) {
  +                             StringBuffer sb = new StringBuffer();
  +                             for (Node child = pNode.getFirstChild();  child 
!= null;  child = child.getNextSibling()) {
  +                                     if (child.getNodeType() == 
Node.TEXT_NODE  ||  child.getNodeType() == Node.CDATA_SECTION_NODE) {
  +                                             sb.append(child.getNodeValue());
  +                                     }
  +                             }
  +                             return Integer.parseInt(sb.toString());
  +                     } else {
  +                             int result = 0;
  +                             for (Node child = pNode.getFirstChild();  child 
!= null;  child = child.getNextSibling()) {
  +                                     if (child.getNodeType() == 
Node.ELEMENT_NODE) {
  +                                             result += count(child);
  +                                     }
  +                             }
  +                             return result;
  +                     }
  +             }
        }
   
        protected XmlRpcHandlerMapping getHandlerMapping() throws IOException, 
XmlRpcException {
  @@ -704,4 +746,45 @@
                result = client.execute(getExConfig(pProvider), methodName, 
params);
                checkMap((Map) result);
        }
  +
  +     /** Test, whether we can invoke a method, passing a DOM
  +      * node as parameter.
  +      * @throws Exception The test failed.
  +      */
  +     public void testNodeParam() throws Exception {
  +             for (int i = 0;  i < providers.length;  i++) {
  +                     testNodeParam(providers[i]);
  +             }
  +     }
  +
  +     private static final String ROOT_TAG = "root";
  +     private static final String INT_TAG = "int";
  +     private static final String INT_URI = 
"http://ws.apache.org/xmlrpc/namespaces/testNodeParam";;
  +
  +     private void testNodeParam(ClientProvider pProvider) throws Exception {
  +             final String xml =
  +                     "<" + ROOT_TAG + " xmlns='" + INT_URI +"'>" +
  +                     "  <" + INT_TAG + ">1</" + INT_TAG + ">" +
  +                     "  <" + INT_TAG + ">2</" + INT_TAG + ">" +
  +                     "  <" + INT_TAG + ">3</" + INT_TAG + ">" +
  +                     "  <" + INT_TAG + ">4</" + INT_TAG + ">" +
  +                     "  <" + INT_TAG + ">5</" + INT_TAG + ">" +
  +                     "</" + ROOT_TAG + ">";
  +             final String methodName = "Remote.nodeParam";
  +             DocumentBuilderFactory dbf = 
DocumentBuilderFactory.newInstance();
  +             dbf.setValidating(false);
  +             dbf.setNamespaceAware(true);
  +             Document doc = dbf.newDocumentBuilder().parse(new 
InputSource(new StringReader(xml)));
  +             final Object[] params = new Object[]{doc};
  +             final XmlRpcClient client = pProvider.getClient();
  +             Object result = client.execute(getExConfig(pProvider), 
methodName, params);
  +             assertEquals(new Integer(1+2+3+4+5), result);
  +             boolean ok = false;
  +             try {
  +                     client.execute(getConfig(pProvider), methodName, 
params);
  +             } catch (XmlRpcExtensionException e) {
  +                     ok = true;
  +             }
  +             assertTrue(ok);
  +     }
   }
  
  
  
  No                   revision
  No                   revision
  1.1.2.4   +12 -0     
ws-xmlrpc/src/java/org/apache/xmlrpc/common/Attic/TypeFactoryImpl.java
  
  Index: TypeFactoryImpl.java
  ===================================================================
  RCS file: 
/home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/common/Attic/TypeFactoryImpl.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- TypeFactoryImpl.java      13 May 2005 21:06:37 -0000      1.1.2.3
  +++ TypeFactoryImpl.java      21 May 2005 21:23:51 -0000      1.1.2.4
  @@ -31,6 +31,7 @@
   import org.apache.xmlrpc.parser.I4Parser;
   import org.apache.xmlrpc.parser.I8Parser;
   import org.apache.xmlrpc.parser.MapParser;
  +import org.apache.xmlrpc.parser.NodeParser;
   import org.apache.xmlrpc.parser.NullParser;
   import org.apache.xmlrpc.parser.ObjectArrayParser;
   import org.apache.xmlrpc.parser.TypeParser;
  @@ -45,11 +46,13 @@
   import org.apache.xmlrpc.serializer.I8Serializer;
   import org.apache.xmlrpc.serializer.ListSerializer;
   import org.apache.xmlrpc.serializer.MapSerializer;
  +import org.apache.xmlrpc.serializer.NodeSerializer;
   import org.apache.xmlrpc.serializer.NullSerializer;
   import org.apache.xmlrpc.serializer.ObjectArraySerializer;
   import org.apache.xmlrpc.serializer.StringSerializer;
   import org.apache.xmlrpc.serializer.TypeSerializer;
   import org.apache.xmlrpc.serializer.XmlRpcWriter;
  +import org.w3c.dom.Node;
   import org.xml.sax.SAXException;
   
   
  @@ -66,6 +69,7 @@
        private static final TypeSerializer SHORT_SERIALIZER = new 
I2Serializer();
        private static final TypeSerializer LONG_SERIALIZER = new 
I8Serializer();
        private static final TypeSerializer FLOAT_SERIALIZER = new 
FloatSerializer();
  +     private static final TypeSerializer NODE_SERIALIZER = new 
NodeSerializer();
   
        private final XmlRpcController controller;
   
  @@ -133,6 +137,12 @@
                        return new ListSerializer(this, pConfig);
                } else if (pObject instanceof Map) {
                        return new MapSerializer(this, pConfig);
  +             } else if (pObject instanceof Node) {
  +                     if (pConfig.isEnabledForExtensions()) {
  +                             return NODE_SERIALIZER;
  +                     } else {
  +                             throw new SAXException(new 
XmlRpcExtensionException("DOM nodes aren't supported, if 
isEnabledForExtensions() == false"));
  +                     }
                } else {
                        throw new SAXException("Unsupported Java type: " + 
pObject.getClass().getName());
                }
  @@ -153,6 +163,8 @@
                                return new I8Parser();
                        } else if 
(FloatSerializer.FLOAT_TAG.equals(pLocalName)) {
                                return new FloatParser();
  +                     } else if (NodeSerializer.DOM_TAG.equals(pLocalName)) {
  +                             return new NodeParser();
                        }
                } else if ("".equals(pURI)) {
                        if (I4Serializer.INT_TAG.equals(pLocalName)  ||  
I4Serializer.I4_TAG.equals(pLocalName)) {
  
  
  

Reply via email to