KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > ant > TorqueRepositoryGeneratorTask


1 package org.apache.ojb.broker.ant;
2
3 /* Copyright 2002-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import org.apache.tools.ant.BuildException;
19 import org.apache.tools.ant.Task;
20 import org.apache.tools.ant.types.Path;
21 import org.apache.tools.ant.types.Reference;
22 import org.apache.tools.ant.taskdefs.Java;
23
24 public class TorqueRepositoryGeneratorTask extends Task {
25
26     private String JavaDoc inputFile;
27     private String JavaDoc outputFile;
28     private String JavaDoc database;
29
30     // Optional parameters to the task
31
private Reference classpathRef = null;
32     private Path classpath = null;
33     private String JavaDoc indexTablespace = "";
34     private boolean useNativeIncrement = true;
35
36     public void setInputFile(String JavaDoc inputFile) {
37         this.inputFile = inputFile;
38     }
39
40     public String JavaDoc getInputFile() {
41         return this.inputFile;
42     }
43
44     public void setOutputFile(String JavaDoc outputFile) {
45         this.outputFile = outputFile;
46     }
47
48     public String JavaDoc getOutputFile() {
49         return this.outputFile;
50     }
51
52     public void setDatabase(String JavaDoc database) {
53         this.database = database;
54     }
55
56     public String JavaDoc getDatabase() {
57         return this.database;
58     }
59
60     public void setIndexTablespace(String JavaDoc indexTablespace) {
61         this.indexTablespace = indexTablespace;
62     }
63
64     public String JavaDoc getIndexTablespace() {
65         return this.indexTablespace;
66     }
67
68     public void setUseNativeIncrement(String JavaDoc useNativeIncrement) {
69         if ("yes".equalsIgnoreCase(useNativeIncrement)) {
70             this.useNativeIncrement = true;
71         } else {
72             this.useNativeIncrement = false;
73         }
74     }
75
76     public String JavaDoc getUseNativeIncrement() {
77         if (this.useNativeIncrement) {
78             return "yes";
79         } else {
80             return "no";
81         }
82     }
83
84     public Path getClasspath() {
85         return this.classpath;
86     }
87
88     public void setClasspath(Path path) {
89         this.classpath = path;
90     }
91
92     public Path createClasspath() {
93         if (this.classpath == null) {
94             this.classpath = new Path(getProject());
95         }
96
97         return this.classpath.createPath();
98     }
99
100     public Reference getClasspathRef() {
101         return this.classpathRef;
102     }
103
104     public void setClasspathRef(Reference classpathRef) {
105         this.classpathRef = classpathRef;
106     }
107
108     public void execute() throws BuildException {
109         checkParameters();
110         Java javaTask = (Java)project.createTask("java");
111         javaTask.createArg().setLine(this.inputFile + " " +
112                                      this.outputFile + " " +
113                                      this.database + " " +
114                                      this.indexTablespace + " " +
115                                      this.useNativeIncrement);
116         javaTask.setFork(true);
117         javaTask.setClassname("org.apache.ojb.broker.metadata.torque.TorqueRepositoryGenerator");
118         if (this.classpathRef != null) {
119             javaTask.setClasspathRef(this.classpathRef);
120         }
121         if (this.classpath != null) {
122             javaTask.setClasspath(this.classpath);
123         }
124         javaTask.execute();
125     }
126
127     protected boolean isEmpty(String JavaDoc string) {
128         return (string == null || string.trim().length() == 0);
129     }
130
131     protected void checkParameters() throws BuildException {
132         StringBuffer JavaDoc errorMessageBuffer = new StringBuffer JavaDoc();
133
134         if (isEmpty(this.database)) {
135             errorMessageBuffer.append("Database property not set.\n");
136         }
137
138         if (isEmpty(this.inputFile)) {
139             errorMessageBuffer.append("Input file property not set.\n");
140         }
141
142         if (isEmpty(this.outputFile)) {
143             errorMessageBuffer.append("Output file property not set.\n");
144         }
145
146         if (errorMessageBuffer.toString().length() > 0) {
147             throw new BuildException(errorMessageBuffer.toString());
148         }
149     }
150 }
151
Popular Tags