You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-cvs@xml.apache.org by mk...@apache.org on 2005/06/14 21:17:19 UTC

cvs commit: xml-commons/java/external/src/javax/xml/transform/stream StreamResult.java

mkwan       2005/06/14 12:17:19

  Modified:    java/external/src/javax/xml/transform/stream
                        StreamResult.java
  Log:
  Fix compile time dependency on File.toURI() which is new to JDK 1.4.
  Use reflection instead of a direct method call.
  
  Revision  Changes    Path
  1.6       +11 -10    xml-commons/java/external/src/javax/xml/transform/stream/StreamResult.java
  
  Index: StreamResult.java
  ===================================================================
  RCS file: /home/cvs/xml-commons/java/external/src/javax/xml/transform/stream/StreamResult.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StreamResult.java	8 Apr 2005 10:39:14 -0000	1.5
  +++ StreamResult.java	14 Jun 2005 19:17:19 -0000	1.6
  @@ -18,6 +18,7 @@
   
   package javax.xml.transform.stream;
   
  +import java.lang.reflect.Method;
   import javax.xml.transform.Result;
   
   import java.io.File;
  @@ -161,9 +162,15 @@
       public void setSystemId(File f) {
       	
       	try {
  -    		// assume >= 1.4
  -    		this.systemId = f.toURI().toString();
  -    	} catch (java.lang.NoSuchMethodError nme) {
  +    		// use reflection to call f.toURI().toString().
  +    		// Avoid compile time dependency on J2SE 1.4.
  +    		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?
       		try {
           		this.systemId = f.toURL().toString();
  @@ -174,12 +181,6 @@
       					+ malformedURLException.toString()
       			);
       		}
  -        } catch (Exception exception) {
  -    		throw new RuntimeException(
  -    				"javax.xml.transform.stream.StreamResult#setSystemId(File f):"
  -    				+ " unexpected Exception: " + exception.toString()
  -			);
  -    		
           }
       }