comparison src/share/tools/IdealGraphVisualizer/BatikSVGProxy/src/com/sun/hotspot/igv/svg/BatikSVG.java @ 18983:43baadc1913a

Automatically install Batik for SVG export in IGV
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 27 Jan 2015 15:47:34 -0800
parents bf4f8817e3bd
children
comparison
equal deleted inserted replaced
18982:479d2d030bf3 18983:43baadc1913a
23 */ 23 */
24 package com.sun.hotspot.igv.svg; 24 package com.sun.hotspot.igv.svg;
25 25
26 import java.awt.Graphics2D; 26 import java.awt.Graphics2D;
27 import java.io.Writer; 27 import java.io.Writer;
28 import java.io.File;
28 import java.lang.reflect.Constructor; 29 import java.lang.reflect.Constructor;
29 import java.lang.reflect.InvocationTargetException; 30 import java.lang.reflect.InvocationTargetException;
30 import java.lang.reflect.Method; 31 import java.lang.reflect.Method;
32 import java.net.MalformedURLException;
33 import java.net.URL;
34 import java.net.URLClassLoader;
31 import org.w3c.dom.DOMImplementation; 35 import org.w3c.dom.DOMImplementation;
32 36
33 /** 37 /**
34 * Utility class 38 * Utility class
35 * @author Thomas Wuerthinger 39 * @author Thomas Wuerthinger
51 * @return the newly created Graphics2D object or null if the library does not exist 55 * @return the newly created Graphics2D object or null if the library does not exist
52 */ 56 */
53 public static Graphics2D createGraphicsObject() { 57 public static Graphics2D createGraphicsObject() {
54 try { 58 try {
55 if (SVGGraphics2DConstructor == null) { 59 if (SVGGraphics2DConstructor == null) {
56 ClassLoader cl = BatikSVG.class.getClassLoader(); 60 String batikJar = System.getenv().get("IGV_BATIK_JAR");
61 if (batikJar == null) {
62 return null;
63 }
64 // Load batik in it's own class loader since some it's support jars interfere with the JDK
65 URL url = new File(batikJar).toURI().toURL();
66 ClassLoader cl = new URLClassLoader(new URL[] { url });
57 Class<?> classGenericDOMImplementation = cl.loadClass("org.apache.batik.dom.GenericDOMImplementation"); 67 Class<?> classGenericDOMImplementation = cl.loadClass("org.apache.batik.dom.GenericDOMImplementation");
58 Class<?> classSVGGeneratorContext = cl.loadClass("org.apache.batik.svggen.SVGGeneratorContext"); 68 Class<?> classSVGGeneratorContext = cl.loadClass("org.apache.batik.svggen.SVGGeneratorContext");
59 classSVGGraphics2D = cl.loadClass("org.apache.batik.svggen.SVGGraphics2D"); 69 classSVGGraphics2D = cl.loadClass("org.apache.batik.svggen.SVGGraphics2D");
60 getDOMImplementationMethod = classGenericDOMImplementation.getDeclaredMethod("getDOMImplementation", new Class[0]); 70 getDOMImplementationMethod = classGenericDOMImplementation.getDeclaredMethod("getDOMImplementation", new Class[0]);
61 createDefaultMethod = classSVGGeneratorContext.getDeclaredMethod("createDefault", new Class[]{org.w3c.dom.Document.class}); 71 createDefaultMethod = classSVGGeneratorContext.getDeclaredMethod("createDefault", new Class[]{org.w3c.dom.Document.class});
77 return null; 87 return null;
78 } catch (InvocationTargetException e) { 88 } catch (InvocationTargetException e) {
79 return null; 89 return null;
80 } catch (InstantiationException e) { 90 } catch (InstantiationException e) {
81 return null; 91 return null;
92 } catch (MalformedURLException e) {
93 return null;
82 } 94 }
83 } 95 }
84 96
85 /** 97 /**
86 * Serializes a graphics object to a stream in SVG format. 98 * Serializes a graphics object to a stream in SVG format.