1 package org.objectweb.celtix.tools.processors.wsdl2.compiler; 2 3 import java.io.OutputStream ; 4 import java.io.PrintWriter ; 5 import java.lang.reflect.Method ; 6 import java.util.logging.Logger ; 7 8 import org.objectweb.celtix.common.i18n.Message; 9 import org.objectweb.celtix.common.logging.LogUtils; 10 import org.objectweb.celtix.tools.common.ToolException; 11 import org.objectweb.celtix.tools.processors.wsdl2.WSDLToProcessor; 12 13 public class Compiler { 14 private static final Logger LOG = LogUtils.getL7dLogger(WSDLToProcessor.class); 15 private OutputStream out; 16 17 public Compiler(OutputStream o) { 18 this.out = o; 19 } 20 21 public boolean internalCompile(String [] args) throws ToolException { 22 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 23 24 Class javacMainClass = null; 25 Class [] compileMethodSignature; 26 compileMethodSignature = new Class [2]; 27 compileMethodSignature[0] = (new String [0]).getClass(); 28 compileMethodSignature[1] = PrintWriter .class; 29 try { 30 javacMainClass = classLoader.loadClass("com.sun.tools.javac.Main"); 31 try { 32 33 Method compileMethod = javacMainClass.getMethod("compile", compileMethodSignature); 34 try { 35 Object result = compileMethod.invoke(null, new Object [] {args, new PrintWriter (out)}); 36 if (!(result instanceof Integer )) { 37 return false; 38 } 39 return ((Integer )result).intValue() == 0; 40 } catch (Exception e1) { 41 Message msg = new Message("FAIL_TO_COMPILE_GENERATE_CODES", LOG); 42 throw new ToolException(msg, e1); 43 } 44 } catch (NoSuchMethodException e2) { 45 throw new ToolException(e2.getMessage(), e2); 46 } 47 } catch (ClassNotFoundException e3) { 48 throw new ToolException(e3.getMessage(), e3); 49 50 } catch (SecurityException e4) { 51 throw new ToolException(e4.getMessage() , e4); 52 } 53 } 54 } 55 | Popular Tags |