FileDocCategorySizeDatePackage
BorlandGenerateClient.javaAPI DocApache Ant 1.7010175Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs.optional.ejb

BorlandGenerateClient

public class BorlandGenerateClient extends org.apache.tools.ant.Task
Generates a Borland Application Server 4.5 client JAR using as input the EJB JAR file. Two mode are available: java mode (default) and fork mode. With the fork mode, it is impossible to add classpath to the command line.
ant.task
name="blgenclient" category="ejb"

Fields Summary
static final String
JAVA_MODE
static final String
FORK_MODE
boolean
debug
debug the generateclient task
File
ejbjarfile
hold the ejbjar file name
File
clientjarfile
hold the client jar file name
org.apache.tools.ant.types.Path
classpath
hold the classpath
String
mode
hold the mode (java|fork)
int
version
hold the version
Constructors Summary
Methods Summary
public org.apache.tools.ant.types.PathcreateClasspath()
Adds path to the classpath.

return
a path to be configured as a nested element.

        if (this.classpath == null) {
            this.classpath = new Path(getProject());
        }
        return this.classpath.createPath();
    
public voidexecute()
Do the work. The work is actually done by creating a separate JVM to run a java task.

exception
BuildException if something goes wrong with the build

        if (ejbjarfile == null || ejbjarfile.isDirectory()) {
            throw new BuildException("invalid ejb jar file.");
        }

        if (clientjarfile == null || clientjarfile.isDirectory()) {
            log("invalid or missing client jar file.", Project.MSG_VERBOSE);
            String ejbjarname = ejbjarfile.getAbsolutePath();
            //clientname = ejbjarfile+client.jar
            String clientname = ejbjarname.substring(0, ejbjarname.lastIndexOf("."));
            clientname = clientname + "client.jar";
            clientjarfile = new File(clientname);
        }

        if (mode == null) {
            log("mode is null default mode  is java");
            setMode(JAVA_MODE);
        }

        if (!(version == BorlandDeploymentTool.BES
            || version == BorlandDeploymentTool.BAS)) {
            throw new BuildException("version " + version
                                      + " is not supported");
        }

        log("client jar file is " + clientjarfile);

        if (mode.equalsIgnoreCase(FORK_MODE)) {
            executeFork();
        } else {
            executeJava();
        } // end of else
    
protected voidexecuteFork()
launch the generate client using system api.

throws
BuildException if there is an error.

        if (version == BorlandDeploymentTool.BAS) {
            executeForkV4();
        }
        if (version == BorlandDeploymentTool.BES) {
            executeForkV5();
        }
    
protected voidexecuteForkV4()
launch the generate client using system api.

throws
BuildException if there is an error.

        try {

            log("mode : fork " + BorlandDeploymentTool.BAS, Project.MSG_DEBUG);

            ExecTask execTask = new ExecTask(this);

            execTask.setDir(new File("."));
            execTask.setExecutable("iastool");
            execTask.createArg().setValue("generateclient");
            if (debug) {
                execTask.createArg().setValue("-trace");
            }

            execTask.createArg().setValue("-short");
            execTask.createArg().setValue("-jarfile");
            // ejb jar file
            execTask.createArg().setValue(ejbjarfile.getAbsolutePath());
            //client jar file
            execTask.createArg().setValue("-single");
            execTask.createArg().setValue("-clientjarfile");
            execTask.createArg().setValue(clientjarfile.getAbsolutePath());

            log("Calling iastool", Project.MSG_VERBOSE);
            execTask.execute();
        } catch (Exception e) {
            // Have to catch this because of the semantics of calling main()
            String msg = "Exception while calling generateclient Details: "
                + e.toString();
            throw new BuildException(msg, e);
        }

    
protected voidexecuteForkV5()
launch the generate client using system api.

throws
BuildException if there is an error.

        try {
            log("mode : fork " + BorlandDeploymentTool.BES, Project.MSG_DEBUG);
            ExecTask execTask = new ExecTask(this);

            execTask.setDir(new File("."));

            execTask.setExecutable("iastool");
            if (debug) {
                execTask.createArg().setValue("-debug");
            }
            execTask.createArg().setValue("-genclient");
            execTask.createArg().setValue("-jars");
            // ejb jar file
            execTask.createArg().setValue(ejbjarfile.getAbsolutePath());
            //client jar file
            execTask.createArg().setValue("-target");
            execTask.createArg().setValue(clientjarfile.getAbsolutePath());
            //classpath
            execTask.createArg().setValue("-cp");
            execTask.createArg().setValue(classpath.toString());
            log("Calling iastool", Project.MSG_VERBOSE);
            execTask.execute();
        } catch (Exception e) {
            // Have to catch this because of the semantics of calling main()
            String msg = "Exception while calling generateclient Details: "
                + e.toString();
            throw new BuildException(msg, e);
        }

    
protected voidexecuteJava()
launch the generate client using java api.

throws
BuildException if there is an error.

        try {
            if (version == BorlandDeploymentTool.BES)  {
                throw new BuildException("java mode is supported only for "
                    + "previous version <=" + BorlandDeploymentTool.BAS);
            }

            log("mode : java");

            Java execTask = null;
            execTask = new Java(this);

            execTask.setDir(new File("."));
            execTask.setClassname("com.inprise.server.commandline.EJBUtilities");
            //classpath
            //add at the end of the classpath
            //the system classpath in order to find the tools.jar file
            execTask.setClasspath(classpath.concatSystemClasspath());

            execTask.setFork(true);
            execTask.createArg().setValue("generateclient");
            if (debug) {
                execTask.createArg().setValue("-trace");
            }

            execTask.createArg().setValue("-short");
            execTask.createArg().setValue("-jarfile");
            // ejb jar file
            execTask.createArg().setValue(ejbjarfile.getAbsolutePath());
            //client jar file
            execTask.createArg().setValue("-single");
            execTask.createArg().setValue("-clientjarfile");
            execTask.createArg().setValue(clientjarfile.getAbsolutePath());

            log("Calling EJBUtilities", Project.MSG_VERBOSE);
            execTask.execute();

        } catch (Exception e) {
            // Have to catch this because of the semantics of calling main()
            String msg = "Exception while calling generateclient Details: " + e.toString();
            throw new BuildException(msg, e);
        }
    
public voidsetClasspath(org.apache.tools.ant.types.Path classpath)
Path to use for classpath.

param
classpath the path to use.

        if (this.classpath == null) {
            this.classpath = classpath;
        } else {
            this.classpath.append(classpath);
        }
    
public voidsetClasspathRef(org.apache.tools.ant.types.Reference r)
Reference to existing path, to use as a classpath.

param
r the reference to use.

        createClasspath().setRefid(r);
    
public voidsetClientjar(java.io.File clientjar)
Client JAR file name.

param
clientjar the file to use.

        clientjarfile = clientjar;
    
public voidsetDebug(boolean debug)
If true, turn on the debug mode for each of the Borland tools launched.

param
debug a boolean value.

        this.debug = debug;
    
public voidsetEjbjar(java.io.File ejbfile)
EJB JAR file.

param
ejbfile the file to use.

        ejbjarfile = ejbfile;
    
public voidsetMode(java.lang.String s)
Command launching mode: java or fork.

param
s the mode to use.

        mode = s;
    
public voidsetVersion(int version)
Set the version attribute.

param
version the value to use.

    // CheckStyle:VisibilityModifier ON

                   
        
        this.version = version;