aevers 2003/09/12 02:44:07
Modified: src/java/org/apache/xmlrpc XmlWriter.java
Added: src/java/org/apache/xmlrpc TypeDecoder.java
DefaultTypeDecoder.java
Log:
Allow more Java types to be encoded as <i4> and <double>. Default implementation
works as specified. Developers can override the behaviour of the DefaultTypeEncoder
and specify other Java types to be encoded as these tags.
Revision Changes Path
1.9 +13 -2 xml-rpc/src/java/org/apache/xmlrpc/XmlWriter.java
Index: XmlWriter.java
===================================================================
RCS file: /home/cvs/xml-rpc/src/java/org/apache/xmlrpc/XmlWriter.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- XmlWriter.java 1 May 2003 16:53:15 -0000 1.8
+++ XmlWriter.java 12 Sep 2003 09:44:06 -0000 1.9
@@ -104,6 +104,11 @@
protected static final Base64 base64Codec = new Base64();
/**
+ * Class to delegate type decoding to.
+ */
+ protected static TypeDecoder typeDecoder;
+
+ /**
* Mapping between Java encoding names and "real" names used in
* XML prolog.
*/
@@ -113,6 +118,7 @@
{
encodings.put(UTF8, "UTF-8");
encodings.put(ISO8859_1, "ISO-8859-1");
+ typeDecoder = new DefaultTypeDecoder();
}
/**
@@ -177,7 +183,7 @@
{
chardata(obj.toString());
}
- else if (obj instanceof Integer)
+ else if (typeDecoder.isXmlRpcI4(obj))
{
startElement("int");
write(obj.toString());
@@ -189,7 +195,7 @@
write(((Boolean) obj).booleanValue() ? "1" : "0");
endElement("boolean");
}
- else if (obj instanceof Double || obj instanceof Float)
+ else if (typeDecoder.isXmlRpcDouble(obj))
{
startElement("double");
write(obj.toString());
@@ -358,5 +364,10 @@
}
}
}
+ }
+
+ protected static void setTypeDecoder(TypeDecoder newTypeDecoder)
+ {
+ typeDecoder = newTypeDecoder;
}
}
1.1 xml-rpc/src/java/org/apache/xmlrpc/TypeDecoder.java
Index: TypeDecoder.java
===================================================================
package org.apache.xmlrpc;
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "XML-RPC" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/**
* Allows developers to customize the types translated to the XML-RPC
* <i4> and <double> .
*
* @author <a href="mailto:[EMAIL PROTECTED]">Andrew Evers</a>
* @see org.apache.xmlrpc.DefaultTypeDecoder
* @since 1.2
*/
public interface TypeDecoder
{
/**
* Test if a local object translates to an <i4> tag.
*/
public boolean isXmlRpcI4(Object o);
/**
* Test if a local object translates to a <double> tag.
*/
public boolean isXmlRpcDouble(Object o);
}
1.1 xml-rpc/src/java/org/apache/xmlrpc/DefaultTypeDecoder.java
Index: DefaultTypeDecoder.java
===================================================================
package org.apache.xmlrpc;
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "XML-RPC" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/**
* The default implementation of the <code>TypeDecoder</code>
* interface. Provides the following mappings:
*
* <table cellpadding="3" cellspacing="2" border="1" width="100%">
* <tr><th>XML-RPC data type</th> <th>Java class</th></tr>
* <tr><td><i4> or <int></td> <td>java.lang.Integer</td></tr>
* <tr><td><double></td> <td>java.lang.Double,
java.lang.Float</td></tr>
* </table>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Andrew Evers</a>
* @see org.apache.xmlrpc.TypeDecoder
* @since 1.2
*/
public class DefaultTypeDecoder
implements TypeDecoder
{
/**
* Creates a new instance.
*/
public DefaultTypeDecoder()
{
}
public boolean isXmlRpcI4(Object o)
{
return (o instanceof Integer);
}
public boolean isXmlRpcDouble(Object o)
{
return (o instanceof Float || o instanceof Double);
}
}