geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1387447 - in /geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el: BeanELResolver.java CompositeELResolver.java ELUtils.java
Date Wed, 19 Sep 2012 04:11:56 GMT
Author: gawor
Date: Wed Sep 19 04:11:56 2012
New Revision: 1387447

URL: http://svn.apache.org/viewvc?rev=1387447&view=rev
Log:
some more minor optimizations

Modified:
    geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/BeanELResolver.java
    geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/CompositeELResolver.java
    geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/ELUtils.java

Modified: geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/BeanELResolver.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/BeanELResolver.java?rev=1387447&r1=1387446&r2=1387447&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/BeanELResolver.java (original)
+++ geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/BeanELResolver.java Wed
Sep 19 04:11:56 2012
@@ -351,20 +351,11 @@ public class BeanELResolver extends ELRe
             throw new NullPointerException("ELContext could not be nulll");
         }
         // Why static invocation is not supported
-        if(base == null || method == null) {
+        if (base == null || method == null) {
             return null;
         }
-        if (params == null) {
-            params = new Object[0];
-        }
-        ExpressionFactory expressionFactory = null;
-        if (ELUtils.isCachedExpressionFactoryEnabled()) {
-            expressionFactory = ELUtils.getCachedExpressionFactory();
-        }
-        if (expressionFactory == null) {
-            expressionFactory = ExpressionFactory.newInstance();
-        }
-        String methodName = (String) expressionFactory.coerceToType(method, String.class);
+
+        String methodName = ELUtils.coerceToString(method);
         if (methodName.length() == 0) {
             throw new MethodNotFoundException("The parameter method could not be zero-length");
         }
@@ -372,17 +363,23 @@ public class BeanELResolver extends ELRe
         if (methodName.equals("<init>") || methodName.equals("<cinit>")) {
             throw new MethodNotFoundException(method + " is not found in target class " +
targetClass.getName());
         }
+
+        if (params == null) {
+            params = new Object[0];
+        }
+
         Method targetMethod = null;
         if (paramTypes == null) {
             int paramsNumber = params.length;
-            for (Method m : targetClass.getMethods()) {
+            Method[] methods = targetClass.getMethods();
+            for (Method m : methods) {
                 if (m.getName().equals(methodName) && m.getParameterTypes().length
== paramsNumber) {
                     targetMethod = m;
                     break;
                 }
             }
             if (targetMethod == null) {
-                for (Method m : targetClass.getMethods()) {
+                for (Method m : methods) {
                     if (m.getName().equals(methodName) && m.isVarArgs() &&
paramsNumber >= (m.getParameterTypes().length - 1)) {
                         targetMethod = m;
                         break;
@@ -416,6 +413,14 @@ public class BeanELResolver extends ELRe
             Object[] finalParamValues = new Object[paramTypes.length];
             //Only do the parameter conversion while the method is not a non-parameter one
             if (paramTypes.length > 0) {
+                ExpressionFactory expressionFactory = null;
+                if (ELUtils.isCachedExpressionFactoryEnabled()) {
+                    expressionFactory = ELUtils.getCachedExpressionFactory();
+                }
+                if (expressionFactory == null) {
+                    expressionFactory = ExpressionFactory.newInstance();
+                }
+
                 int iCurrentIndex = 0;
                 for (int iLoopSize = paramTypes.length - 1; iCurrentIndex < iLoopSize;
iCurrentIndex++) {
                     finalParamValues[iCurrentIndex] = expressionFactory.coerceToType(params[iCurrentIndex],
paramTypes[iCurrentIndex]);

Modified: geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/CompositeELResolver.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/CompositeELResolver.java?rev=1387447&r1=1387446&r2=1387447&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/CompositeELResolver.java
(original)
+++ geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/CompositeELResolver.java
Wed Sep 19 04:11:56 2012
@@ -196,21 +196,12 @@ public class CompositeELResolver extends
         if (method == null || base == null) {
             return null;
         }
-        ExpressionFactory expressionFactory = null;
-        if (ELUtils.isCachedExpressionFactoryEnabled()) {
-            expressionFactory = ELUtils.getCachedExpressionFactory();
-        }
-        if (expressionFactory == null) {
-            expressionFactory = ExpressionFactory.newInstance();
-        }
-        String targetMethod = (String) expressionFactory.coerceToType(method, String.class);
+        String targetMethod = ELUtils.coerceToString(method);
         if (targetMethod.length() == 0) {
             throw new ELException(new NoSuchMethodException());
         }
+
         context.setPropertyResolved(false);
-        if (context.getContext(ExpressionFactory.class) == null) {
-            context.putContext(ExpressionFactory.class, expressionFactory);
-        }
 
         ELResolver[] rslvrs = resolvers.get();
         int sz = rslvrs.length;
@@ -224,4 +215,5 @@ public class CompositeELResolver extends
         }
         return null;
     }
+
 }

Modified: geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/ELUtils.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/ELUtils.java?rev=1387447&r1=1387446&r2=1387447&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/ELUtils.java (original)
+++ geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/ELUtils.java Wed Sep
19 04:11:56 2012
@@ -34,4 +34,16 @@ class ELUtils {
     public static void setCachedExpressionFactory(ExpressionFactory expressionFactory) {
         cachedExpressionFactory = expressionFactory;
     }
+
+    public static String coerceToString(Object obj) {
+        if (obj == null) {
+            return "";
+        } else if (obj instanceof String) {
+            return (String) obj;
+        } else if (obj instanceof Enum<?>) {
+            return ((Enum<?>) obj).name();
+        } else {
+            return obj.toString();
+        }
+    }
 }



Mime
View raw message