KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > tools > processors > wsdl2 > compiler > Compiler


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