1
2
3
4 package net.sf.tomp.xtcl;
5
6 import java.util.StringTokenizer;
7
8 /***
9 * @author tomp
10 */
11 public class CompilerFactory {
12 public static void createDefaultCompilers(Context context)
13 throws InstantiationException, IllegalAccessException,
14 ClassNotFoundException {
15 String compClassNames = System.getProperty("net.sf.tomp.xtcl.Compiler",
16 "net.sf.tomp.xtcl.XTCompiler");
17 StringTokenizer st = new StringTokenizer(compClassNames, " :;,\t\n\r\f");
18
19 while (st.hasMoreTokens()) {
20 createCompiler(st.nextToken(), context);
21 }
22 }
23
24 public static Compiler createCompiler(String compClassName, Context context)
25 throws InstantiationException, IllegalAccessException,
26 ClassNotFoundException {
27 Class compClass = Class.forName(compClassName);
28
29 return createCompiler(compClass, context);
30 }
31
32 public static Compiler createCompiler(Class compClass, Context context)
33 throws InstantiationException, IllegalAccessException,
34 ClassNotFoundException {
35 Object compObj = compClass.newInstance();
36
37 if (compObj instanceof Compiler) {
38 Compiler compiler = (Compiler) compObj;
39
40 context.addCompiler(compiler);
41
42 return compiler;
43 } else {
44 throw new IllegalArgumentException("Not a Compiler class: "
45 + compClass.getName());
46 }
47 }
48
49 public static void cloneCompilers(Context srcContext, Context targetContext)
50 throws InstantiationException, IllegalAccessException,
51 ClassNotFoundException {
52 int compCount = srcContext.getCompilerCount();
53
54 for (int i = 0; i < compCount; i++) {
55 Class compClass = srcContext.getCompiler(i).getClass();
56
57 createCompiler(compClass, targetContext);
58 }
59 }
60 }