View Javadoc

1   /*
2    * Created on 9.7.2004, changed 27.7.2004
3    */
4   package net.sf.tomp.xml.include.xtcl;
5   
6   import net.sf.tomp.xml.type.xtcl.TypeDatabaseFilterCommand;
7   import net.sf.tomp.xml.type.xtcl.TypeDetectorFilterCommand;
8   import net.sf.tomp.xtcl.Command;
9   import net.sf.tomp.xtcl.CommandLineReader;
10  import net.sf.tomp.xtcl.CompilerBase;
11  
12  import java.util.StringTokenizer;
13  
14  /***
15   * @author tomp
16   */
17  public class XTCompiler extends CompilerBase {
18      public Command compile(String[] cl, CommandLineReader clr) throws Exception {
19          Command commandToReturn = null;
20  
21          if (cl.length == 0) {
22              return null;
23          }
24  
25          int i = 0;
26          String ci = cl[i++];
27  
28          // ADAPTIVEXINCLUDER $varname $typedatabasevarname [param1=val1...]
29          if (ci.equalsIgnoreCase("ADAPTIVEXINCLUDER")) {
30              AdaptiveXIncluderCommand command = new AdaptiveXIncluderCommand();
31  
32              command.setVar(cl[i++]);
33              command.setTypeDatabaseVar(cl[i++]);
34  
35              //System.out.println(command);
36              while (i < cl.length) {
37                  String param = cl[i++];
38                  StringTokenizer pst = new StringTokenizer(param, "=");
39                  String name = pst.nextToken();
40                  Object value = pst.nextToken();
41  
42                  command.setParameter(name, value);
43              }
44  
45              commandToReturn = command;
46  
47              // ADAPTIVEFILTER $varname $typedatabasevarname [param1=val1 ...]
48          } else if (ci.equalsIgnoreCase("ADAPTIVEFILTER")) {
49              AdaptiveFilterCommand command = new AdaptiveFilterCommand();
50  
51              command.setVar(cl[i++]);
52              command.setTypeDatabaseVar(cl[i++]);
53  
54              //System.out.println(command);
55              while (i < cl.length) {
56                  String param = cl[i++];
57                  StringTokenizer pst = new StringTokenizer(param, "=");
58                  String name = pst.nextToken();
59                  Object value = pst.nextToken();
60  
61                  command.setParameter(name, value);
62              }
63  
64              commandToReturn = command;
65  
66              // TYPEDETECTORFILTER $varname $typedbvarname [param1=val1 ...]
67          } else if (ci.equalsIgnoreCase("TYPEDETECTORFILTER")) {
68              TypeDetectorFilterCommand command = new TypeDetectorFilterCommand();
69  
70              command.setVar(cl[i++]);
71              command.setTypeDatabaseVar(cl[i++]);
72  
73              //System.out.println(command);
74              while (i < cl.length) {
75                  String param = cl[i++];
76                  StringTokenizer pst = new StringTokenizer(param, "=");
77                  String name = pst.nextToken();
78                  Object value = pst.nextToken();
79  
80                  command.setParameter(name, value);
81              }
82  
83              commandToReturn = command;
84  
85              // TYPEDATABASEFILTER $varname
86          } else if (ci.equalsIgnoreCase("TYPEDATABASEFILTER")) {
87              TypeDatabaseFilterCommand command = new TypeDatabaseFilterCommand();
88  
89              if (i < cl.length) {
90                  command.setVar(cl[i++]);
91              }
92  
93              //System.out.println(command);
94              commandToReturn = command;
95          } else {
96              return compileByNextCompiler(ci, cl, clr);
97          }
98  
99          assertWholeLineRead(ci, i, cl, commandToReturn);
100 
101         //System.out.println("Compiled command="+commandToReturn);
102         return commandToReturn;
103     }
104 }