Fix compile time dependency on File.toURI() which is new to JDK 1.4.

Use reflection instead of a direct method call.


git-svn-id: https://svn.apache.org/repos/asf/xml/commons/trunk@226233 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
mkwan 2005-06-14 19:17:19 +00:00
parent 081cad56b4
commit e58a70e3ee

View File

@ -18,6 +18,7 @@
package javax.xml.transform.stream; package javax.xml.transform.stream;
import java.lang.reflect.Method;
import javax.xml.transform.Result; import javax.xml.transform.Result;
import java.io.File; import java.io.File;
@ -161,9 +162,15 @@ public class StreamResult implements Result {
public void setSystemId(File f) { public void setSystemId(File f) {
try { try {
// assume >= 1.4 // use reflection to call f.toURI().toString().
this.systemId = f.toURI().toString(); // Avoid compile time dependency on J2SE 1.4.
} catch (java.lang.NoSuchMethodError nme) { Method toURIMethod = f.getClass().getMethod("toURI", null);
Object uri = toURIMethod.invoke(f, null);
Method toStringMethod = uri.getClass().getMethod("toString", null);
this.systemId = (String)toStringMethod.invoke(uri, null);
}
catch (Exception exception)
{
// running on J2SE 1.3? // running on J2SE 1.3?
try { try {
this.systemId = f.toURL().toString(); this.systemId = f.toURL().toString();
@ -174,12 +181,6 @@ public class StreamResult implements Result {
+ malformedURLException.toString() + malformedURLException.toString()
); );
} }
} catch (Exception exception) {
throw new RuntimeException(
"javax.xml.transform.stream.StreamResult#setSystemId(File f):"
+ " unexpected Exception: " + exception.toString()
);
} }
} }