1 | |
package org.apache.ojb.broker.ant; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
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 inputFile; |
27 | |
private String outputFile; |
28 | |
private String database; |
29 | |
|
30 | |
|
31 | |
private Reference classpathRef = null; |
32 | |
private Path classpath = null; |
33 | |
private String indexTablespace = ""; |
34 | |
private boolean useNativeIncrement = true; |
35 | |
|
36 | |
public void setInputFile(String inputFile) { |
37 | |
this.inputFile = inputFile; |
38 | |
} |
39 | |
|
40 | |
public String getInputFile() { |
41 | |
return this.inputFile; |
42 | |
} |
43 | |
|
44 | |
public void setOutputFile(String outputFile) { |
45 | |
this.outputFile = outputFile; |
46 | |
} |
47 | |
|
48 | |
public String getOutputFile() { |
49 | |
return this.outputFile; |
50 | |
} |
51 | |
|
52 | |
public void setDatabase(String database) { |
53 | |
this.database = database; |
54 | |
} |
55 | |
|
56 | |
public String getDatabase() { |
57 | |
return this.database; |
58 | |
} |
59 | |
|
60 | |
public void setIndexTablespace(String indexTablespace) { |
61 | |
this.indexTablespace = indexTablespace; |
62 | |
} |
63 | |
|
64 | |
public String getIndexTablespace() { |
65 | |
return this.indexTablespace; |
66 | |
} |
67 | |
|
68 | |
public void setUseNativeIncrement(String useNativeIncrement) { |
69 | |
if ("yes".equalsIgnoreCase(useNativeIncrement)) { |
70 | |
this.useNativeIncrement = true; |
71 | |
} else { |
72 | |
this.useNativeIncrement = false; |
73 | |
} |
74 | |
} |
75 | |
|
76 | |
public String 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 string) { |
128 | |
return (string == null || string.trim().length() == 0); |
129 | |
} |
130 | |
|
131 | |
protected void checkParameters() throws BuildException { |
132 | |
StringBuffer errorMessageBuffer = new StringBuffer(); |
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 | |
} |