You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rpc-dev@xml.apache.org by dl...@apache.org on 2002/09/27 20:37:23 UTC

cvs commit: xml-rpc/src/java/org/apache/xmlrpc XmlRpc.java XmlWriter.java

dlr         2002/09/27 11:37:23

  Modified:    src/java/org/apache/xmlrpc XmlRpc.java XmlWriter.java
  Log:
  Custom integration of Andrew Evers' TypeFactory patches.
  
  Revision  Changes    Path
  1.29      +78 -22    xml-rpc/src/java/org/apache/xmlrpc/XmlRpc.java
  
  Index: XmlRpc.java
  ===================================================================
  RCS file: /home/cvs/xml-rpc/src/java/org/apache/xmlrpc/XmlRpc.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -u -r1.28 -r1.29
  --- XmlRpc.java	15 Aug 2002 18:51:53 -0000	1.28
  +++ XmlRpc.java	27 Sep 2002 18:37:23 -0000	1.29
  @@ -56,7 +56,6 @@
    */
   
   import java.io.InputStream;
  -import java.text.ParseException;
   import java.util.Hashtable;
   import java.util.Stack;
   import java.util.Vector;
  @@ -82,6 +81,7 @@
    *
    * @author <a href="mailto:hannes@apache.org">Hannes Wallnoefer</a>
    * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
  + * @author <a href="mailto:andrew@kungfoocoder.org">Andrew Evers</a>
    * @version $Id$
    */
   public abstract class XmlRpc extends HandlerBase
  @@ -130,12 +130,6 @@
       Value currentValue;
   
       /**
  -     * Thread-safe wrapper for the <code>DateFormat</code> object used
  -     * to parse date/time values.
  -     */
  -    static DateTool dateformat = new DateTool();
  -
  -    /**
        * Used to collect character data (<code>CDATA</code>) of
        * parameter values.
        */
  @@ -191,6 +185,76 @@
        */
       static String encoding = XmlWriter.ISO8859_1;
   
  +    private TypeFactory typeFactory;
  +
  +    /**
  +     * Creates a new instance with the {@link
  +     * org.apache.xmlrpc.TypeFactory} set to an instance of the class
  +     * named by the <code>org.apache.xmlrpc.TypeFactory</code> System
  +     * property.  If property not set or class is unavailable, uses
  +     * the default.
  +     */
  +    protected XmlRpc()
  +    {
  +        this(System.getProperty(TypeFactory.class.getName()));
  +    }
  +
  +    /**
  +     * Creates a new instance with the specified {@link
  +     * org.apache.xmlrpc.TypeFactory}.
  +     *
  +     * @param typeFactory The implementation to use.
  +     */
  +    protected XmlRpc(String typeFactory)
  +    {
  +        Class c = null;
  +        if (typeFactory != null && typeFactory.length() > 0)
  +        {
  +            try
  +            {
  +                c = Class.forName(typeFactory);
  +            }
  +            catch (ClassNotFoundException e)
  +            {
  +                System.err.println("Error loading TypeFactory specified by " +
  +                                   "the " + TypeFactory.class.getName() +
  +                                   " property, using default instead: " +
  +                                   e.getMessage());
  +            }
  +        }
  +        this.typeFactory = createTypeFactory(c);
  +    }
  +
  +    /**
  +     * Creates a new instance of the specified {@link
  +     * org.apache.xmlrpc.TypeFactory}.
  +     *
  +     * @param typeFactory The implementation to use.
  +     * @return The new type mapping.
  +     */
  +    private TypeFactory createTypeFactory(Class typeFactory)
  +    {
  +        // If we're using the default, serve it up immediately.
  +        if (typeFactory == null ||
  +            DefaultTypeFactory.class.equals(typeFactory))
  +        {
  +            return new DefaultTypeFactory();
  +        }
  +
  +        try
  +        {
  +            return (TypeFactory) typeFactory.newInstance();
  +        }
  +        catch (Exception e)
  +        {
  +            System.err.println("Unable to create configured TypeFactory '" +
  +                               typeFactory.getName() + "': " + e.getMessage() +
  +                               ": Using default");
  +            // Call self recursively to acquire default.
  +            return createTypeFactory(null);
  +        }
  +    }
  +
       /**
        * Set the SAX Parser to be used. The argument can either be the
        * full class name or a user friendly shortcut if the parser is
  @@ -603,30 +667,22 @@
               switch (type)
               {
                   case INTEGER:
  -                    value = new Integer(cdata.trim ());
  +                    value = typeFactory.createInteger(cdata);
                       break;
                   case BOOLEAN:
  -                    value = ("1".equals(cdata.trim ())
  -                            ? Boolean.TRUE : Boolean.FALSE);
  +                    value = typeFactory.createBoolean(cdata);
                       break;
                   case DOUBLE:
  -                    value = new Double(cdata.trim ());
  +                    value = typeFactory.createDouble(cdata);
                       break;
                   case DATE:
  -                    try
  -                    {
  -                        value = dateformat.parse(cdata.trim());
  -                    }
  -                    catch (ParseException p)
  -                    {
  -                        throw new RuntimeException(p.getMessage());
  -                    }
  +                    value = typeFactory.createDate(cdata);
                       break;
                   case BASE64:
  -                    value = Base64.decode(cdata.getBytes());
  +                    value = typeFactory.createBase64(cdata);
                       break;
                   case STRING:
  -                    value = cdata;
  +                    value = typeFactory.createString(cdata);
                       break;
                   case STRUCT:
                       // this is the name to use for the next member of this struct
  
  
  
  1.5       +7 -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.4
  retrieving revision 1.5
  diff -u -u -r1.4 -r1.5
  --- XmlWriter.java	20 Aug 2002 16:48:49 -0000	1.4
  +++ XmlWriter.java	27 Sep 2002 18:37:23 -0000	1.5
  @@ -110,6 +110,12 @@
       }
   
       /**
  +     * Thread-safe wrapper for the <code>DateFormat</code> object used
  +     * to parse date/time values.
  +     */
  +    private static DateTool dateTool = new DateTool();
  +
  +    /**
        * Creates a new instance.
        *
        * @param out The stream to write output to.
  @@ -187,8 +193,7 @@
           {
               startElement("dateTime.iso8601");
               Date d = (Date) obj;
  -            // TODO: Stop using package private variable from XmlRpc
  -            write(XmlRpc.dateformat.format(d));
  +            write(dateTool.format(d));
               endElement("dateTime.iso8601");
           }
           else if (obj instanceof byte[])