01: package org.objectweb.celtix.tools.processors.wsdl2.compiler;
02:
03: import java.io.OutputStream;
04: import java.io.PrintWriter;
05: import java.lang.reflect.Method;
06: import java.util.logging.Logger;
07:
08: import org.objectweb.celtix.common.i18n.Message;
09: 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
15: .getL7dLogger(WSDLToProcessor.class);
16: private OutputStream out;
17:
18: public Compiler(OutputStream o) {
19: this .out = o;
20: }
21:
22: public boolean internalCompile(String[] args) throws ToolException {
23: ClassLoader classLoader = Thread.currentThread()
24: .getContextClassLoader();
25:
26: Class javacMainClass = null;
27: Class[] compileMethodSignature;
28: compileMethodSignature = new Class[2];
29: compileMethodSignature[0] = (new String[0]).getClass();
30: compileMethodSignature[1] = PrintWriter.class;
31: try {
32: javacMainClass = classLoader
33: .loadClass("com.sun.tools.javac.Main");
34: try {
35:
36: Method compileMethod = javacMainClass.getMethod(
37: "compile", compileMethodSignature);
38: try {
39: Object result = compileMethod
40: .invoke(null, new Object[] { args,
41: new PrintWriter(out) });
42: if (!(result instanceof Integer)) {
43: return false;
44: }
45: return ((Integer) result).intValue() == 0;
46: } catch (Exception e1) {
47: Message msg = new Message(
48: "FAIL_TO_COMPILE_GENERATE_CODES", LOG);
49: throw new ToolException(msg, e1);
50: }
51: } catch (NoSuchMethodException e2) {
52: throw new ToolException(e2.getMessage(), e2);
53: }
54: } catch (ClassNotFoundException e3) {
55: throw new ToolException(e3.getMessage(), e3);
56:
57: } catch (SecurityException e4) {
58: throw new ToolException(e4.getMessage(), e4);
59: }
60: }
61: }
|