Author: markt
Date: Fri Jun 28 19:16:24 2013
New Revision: 1497896
URL: http://svn.apache.org/r1497896
Log:
Re-order to make checking against EL Spec RI easier
Modified:
tomcat/trunk/java/javax/el/BeanELResolver.java
Modified: tomcat/trunk/java/javax/el/BeanELResolver.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/BeanELResolver.java?rev=1497896&r1=1497895&r2=1497896&view=diff
==============================================================================
--- tomcat/trunk/java/javax/el/BeanELResolver.java (original)
+++ tomcat/trunk/java/javax/el/BeanELResolver.java Fri Jun 28 19:16:24 2013
@@ -72,6 +72,20 @@ public class BeanELResolver extends ELRe
}
@Override
+ public Class<?> getType(ELContext context, Object base, Object property)
+ throws NullPointerException, PropertyNotFoundException,
ELException {
+ if (context == null) {
+ throw new NullPointerException();
+ }
+ if (base == null || property == null) {
+ return null;
+ }
+
+ context.setPropertyResolved(true);
+ return this.property(context, base, property).getPropertyType();
+ }
+
+ @Override
public Object getValue(ELContext context, Object base, Object property)
throws NullPointerException, PropertyNotFoundException,
ELException {
if (context == null) {
@@ -104,20 +118,6 @@ public class BeanELResolver extends ELRe
}
@Override
- public Class<?> getType(ELContext context, Object base, Object property)
- throws NullPointerException, PropertyNotFoundException,
ELException {
- if (context == null) {
- throw new NullPointerException();
- }
- if (base == null || property == null) {
- return null;
- }
-
- context.setPropertyResolved(true);
- return this.property(context, base, property).getPropertyType();
- }
-
- @Override
public void setValue(ELContext context, Object base, Object property,
Object value) throws NullPointerException,
PropertyNotFoundException, PropertyNotWritableException,
@@ -158,6 +158,113 @@ public class BeanELResolver extends ELRe
}
}
+ /**
+ * @since EL 2.2
+ */
+ @Override
+ public Object invoke(ELContext context, Object base, Object method,
+ Class<?>[] paramTypes, Object[] params) {
+ if (context == null) {
+ throw new NullPointerException();
+ }
+ if (base == null || method == null) {
+ return null;
+ }
+
+ ExpressionFactory factory = ExpressionFactory.newInstance();
+
+ String methodName = (String) factory.coerceToType(method,
String.class);
+
+ // Find the matching method
+ Method matchingMethod = null;
+ Class<?> clazz = base.getClass();
+ if (paramTypes != null) {
+ try {
+ matchingMethod =
+ getMethod(clazz, clazz.getMethod(methodName, paramTypes));
+ } catch (NoSuchMethodException e) {
+ throw new MethodNotFoundException(e);
+ }
+ } else {
+ int paramCount = 0;
+ if (params != null) {
+ paramCount = params.length;
+ }
+ Method[] methods = clazz.getMethods();
+ for (Method m : methods) {
+ if (methodName.equals(m.getName())) {
+ if (m.getParameterTypes().length == paramCount) {
+ // Same number of parameters - use the first match
+ matchingMethod = getMethod(clazz, m);
+ break;
+ }
+ if (m.isVarArgs()
+ && paramCount > m.getParameterTypes().length - 2) {
+ matchingMethod = getMethod(clazz, m);
+ }
+ }
+ }
+ if (matchingMethod == null) {
+ throw new MethodNotFoundException(
+ "Unable to find method [" + methodName + "] with ["
+ + paramCount + "] parameters");
+ }
+ }
+
+ Class<?>[] parameterTypes = matchingMethod.getParameterTypes();
+ Object[] parameters = null;
+ if (parameterTypes.length > 0) {
+ parameters = new Object[parameterTypes.length];
+ @SuppressWarnings("null") // params.length >=
parameterTypes.length
+ int paramCount = params.length;
+ if (matchingMethod.isVarArgs()) {
+ int varArgIndex = parameterTypes.length - 1;
+ // First argCount-1 parameters are standard
+ for (int i = 0; (i < varArgIndex); i++) {
+ parameters[i] = factory.coerceToType(params[i],
+ parameterTypes[i]);
+ }
+ // Last parameter is the varargs
+ Class<?> varArgClass =
+ parameterTypes[varArgIndex].getComponentType();
+ final Object varargs = Array.newInstance(
+ varArgClass,
+ (paramCount - varArgIndex));
+ for (int i = (varArgIndex); i < paramCount; i++) {
+ Array.set(varargs, i - varArgIndex,
+ factory.coerceToType(params[i], varArgClass));
+ }
+ parameters[varArgIndex] = varargs;
+ } else {
+ parameters = new Object[parameterTypes.length];
+ for (int i = 0; i < parameterTypes.length; i++) {
+ parameters[i] = factory.coerceToType(params[i],
+ parameterTypes[i]);
+ }
+ }
+ }
+ Object result = null;
+ try {
+ result = matchingMethod.invoke(base, parameters);
+ } catch (IllegalArgumentException e) {
+ throw new ELException(e);
+ } catch (IllegalAccessException e) {
+ throw new ELException(e);
+ } catch (InvocationTargetException e) {
+ Throwable cause = e.getCause();
+ if (cause instanceof ThreadDeath) {
+ throw (ThreadDeath) cause;
+ }
+ if (cause instanceof VirtualMachineError) {
+ throw (VirtualMachineError) cause;
+ }
+ throw new ELException(cause);
+ }
+
+ context.setPropertyResolved(true);
+ return result;
+ }
+
@Override
public boolean isReadOnly(ELContext context, Object base, Object property)
throws NullPointerException, PropertyNotFoundException,
ELException {
@@ -393,112 +500,4 @@ public class BeanELResolver extends ELRe
}
}
-
- /**
- * @since EL 2.2
- */
- @Override
- public Object invoke(ELContext context, Object base, Object method,
- Class<?>[] paramTypes, Object[] params) {
- if (context == null) {
- throw new NullPointerException();
- }
- if (base == null || method == null) {
- return null;
- }
-
- ExpressionFactory factory = ExpressionFactory.newInstance();
-
- String methodName = (String) factory.coerceToType(method,
String.class);
-
- // Find the matching method
- Method matchingMethod = null;
- Class<?> clazz = base.getClass();
- if (paramTypes != null) {
- try {
- matchingMethod =
- getMethod(clazz, clazz.getMethod(methodName, paramTypes));
- } catch (NoSuchMethodException e) {
- throw new MethodNotFoundException(e);
- }
- } else {
- int paramCount = 0;
- if (params != null) {
- paramCount = params.length;
- }
- Method[] methods = clazz.getMethods();
- for (Method m : methods) {
- if (methodName.equals(m.getName())) {
- if (m.getParameterTypes().length == paramCount) {
- // Same number of parameters - use the first match
- matchingMethod = getMethod(clazz, m);
- break;
- }
- if (m.isVarArgs()
- && paramCount > m.getParameterTypes().length - 2) {
- matchingMethod = getMethod(clazz, m);
- }
- }
- }
- if (matchingMethod == null) {
- throw new MethodNotFoundException(
- "Unable to find method [" + methodName + "] with ["
- + paramCount + "] parameters");
- }
- }
-
- Class<?>[] parameterTypes = matchingMethod.getParameterTypes();
- Object[] parameters = null;
- if (parameterTypes.length > 0) {
- parameters = new Object[parameterTypes.length];
- @SuppressWarnings("null") // params.length >=
parameterTypes.length
- int paramCount = params.length;
- if (matchingMethod.isVarArgs()) {
- int varArgIndex = parameterTypes.length - 1;
- // First argCount-1 parameters are standard
- for (int i = 0; (i < varArgIndex); i++) {
- parameters[i] = factory.coerceToType(params[i],
- parameterTypes[i]);
- }
- // Last parameter is the varargs
- Class<?> varArgClass =
- parameterTypes[varArgIndex].getComponentType();
- final Object varargs = Array.newInstance(
- varArgClass,
- (paramCount - varArgIndex));
- for (int i = (varArgIndex); i < paramCount; i++) {
- Array.set(varargs, i - varArgIndex,
- factory.coerceToType(params[i], varArgClass));
- }
- parameters[varArgIndex] = varargs;
- } else {
- parameters = new Object[parameterTypes.length];
- for (int i = 0; i < parameterTypes.length; i++) {
- parameters[i] = factory.coerceToType(params[i],
- parameterTypes[i]);
- }
- }
- }
- Object result = null;
- try {
- result = matchingMethod.invoke(base, parameters);
- } catch (IllegalArgumentException e) {
- throw new ELException(e);
- } catch (IllegalAccessException e) {
- throw new ELException(e);
- } catch (InvocationTargetException e) {
- Throwable cause = e.getCause();
- if (cause instanceof ThreadDeath) {
- throw (ThreadDeath) cause;
- }
- if (cause instanceof VirtualMachineError) {
- throw (VirtualMachineError) cause;
- }
- throw new ELException(cause);
- }
-
- context.setPropertyResolved(true);
- return result;
- }
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]