Author: musachy
Date: Wed Nov 4 06:55:12 2009
New Revision: 832667
URL:
http://svn.apache.org/viewvc?rev=832667&view=revLog:
add method el resolver
Added:
struts/sandbox/trunk/struts2-uel-plugin/src/main/java/org/apache/struts2/uelplugin/elresolvers/PublicMethodResolver.java
Modified:
struts/sandbox/trunk/struts2-uel-plugin/src/main/java/org/apache/struts2/uelplugin/CompoundRootELContext.java
Modified: struts/sandbox/trunk/struts2-uel-plugin/src/main/java/org/apache/struts2/uelplugin/CompoundRootELContext.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-uel-plugin/src/main/java/org/apache/struts2/uelplugin/CompoundRootELContext.java?rev=832667&r1=832666&r2=832667&view=diff==============================================================================
--- struts/sandbox/trunk/struts2-uel-plugin/src/main/java/org/apache/struts2/uelplugin/CompoundRootELContext.java (original)
+++ struts/sandbox/trunk/struts2-uel-plugin/src/main/java/org/apache/struts2/uelplugin/CompoundRootELContext.java Wed Nov 4 06:55:12 2009
@@ -1,29 +1,23 @@
package org.apache.struts2.uelplugin;
-import javax.el.ArrayELResolver;
-import javax.el.CompositeELResolver;
-import javax.el.ELContext;
-import javax.el.ELResolver;
-import javax.el.FunctionMapper;
-import javax.el.ListELResolver;
-import javax.el.MapELResolver;
-import javax.el.ResourceBundleELResolver;
-import javax.el.VariableMapper;
+import javax.el.*;
import org.apache.struts2.uelplugin.elresolvers.CompoundRootELResolver;
import org.apache.struts2.uelplugin.elresolvers.XWorkBeanELResolver;
+import org.apache.struts2.uelplugin.elresolvers.PublicMethodResolver;
+import de.odysseus.el.util.SimpleContext;
/**
* An implementation of SimpleContext that knows about the ValueStack's
* CompoundRoot.
*/
-public class CompoundRootELContext extends ELContext {
- private ELResolver DEFAULT_RESOLVER_READ_WRITE;
-
+public class CompoundRootELContext extends SimpleContext {
public CompoundRootELContext() {
- DEFAULT_RESOLVER_READ_WRITE = new CompositeELResolver() {
+ super(new CompositeELResolver() {
{
+ add(new BeanELResolver());
+ add(new PublicMethodResolver());
add(new CompoundRootELResolver());
add(new ArrayELResolver(false));
add(new ListELResolver(false));
@@ -31,7 +25,7 @@
add(new ResourceBundleELResolver());
add(new XWorkBeanELResolver());
}
- };
+ });
}
@Override
@@ -40,11 +34,6 @@
}
@Override
- public ELResolver getELResolver() {
- return DEFAULT_RESOLVER_READ_WRITE;
- }
-
- @Override
public FunctionMapper getFunctionMapper() {
return null;
}
Added: struts/sandbox/trunk/struts2-uel-plugin/src/main/java/org/apache/struts2/uelplugin/elresolvers/PublicMethodResolver.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-uel-plugin/src/main/java/org/apache/struts2/uelplugin/elresolvers/PublicMethodResolver.java?rev=832667&view=auto==============================================================================
--- struts/sandbox/trunk/struts2-uel-plugin/src/main/java/org/apache/struts2/uelplugin/elresolvers/PublicMethodResolver.java (added)
+++ struts/sandbox/trunk/struts2-uel-plugin/src/main/java/org/apache/struts2/uelplugin/elresolvers/PublicMethodResolver.java Wed Nov 4 06:55:12 2009
@@ -0,0 +1,66 @@
+package org.apache.struts2.uelplugin.elresolvers;
+
+import de.odysseus.el.misc.MethodInvocation;
+
+import javax.el.ELResolver;
+import javax.el.ELContext;
+import javax.el.PropertyNotWritableException;
+import java.lang.reflect.Method;
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+
+public class PublicMethodResolver extends ELResolver {
+ private boolean match(MethodInvocation call, Method method) {
+ if (method.getName().equals(call.getName()) && method.getReturnType() != void.class) {
+ if (call.getParamCount() == method.getParameterTypes().length) {
+ return true;
+ }
+ if (method.isVarArgs() && call.isVarArgs()) {
+ if (call.getParamCount() >= method.getParameterTypes().length - 1) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public Method getValue(ELContext context, Object base, Object prop) {
+ if (base != null && prop instanceof MethodInvocation) {
+ MethodInvocation call = (MethodInvocation) prop;
+ for (Method method : base.getClass().getMethods()) {
+ if (match(call, method)) {
+ context.setPropertyResolved(true);
+ return method;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void setValue(ELContext context, Object base, Object property, Object value) {
+ throw new PropertyNotWritableException();
+ }
+
+ @Override
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+ return MethodInvocation.class;
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext context, Object base, Object property) {
+ return true;
+ }
+
+ @Override
+ public Class<?> getType(ELContext context, Object base, Object property) {
+ return null;
+ }
+
+ @Override
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
+ return null;
+ }
+}
+