dlr 2004/06/29 23:11:55
Modified: src/java/org/apache/xmlrpc XmlRpc.java
Log:
Work around based on a patch from Ken Huffman for the
SecurityException generated by use in unsigned applets, thrown when
the code attempts to read a System property.
* src/java/org/apache/xmlrpc/XmlRpc.java
version: Added detail about how to implement the associated TODO to
pre-process in the version number. Dropped alpha/beta
qualification of provided version number.
XmlRpc(): Improved JavaDoc. Remodeled the interior to handle the
possible SecurityException which may be thrown when invoked by an
unsigned applet when determining TypeFactory implementation to use
from System property.
XmlRpc(String): Improved JavaDoc. Remodeled interior to use a joist
construction, leveraging the new createTypeFactory(String) method to
replace old debris.
createTypeFactory(String): Merged this overload with the old private
createTypeFactory(Class) version for use by both constructors.
Improved implementation accordingly.
Revision Changes Path
1.37 +55 -31 ws-xmlrpc/src/java/org/apache/xmlrpc/XmlRpc.java
Index: XmlRpc.java
===================================================================
RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/XmlRpc.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -u -r1.36 -r1.37
--- XmlRpc.java 17 Jun 2004 01:40:14 -0000 1.36
+++ XmlRpc.java 30 Jun 2004 06:11:55 -0000 1.37
@@ -89,8 +89,10 @@
/**
* The version string used in HTTP communication.
*/
- // FIXME: Use Ant <filter> to preprocess during compilation
- public static final String version = "Apache XML-RPC 1.2-a3-dev";
+ // FIXME: Use Ant <filter> to pre-process version number into a
+ // class-loaded .properties file at build time. Use here when
+ // available, and otherwise provide no version string.
+ public static final String version = "Apache XML-RPC 2.0";
/**
* The default parser to use (MinML).
@@ -193,66 +195,88 @@
* 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.
+ * the default of [EMAIL PROTECTED] org.apache.xmlrpc.TypeFactory}.
*/
protected XmlRpc()
{
- this(System.getProperty(TypeFactory.class.getName()));
+ String typeFactoryName = null;
+ try
+ {
+ typeFactoryName = System.getProperty(TypeFactory.class.getName());
+ }
+ catch (SecurityException e)
+ {
+ // An unsigned applet may not access system properties.
+ // No-op means we use the default TypeFactory instead.
+ if (debug)
+ {
+ System.out.println("Unable to determine the value of the " +
+ "system property '" +
+ TypeFactory.class.getName() + "': " +
+ e.getMessage());
+ }
+ }
+ this.typeFactory = createTypeFactory(typeFactoryName);
}
/**
* Creates a new instance with the specified [EMAIL PROTECTED]
* org.apache.xmlrpc.TypeFactory}.
*
- * @param typeFactory The implementation to use.
+ * @param typeFactoryName The fully qualified class name of the
+ * [EMAIL PROTECTED] org.apache.xmlrpc.TypeFactory} implementation to use.
+ */
+ protected XmlRpc(String typeFactoryName)
+ {
+ this.typeFactory = createTypeFactory(typeFactoryName);
+ }
+
+ /**
+ * Creates a new instance of the specified [EMAIL PROTECTED]
+ * org.apache.xmlrpc.TypeFactory}.
+ *
+ * @param className The fully qualified class name of the
+ * implementation to use.
+ * @return The new type mapping.
*/
- protected XmlRpc(String typeFactory)
+ private TypeFactory createTypeFactory(String className)
{
Class c = null;
- if (typeFactory != null && typeFactory.length() > 0)
+ if (className != null && className.length() > 0)
{
try
{
- c = Class.forName(typeFactory);
+ c = Class.forName(className);
}
catch (ClassNotFoundException e)
{
- System.err.println("Error loading TypeFactory specified by " +
- "the " + TypeFactory.class.getName() +
- " property, using default instead: " +
+ System.err.println("Error loading TypeFactory '" +
+ "' " + c.getName() +
+ "': Using the default instead: " +
e.getMessage());
}
}
- this.typeFactory = createTypeFactory(c);
- }
- /**
- * Creates a new instance of the specified [EMAIL PROTECTED]
- * 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))
+ // If we're using the default, provide it immediately.
+ if (c == null || DefaultTypeFactory.class.equals(c))
{
return new DefaultTypeFactory();
}
try
{
- return (TypeFactory) typeFactory.newInstance();
+ return (TypeFactory) c.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);
+ c.getName() + "': " + e.getMessage() +
+ ": Falling back to default");
+ if (debug)
+ {
+ e.printStackTrace();
+ }
+ return new DefaultTypeFactory();
}
}