FileDocCategorySizeDatePackage
AbstractCompiler.javaAPI DocApache Axis 1.45104Sat Apr 22 18:57:28 BST 2006org.apache.axis.components.compiler

AbstractCompiler

public abstract class AbstractCompiler extends Object implements Compiler
This class implements the functionality common to all Java compilers.
author
Davanum Srinivas
author
Stefano Mazzocchi
since
2.0

Fields Summary
protected ArrayList
fileList
The source program filenames
protected String
srcDir
The name of the directory containing the source program file
protected String
destDir
The name of the directory to contain the resulting object program file
protected String
classpath
The classpath to be used for compilation
protected String
encoding
The encoding of the source program or null to use the platform's default encoding
protected InputStream
errors
The input stream to output compilation errors
Constructors Summary
Methods Summary
public voidaddFile(java.lang.String file)
Add the name of the file containing the source program to the file list

param
file The name of the file containing the source program


                              
      
    this.fileList.add(file);
  
protected java.util.ListfillArguments(java.util.List arguments)
Fill the arguments taken by the Java compiler

param
arguments The list of compilation arguments
return
The prepared list of compilation arguments

    // destination directory
    arguments.add("-d");
    arguments.add(destDir);

    // classpath
    arguments.add("-classpath");
    arguments.add(classpath);

    // sourcepath
    if(srcDir != null) {
        arguments.add("-sourcepath");
        arguments.add(srcDir);
    }

    // add optimization (for what is worth)
    arguments.add("-O");

    // add debug option
    arguments.add("-g");

    // add encoding if set
    if (encoding != null) {
      arguments.add("-encoding");
      arguments.add(encoding);
    }

    return arguments;
  
public java.util.ListgetErrors()
Return the list of errors generated by this compilation

return
The list of errors generated by this compilation
exception
IOException If an error occurs during message collection

    return parseStream(new BufferedReader(new InputStreamReader(errors)));
  
protected abstract java.util.ListparseStream(java.io.BufferedReader errors)
Parse the compiler error stream to produce a list of CompilerErrors

param
errors The error stream
return
The list of compiler error messages
exception
IOException If an error occurs during message collection

public voidsetClasspath(java.lang.String classpath)
Set the classpath to be used for this compilation

param
classpath The classpath to be used for this compilation

    this.classpath = classpath;
  
public voidsetDestination(java.lang.String destDir)
Set the name of the directory to contain the resulting object program file

param
destDir The name of the directory to contain the resulting object program file

      this.destDir = destDir;
  
public voidsetEncoding(java.lang.String encoding)
Set the encoding of the input source file or null to use the platform's default encoding

param
encoding The encoding of the input source file or null to use the platform's default encoding

    this.encoding = encoding;
  
public voidsetSource(java.lang.String srcDir)
Set the name of the directory containing the source program file

param
srcDir The name of the directory containing the source program file

    this.srcDir = srcDir;
  
protected java.lang.String[]toStringArray(java.util.List arguments)
Copy arguments to a string array

param
arguments The compiler arguments
return
A string array containing compilation arguments

    int    i;
    String[] args = new String[arguments.size() + fileList.size()];

    for (i = 0; i < arguments.size(); i++) {
      args[i] = (String) arguments.get(i);
    }

    for (int j=0; j < fileList.size(); i++,j++) {
        args[i] = (String)fileList.get(j);
    }
    return args;