FileDocCategorySizeDatePackage
JspCompilerAdapterFactory.javaAPI DocApache Ant 1.704818Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs.optional.jsp.compilers

JspCompilerAdapterFactory

public final class JspCompilerAdapterFactory extends Object
Creates the necessary compiler adapter, given basic criteria.

Fields Summary
Constructors Summary
private JspCompilerAdapterFactory()
This is a singleton -- can't create instances!!

    
Methods Summary
public static JspCompilerAdaptergetCompiler(java.lang.String compilerType, org.apache.tools.ant.Task task)
Based on the parameter passed in, this method creates the necessary factory desired. The current mapping for compiler names are as follows:
  • jasper = jasper compiler (the default)
  • a fully quallified classname = the name of a jsp compiler adapter

param
compilerType either the name of the desired compiler, or the full classname of the compiler's adapter.
param
task a task to log through.
return
the compiler
throws
BuildException if the compiler type could not be resolved into a compiler adapter.

        return getCompiler(compilerType, task,
                           task.getProject().createClassLoader(null));
    
public static JspCompilerAdaptergetCompiler(java.lang.String compilerType, org.apache.tools.ant.Task task, org.apache.tools.ant.AntClassLoader loader)
Based on the parameter passed in, this method creates the necessary factory desired. The current mapping for compiler names are as follows:
  • jasper = jasper compiler (the default)
  • a fully quallified classname = the name of a jsp compiler adapter

param
compilerType either the name of the desired compiler, or the full classname of the compiler's adapter.
param
task a task to log through.
param
loader AntClassLoader with which the compiler should be loaded
return
the compiler
throws
BuildException if the compiler type could not be resolved into a compiler adapter.


        if (compilerType.equalsIgnoreCase("jasper")) {
            //tomcat4.0 gets the old mangler
            return new JasperC(new JspNameMangler());
        }
        if (compilerType.equalsIgnoreCase("jasper41")) {
            //tomcat4.1 gets the new one
            return new JasperC(new Jasper41Mangler());
        }
        return resolveClassName(compilerType, loader);
    
private static JspCompilerAdapterresolveClassName(java.lang.String className, org.apache.tools.ant.AntClassLoader classloader)
Tries to resolve the given classname into a compiler adapter. Throws a fit if it can't.

param
className The fully qualified classname to be created.
param
classloader Classloader with which to load the class
throws
BuildException This is the fit that is thrown if className isn't an instance of JspCompilerAdapter.

        try {
            Class c = classloader.findClass(className);
            Object o = c.newInstance();
            return (JspCompilerAdapter) o;
        } catch (ClassNotFoundException cnfe) {
            throw new BuildException(className + " can\'t be found.", cnfe);
        } catch (ClassCastException cce) {
            throw new BuildException(className + " isn\'t the classname of "
                                     + "a compiler adapter.", cce);
        } catch (Throwable t) {
            // for all other possibilities
            throw new BuildException(className + " caused an interesting "
                                     + "exception.", t);
        }