1 19 20 package org.netbeans.modules.java.source.engine; 21 22 import java.io.File ; 23 import java.io.FileNotFoundException ; 24 import java.io.IOException ; 25 import java.lang.reflect.Constructor ; 26 import org.openide.modules.InstalledFileLocator; 27 28 32 public final class EngineFactory { 33 38 public static JackpotEngine createEngine(ApplicationContext appContext) throws Exception { 39 String jarPath = jackpotJarsPath(); 40 ClassLoader loader = new ClassLoader (EngineFactory.class.getClassLoader()) { 42 protected Class <?> findClass(String name) throws ClassNotFoundException { 43 return super.findClass(name); 44 } 45 }; 46 Class c = Class.forName("org.netbeans.modules.java.source.builder.Engine", true, loader); Constructor con = c.getConstructor(ApplicationContext.class, String .class); 48 con.setAccessible(true); 49 return (JackpotEngine)con.newInstance(appContext, jarPath); 50 } 51 52 private static String jackpotJarsPath() throws IOException { 53 InstalledFileLocator locator = InstalledFileLocator.getDefault(); 54 File jar = locator.locate("modules/org-netbeans-modules-java-source.jar", "org.netbeans.modules.java.source", false); if (jar == null) 57 return(""); StringBuffer sb = new StringBuffer (); 59 sb.append(jar.getCanonicalPath()); 60 sb.append(File.pathSeparator); 61 jar = locator.locate("modules/ext/javac-api.jar", "org.netbeans.libs.javacapi", false); if (jar == null) 64 throw new FileNotFoundException ("modules/ext/javac-api.jar"); 65 sb.append(jar.getCanonicalPath()); 66 sb.append(File.pathSeparator); 67 jar = locator.locate("modules/ext/javac-impl.jar", "org.netbeans.libs.javacimpl", false); if (jar == null) 70 throw new FileNotFoundException ("modules/ext/javac-impl.jar"); 71 sb.append(jar.getCanonicalPath()); 72 return sb.toString(); 73 } 74 } 75 | Popular Tags |