1 18 package org.apache.tools.ant.taskdefs.optional.jsp.compilers; 19 20 import org.apache.tools.ant.AntClassLoader; 21 import org.apache.tools.ant.BuildException; 22 import org.apache.tools.ant.Task; 23 import org.apache.tools.ant.taskdefs.optional.jsp.JspNameMangler; 24 import org.apache.tools.ant.taskdefs.optional.jsp.Jasper41Mangler; 25 26 27 31 public final class JspCompilerAdapterFactory { 32 33 34 private JspCompilerAdapterFactory() { 35 } 36 37 54 public static JspCompilerAdapter getCompiler(String compilerType, Task task) 55 throws BuildException { 56 return getCompiler(compilerType, task, 57 task.getProject().createClassLoader(null)); 58 } 59 60 78 public static JspCompilerAdapter getCompiler(String compilerType, Task task, 79 AntClassLoader loader) 80 throws BuildException { 81 82 if (compilerType.equalsIgnoreCase("jasper")) { 83 return new JasperC(new JspNameMangler()); 85 } 86 if (compilerType.equalsIgnoreCase("jasper41")) { 87 return new JasperC(new Jasper41Mangler()); 89 } 90 return resolveClassName(compilerType, loader); 91 } 92 93 102 private static JspCompilerAdapter resolveClassName(String className, 103 AntClassLoader classloader) 104 throws BuildException { 105 try { 106 Class c = classloader.findClass(className); 107 Object o = c.newInstance(); 108 return (JspCompilerAdapter) o; 109 } catch (ClassNotFoundException cnfe) { 110 throw new BuildException(className + " can\'t be found.", cnfe); 111 } catch (ClassCastException cce) { 112 throw new BuildException(className + " isn\'t the classname of " 113 + "a compiler adapter.", cce); 114 } catch (Throwable t) { 115 throw new BuildException(className + " caused an interesting " 117 + "exception.", t); 118 } 119 } 120 121 } 122 | Popular Tags |