geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1387463 - in /geronimo/external/trunk/tomcat-parent-7.0.27/jasper/src/main/java/org/apache/jasper: el/JasperELResolver.java runtime/JspApplicationContextImpl.java
Date Wed, 19 Sep 2012 06:23:21 GMT
Author: gawor
Date: Wed Sep 19 06:23:21 2012
New Revision: 1387463

URL: http://svn.apache.org/viewvc?rev=1387463&view=rev
Log:
Japser EL Resolver optimization - https://issues.apache.org/bugzilla/show_bug.cgi?id=53896

Added:
    geronimo/external/trunk/tomcat-parent-7.0.27/jasper/src/main/java/org/apache/jasper/el/JasperELResolver.java
  (with props)
Modified:
    geronimo/external/trunk/tomcat-parent-7.0.27/jasper/src/main/java/org/apache/jasper/runtime/JspApplicationContextImpl.java

Added: geronimo/external/trunk/tomcat-parent-7.0.27/jasper/src/main/java/org/apache/jasper/el/JasperELResolver.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.27/jasper/src/main/java/org/apache/jasper/el/JasperELResolver.java?rev=1387463&view=auto
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.27/jasper/src/main/java/org/apache/jasper/el/JasperELResolver.java
(added)
+++ geronimo/external/trunk/tomcat-parent-7.0.27/jasper/src/main/java/org/apache/jasper/el/JasperELResolver.java
Wed Sep 19 06:23:21 2012
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jasper.el;
+
+import java.util.List;
+
+import javax.el.ArrayELResolver;
+import javax.el.BeanELResolver;
+import javax.el.CompositeELResolver;
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ELResolver;
+import javax.el.ListELResolver;
+import javax.el.MapELResolver;
+import javax.el.PropertyNotFoundException;
+import javax.el.ResourceBundleELResolver;
+import javax.servlet.jsp.el.ImplicitObjectELResolver;
+import javax.servlet.jsp.el.ScopedAttributeELResolver;
+
+import org.apache.el.lang.ELSupport;
+
+/*
+ * Jasper-specific CompositeELResolver that optimizes certain functions to avoid unnecessary
resolver calls.
+ */
+public class JasperELResolver extends CompositeELResolver {
+    
+    private int size;
+    private ELResolver[] resolvers;
+    private int appResolversSize;
+
+    public JasperELResolver(List<ELResolver> appResolvers) { 
+        appResolversSize = appResolvers.size();
+        resolvers = new ELResolver[7 /* 7 standard EL resolvers */ + appResolversSize];
+        size = resolvers.length;
+        
+        int index = 0;
+        resolvers[index++] = new ImplicitObjectELResolver();
+        for (ELResolver appResolver : appResolvers) {
+            resolvers[index++] = appResolver;
+        }
+        resolvers[index++] = new MapELResolver();
+        resolvers[index++] = new ResourceBundleELResolver();
+        resolvers[index++] = new ListELResolver();
+        resolvers[index++] = new ArrayELResolver();    
+        resolvers[index++] = new BeanELResolver();
+        resolvers[index++] = new ScopedAttributeELResolver();
+    }
+
+    @Override
+    public synchronized void add(ELResolver elResolver) {
+        super.add(elResolver);
+        
+        ELResolver[] nr = new ELResolver[size + 1];
+        System.arraycopy(resolvers, 0, nr, 0, size);
+        nr[size] = elResolver;
+        
+        resolvers = nr;
+        size ++;
+    }
+
+    @Override
+    public Object getValue(ELContext context, Object base, Object property)
+        throws NullPointerException, PropertyNotFoundException, ELException {        
+        context.setPropertyResolved(false);
+                
+        int start;
+        Object result = null;
+        
+        if (base == null) {
+            // call implicit and app resolvers
+            int index = 1 /* implicit */ + appResolversSize;
+            for (int i = 0; i < index; i++) {
+                result = resolvers[i].getValue(context, base, property);
+                if (context.isPropertyResolved()) {
+                    return result;
+                }
+            }
+            // skip collection-based resolvers (map, resource, list, array, and bean)
+            start = index + 5;
+        } else {
+            // skip implicit resolver only
+            start = 1;
+        }
+        
+        for (int i = start; i < size; i++) {
+            result = resolvers[i].getValue(context, base, property);
+            if (context.isPropertyResolved()) {
+                return result;
+            }
+        }
+
+        return null;
+    }
+    
+    @Override
+    public Object invoke(ELContext context, Object base, Object method, Class<?>[]
paramTypes, Object[] params) {
+        String targetMethod = ELSupport.coerceToString(method);
+        if (targetMethod.length() == 0) {
+            throw new ELException(new NoSuchMethodException());
+        }
+
+        context.setPropertyResolved(false);
+        
+        Object result = null;
+        
+        // skip implicit and call app resolvers
+        int index = 1 /* implicit */ + appResolversSize;
+        for (int i = 1; i < index; i++) {
+            result = resolvers[i].invoke(context, base, targetMethod, paramTypes, params);
+            if (context.isPropertyResolved()) {
+                return result;
+            }
+        }
+        
+        // skip map, resource, list, and array resolvers
+        index += 4; 
+        // call bean and the rest of resolvers
+        for (int i = index; i < size; i++) {
+            result = resolvers[i].invoke(context, base, targetMethod, paramTypes, params);
+            if (context.isPropertyResolved()) {
+                return result;
+            }
+        }
+        
+        return null;
+    }
+    
+}

Propchange: geronimo/external/trunk/tomcat-parent-7.0.27/jasper/src/main/java/org/apache/jasper/el/JasperELResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/external/trunk/tomcat-parent-7.0.27/jasper/src/main/java/org/apache/jasper/el/JasperELResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/external/trunk/tomcat-parent-7.0.27/jasper/src/main/java/org/apache/jasper/el/JasperELResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/external/trunk/tomcat-parent-7.0.27/jasper/src/main/java/org/apache/jasper/runtime/JspApplicationContextImpl.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.27/jasper/src/main/java/org/apache/jasper/runtime/JspApplicationContextImpl.java?rev=1387463&r1=1387462&r2=1387463&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.27/jasper/src/main/java/org/apache/jasper/runtime/JspApplicationContextImpl.java
(original)
+++ geronimo/external/trunk/tomcat-parent-7.0.27/jasper/src/main/java/org/apache/jasper/runtime/JspApplicationContextImpl.java
Wed Sep 19 06:23:21 2012
@@ -19,27 +19,20 @@ package org.apache.jasper.runtime;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
-import javax.el.ArrayELResolver;
-import javax.el.BeanELResolver;
 import javax.el.CompositeELResolver;
 import javax.el.ELContextEvent;
 import javax.el.ELContextListener;
 import javax.el.ELResolver;
 import javax.el.ExpressionFactory;
-import javax.el.ListELResolver;
-import javax.el.MapELResolver;
-import javax.el.ResourceBundleELResolver;
 import javax.servlet.ServletContext;
 import javax.servlet.jsp.JspApplicationContext;
 import javax.servlet.jsp.JspContext;
-import javax.servlet.jsp.el.ImplicitObjectELResolver;
-import javax.servlet.jsp.el.ScopedAttributeELResolver;
 
 import org.apache.jasper.Constants;
 import org.apache.jasper.el.ELContextImpl;
+import org.apache.jasper.el.JasperELResolver;
 
 /**
  * Implementation of JspApplicationContext
@@ -119,18 +112,7 @@ public class JspApplicationContextImpl i
     private ELResolver createELResolver() {
         this.instantiated = true;
         if (this.resolver == null) {
-            CompositeELResolver r = new CompositeELResolver();
-            r.add(new ImplicitObjectELResolver());
-            for (Iterator<ELResolver> itr = this.resolvers.iterator();
-                    itr.hasNext();) {
-                r.add(itr.next());
-            }
-            r.add(new MapELResolver());
-            r.add(new ResourceBundleELResolver());
-            r.add(new ListELResolver());
-            r.add(new ArrayELResolver());    
-            r.add(new BeanELResolver());
-            r.add(new ScopedAttributeELResolver());
+            CompositeELResolver r = new JasperELResolver(this.resolvers);
             this.resolver = r;
         }
         return this.resolver;



Mime
View raw message