KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > ant > JbpmSchemaTask


1 package org.jbpm.ant;
2
3 import java.util.StringTokenizer JavaDoc;
4
5 import org.apache.tools.ant.BuildException;
6 import org.apache.tools.ant.Task;
7 import org.hibernate.cfg.Configuration;
8 import org.hibernate.tool.hbm2ddl.SchemaExport;
9 import org.jbpm.db.JbpmSchema;
10
11 public class JbpmSchemaTask extends Task {
12
13   private String JavaDoc cfg = null;
14   private String JavaDoc properties = null;
15
16   private boolean quiet = false;
17   private boolean text = false;
18   private String JavaDoc output = null;
19   private String JavaDoc delimiter = null;
20
21   private String JavaDoc actions = null;
22
23   public void execute() throws BuildException {
24     if (actions==null) throw new RuntimeException JavaDoc("actions is null in jbpmschema task");
25     
26     Configuration configuration = AntTaskJbpmSessionFactory.getConfiguration(cfg, properties);
27     JbpmSchema jbpmSchema = new JbpmSchema(configuration);
28
29     SchemaExport schemaExport = new SchemaExport(configuration);
30     if (output!=null) schemaExport.setOutputFile(output);
31     if (delimiter!=null) schemaExport.setDelimiter(delimiter);
32
33     StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(actions, ",");
34     while (tokenizer.hasMoreTokens()) {
35       String JavaDoc action = tokenizer.nextToken();
36
37       if ("drop".equalsIgnoreCase(action)) {
38         schemaExport.drop(!quiet, !text);
39
40       } else if ("create".equalsIgnoreCase(action)) {
41         schemaExport.create(!quiet, !text);
42         
43       } else if ("clean".equalsIgnoreCase(action)) {
44         jbpmSchema.cleanSchema();
45       }
46     }
47   }
48   
49   public void setActions(String JavaDoc actions) {
50     this.actions = actions;
51   }
52   public void setCfg(String JavaDoc cfg) {
53     this.cfg = cfg;
54   }
55   public void setDelimiter(String JavaDoc delimiter) {
56     this.delimiter = delimiter;
57   }
58   public void setOutput(String JavaDoc output) {
59     this.output = output;
60   }
61   public void setProperties(String JavaDoc properties) {
62     this.properties = properties;
63   }
64   public void setQuiet(boolean quiet) {
65     this.quiet = quiet;
66   }
67   public void setText(boolean text) {
68     this.text = text;
69   }
70 }
71
Popular Tags