kinman 2003/04/03 14:22:12 Modified: jasper2/src/share/org/apache/jasper/compiler ELFunctionMapper.java jasper2/src/share/org/apache/jasper/runtime ProtectedFunctionMapper.java Log: - Optimization: If the function mapper has only one function, there's no need to create the HashMap for it, and the resolveFunction can just return the Method for it. Revision Changes Path 1.9 +12 -2 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ELFunctionMapper.java Index: ELFunctionMapper.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ELFunctionMapper.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- ELFunctionMapper.java 1 Apr 2003 00:20:01 -0000 1.8 +++ ELFunctionMapper.java 3 Apr 2003 22:22:12 -0000 1.9 @@ -200,13 +200,23 @@ // Generate declaration for the map statically decName = getMapName(); ss.append("static private org.apache.jasper.runtime.ProtectedFunctionMapper " + decName + ";\n"); - ds.append(" " + decName + " = org.apache.jasper.runtime.ProtectedFunctionMapper.getInstance();\n"); + + ds.append(" " + decName + "= "); + ds.append("org.apache.jasper.runtime.ProtectedFunctionMapper"); + // Special case if there is only one function in the map + String funcMethod = null; + if (functions.size() == 1) { + funcMethod = ".getMapForFunction"; + } else { + ds.append(".getInstance();\n"); + funcMethod = " " + decName + ".mapFunction"; + } for (int i = 0; i < functions.size(); i++) { ELNode.Function f = (ELNode.Function)functions.get(i); FunctionInfo funcInfo = f.getFunctionInfo(); String key = f.getPrefix()+ ":" + f.getName(); - ds.append(" " + decName + ".mapFunction(\"" + key + "\", " + + ds.append(funcMethod + "(\"" + key + "\", " + funcInfo.getFunctionClass() + ".class, " + '\"' + f.getMethodName() + "\", " + "new Class[] {"); 1.6 +72 -8 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/ProtectedFunctionMapper.java Index: ProtectedFunctionMapper.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/ProtectedFunctionMapper.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ProtectedFunctionMapper.java 26 Feb 2003 00:11:39 -0000 1.5 +++ ProtectedFunctionMapper.java 3 Apr 2003 22:22:12 -0000 1.6 @@ -80,9 +80,14 @@ public final class ProtectedFunctionMapper implements FunctionMapper { /** - * Maps "prefix:name" to java.lang.Method objects. Lazily created. + * Maps "prefix:name" to java.lang.Method objects. */ - private HashMap fnmap = new java.util.HashMap(); + private HashMap fnmap = null; + + /** + * If there is only one function in the map, this is the Method for it. + */ + private Method theMethod = null; /** * Constructor has protected access. @@ -99,16 +104,19 @@ * @return A new protected function mapper. */ public static ProtectedFunctionMapper getInstance() { + ProtectedFunctionMapper funcMapper; if (System.getSecurityManager() != null) { - return (ProtectedFunctionMapper)AccessController.doPrivileged( + funcMapper = (ProtectedFunctionMapper)AccessController.doPrivileged( new PrivilegedAction() { public Object run() { return new ProtectedFunctionMapper(); } } ); } else { - return new ProtectedFunctionMapper(); + funcMapper = new ProtectedFunctionMapper(); } + funcMapper.fnmap = new java.util.HashMap(); + return funcMapper; } /** @@ -153,6 +161,59 @@ } /** + * Creates an instance for this class, and stores the Method for + * the given EL function prefix and name. This method is used for + * the case when there is only one function in the EL expression. + * + * @param fnQName The EL function qualified name (including prefix) + * @param c The class containing the Java method + * @param methodName The name of the Java method + * @param args The arguments of the Java method + * @throws RuntimeException if no method with the given signature + * could be found. + */ + public static ProtectedFunctionMapper getMapForFunction( + String fnQName, final Class c, + final String methodName, final Class[] args ) + { + java.lang.reflect.Method method; + ProtectedFunctionMapper funcMapper; + if (System.getSecurityManager() != null){ + funcMapper = (ProtectedFunctionMapper)AccessController.doPrivileged( + new PrivilegedAction(){ + public Object run() { + return new ProtectedFunctionMapper(); + } + }); + + try{ + method = (java.lang.reflect.Method)AccessController.doPrivileged +(new PrivilegedExceptionAction(){ + + public Object run() throws Exception{ + return c.getDeclaredMethod(methodName, args); + } + }); + } catch (PrivilegedActionException ex){ + throw new RuntimeException( + "Invalid function mapping - no such method: " + + ex.getException().getMessage()); + } + } else { + funcMapper = new ProtectedFunctionMapper(); + try { + method = c.getDeclaredMethod(methodName, args); + } catch( NoSuchMethodException e ) { + throw new RuntimeException( + "Invalid function mapping - no such method: " + + e.getMessage()); + } + } + funcMapper.theMethod = method; + return funcMapper; + } + + /** * Resolves the specified local name and prefix into a Java.lang.Method. * Returns null if the prefix and local name are not found. * @@ -161,7 +222,10 @@ * @return the result of the method mapping. Null means no entry found. **/ public Method resolveFunction(String prefix, String localName) { - return (Method) this.fnmap.get(prefix + ":" + localName); + if (this.fnmap != null) { + return (Method) this.fnmap.get(prefix + ":" + localName); + } + return theMethod; } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]