1 18 19 20 package org.apache.tools.ant.taskdefs.optional.ejb; 21 22 import java.io.File ; 23 import org.apache.tools.ant.BuildException; 24 import org.apache.tools.ant.Project; 25 import org.apache.tools.ant.Task; 26 import org.apache.tools.ant.taskdefs.ExecTask; 27 import org.apache.tools.ant.taskdefs.Java; 28 import org.apache.tools.ant.types.Path; 29 import org.apache.tools.ant.types.Reference; 30 31 40 public class BorlandGenerateClient extends Task { 41 static final String JAVA_MODE = "java"; 42 static final String FORK_MODE = "fork"; 43 44 46 boolean debug = false; 47 48 49 File ejbjarfile = null; 50 51 52 File clientjarfile = null; 53 54 55 Path classpath; 56 57 58 String mode = FORK_MODE; 59 60 61 int version = BorlandDeploymentTool.BAS; 62 64 68 public void setVersion(int version) { 69 this.version = version; 70 } 71 72 76 public void setMode(String s) { 77 mode = s; 78 } 79 80 84 public void setDebug(boolean debug) { 85 this.debug = debug; 86 } 87 88 92 public void setEjbjar(File ejbfile) { 93 ejbjarfile = ejbfile; 94 } 95 96 100 public void setClientjar(File clientjar) { 101 clientjarfile = clientjar; 102 } 103 104 108 public void setClasspath(Path classpath) { 109 if (this.classpath == null) { 110 this.classpath = classpath; 111 } else { 112 this.classpath.append(classpath); 113 } 114 } 115 116 120 public Path createClasspath() { 121 if (this.classpath == null) { 122 this.classpath = new Path(getProject()); 123 } 124 return this.classpath.createPath(); 125 } 126 127 131 public void setClasspathRef(Reference r) { 132 createClasspath().setRefid(r); 133 } 134 135 136 143 public void execute() throws BuildException { 144 if (ejbjarfile == null || ejbjarfile.isDirectory()) { 145 throw new BuildException("invalid ejb jar file."); 146 } 147 148 if (clientjarfile == null || clientjarfile.isDirectory()) { 149 log("invalid or missing client jar file.", Project.MSG_VERBOSE); 150 String ejbjarname = ejbjarfile.getAbsolutePath(); 151 String clientname = ejbjarname.substring(0, ejbjarname.lastIndexOf(".")); 153 clientname = clientname + "client.jar"; 154 clientjarfile = new File (clientname); 155 } 156 157 if (mode == null) { 158 log("mode is null default mode is java"); 159 setMode(JAVA_MODE); 160 } 161 162 if (!(version == BorlandDeploymentTool.BES 163 || version == BorlandDeploymentTool.BAS)) { 164 throw new BuildException("version " + version 165 + " is not supported"); 166 } 167 168 log("client jar file is " + clientjarfile); 169 170 if (mode.equalsIgnoreCase(FORK_MODE)) { 171 executeFork(); 172 } else { 173 executeJava(); 174 } } 176 177 181 protected void executeJava() throws BuildException { 182 try { 183 if (version == BorlandDeploymentTool.BES) { 184 throw new BuildException("java mode is supported only for " 185 + "previous version <=" + BorlandDeploymentTool.BAS); 186 } 187 188 log("mode : java"); 189 190 Java execTask = null; 191 execTask = new Java(this); 192 193 execTask.setDir(new File (".")); 194 execTask.setClassname("com.inprise.server.commandline.EJBUtilities"); 195 execTask.setClasspath(classpath.concatSystemClasspath()); 199 200 execTask.setFork(true); 201 execTask.createArg().setValue("generateclient"); 202 if (debug) { 203 execTask.createArg().setValue("-trace"); 204 } 205 206 execTask.createArg().setValue("-short"); 207 execTask.createArg().setValue("-jarfile"); 208 execTask.createArg().setValue(ejbjarfile.getAbsolutePath()); 210 execTask.createArg().setValue("-single"); 212 execTask.createArg().setValue("-clientjarfile"); 213 execTask.createArg().setValue(clientjarfile.getAbsolutePath()); 214 215 log("Calling EJBUtilities", Project.MSG_VERBOSE); 216 execTask.execute(); 217 218 } catch (Exception e) { 219 String msg = "Exception while calling generateclient Details: " + e.toString(); 221 throw new BuildException(msg, e); 222 } 223 } 224 225 229 protected void executeFork() throws BuildException { 230 if (version == BorlandDeploymentTool.BAS) { 231 executeForkV4(); 232 } 233 if (version == BorlandDeploymentTool.BES) { 234 executeForkV5(); 235 } 236 } 237 238 242 protected void executeForkV4() throws BuildException { 243 try { 244 245 log("mode : fork " + BorlandDeploymentTool.BAS, Project.MSG_DEBUG); 246 247 ExecTask execTask = new ExecTask(this); 248 249 execTask.setDir(new File (".")); 250 execTask.setExecutable("iastool"); 251 execTask.createArg().setValue("generateclient"); 252 if (debug) { 253 execTask.createArg().setValue("-trace"); 254 } 255 256 execTask.createArg().setValue("-short"); 257 execTask.createArg().setValue("-jarfile"); 258 execTask.createArg().setValue(ejbjarfile.getAbsolutePath()); 260 execTask.createArg().setValue("-single"); 262 execTask.createArg().setValue("-clientjarfile"); 263 execTask.createArg().setValue(clientjarfile.getAbsolutePath()); 264 265 log("Calling iastool", Project.MSG_VERBOSE); 266 execTask.execute(); 267 } catch (Exception e) { 268 String msg = "Exception while calling generateclient Details: " 270 + e.toString(); 271 throw new BuildException(msg, e); 272 } 273 274 } 275 276 280 protected void executeForkV5() throws BuildException { 281 try { 282 log("mode : fork " + BorlandDeploymentTool.BES, Project.MSG_DEBUG); 283 ExecTask execTask = new ExecTask(this); 284 285 execTask.setDir(new File (".")); 286 287 execTask.setExecutable("iastool"); 288 if (debug) { 289 execTask.createArg().setValue("-debug"); 290 } 291 execTask.createArg().setValue("-genclient"); 292 execTask.createArg().setValue("-jars"); 293 execTask.createArg().setValue(ejbjarfile.getAbsolutePath()); 295 execTask.createArg().setValue("-target"); 297 execTask.createArg().setValue(clientjarfile.getAbsolutePath()); 298 execTask.createArg().setValue("-cp"); 300 execTask.createArg().setValue(classpath.toString()); 301 log("Calling iastool", Project.MSG_VERBOSE); 302 execTask.execute(); 303 } catch (Exception e) { 304 String msg = "Exception while calling generateclient Details: " 306 + e.toString(); 307 throw new BuildException(msg, e); 308 } 309 310 } 311 312 } 313 | Popular Tags |