You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by ts...@apache.org on 2007/11/06 04:30:26 UTC
svn commit: r592241 -
/struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/
Author: tschneider
Date: Mon Nov 5 19:30:25 2007
New Revision: 592241
URL: http://svn.apache.org/viewvc?rev=592241&view=rev
Log:
divorced juel from the value stack so we are only dependent on the java el classes
Added:
struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/CompoundRootELResolver.java
struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/ExpressionFactoryLocator.java
Modified:
struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/CompoundRootELContext.java
struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/CompoundRootVariableMapper.java
struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/JuelReflectionProvider.java
struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/JuelValueStack.java
struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/JuelValueStackFactory.java
Modified: struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/CompoundRootELContext.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/CompoundRootELContext.java?rev=592241&r1=592240&r2=592241&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/CompoundRootELContext.java (original)
+++ struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/CompoundRootELContext.java Mon Nov 5 19:30:25 2007
@@ -1,17 +1,36 @@
package com.googlecode.struts2juel;
+import javax.el.ArrayELResolver;
+import javax.el.BeanELResolver;
+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 com.opensymphony.xwork2.util.CompoundRoot;
-import de.odysseus.el.util.SimpleContext;
-
/**
- * An implementation of SimpleContext that knows about the CompoundRoot.
+ * An implementation of SimpleContext that knows about the ValueStack's CompoundRoot.
*/
-public class CompoundRootELContext extends SimpleContext {
+public class CompoundRootELContext extends ELContext {
private VariableMapper variableMapper;
+ private FunctionMapper functionMapper = new NullFunctionMapper();
+ private static final ELResolver DEFAULT_RESOLVER_READ_ONLY = new CompositeELResolver() {
+ {
+ add(new CompoundRootELResolver());
+ add(new ArrayELResolver(false));
+ add(new ListELResolver(false));
+ add(new MapELResolver(false));
+ add(new ResourceBundleELResolver());
+ add(new BeanELResolver(false));
+ }
+ };
+
public CompoundRootELContext(CompoundRoot root) {
variableMapper = new CompoundRootVariableMapper(root);
}
@@ -20,4 +39,14 @@
public VariableMapper getVariableMapper() {
return variableMapper;
}
+
+ @Override
+ public ELResolver getELResolver() {
+ return DEFAULT_RESOLVER_READ_ONLY;
+ }
+
+ @Override
+ public FunctionMapper getFunctionMapper() {
+ return functionMapper;
+ }
}
Added: struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/CompoundRootELResolver.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/CompoundRootELResolver.java?rev=592241&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/CompoundRootELResolver.java (added)
+++ struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/CompoundRootELResolver.java Mon Nov 5 19:30:25 2007
@@ -0,0 +1,51 @@
+package com.googlecode.struts2juel;
+
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+
+/**
+ * An ELResolver capable of resolving
+ */
+public class CompoundRootELResolver extends ELResolver {
+
+ @Override
+ public Class<?> getCommonPropertyType(ELContext arg0, Object arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext arg0,
+ Object arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Class<?> getType(ELContext arg0, Object arg1, Object arg2) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Object getValue(ELContext arg0, Object arg1, Object arg2) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext arg0, Object arg1, Object arg2) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void setValue(ELContext arg0, Object arg1, Object arg2, Object arg3) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Modified: struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/CompoundRootVariableMapper.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/CompoundRootVariableMapper.java?rev=592241&r1=592240&r2=592241&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/CompoundRootVariableMapper.java (original)
+++ struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/CompoundRootVariableMapper.java Mon Nov 5 19:30:25 2007
@@ -1,14 +1,9 @@
package com.googlecode.struts2juel;
-import java.util.HashMap;
-import java.util.Map;
-
import javax.el.ValueExpression;
import javax.el.VariableMapper;
import org.apache.commons.beanutils.PropertyUtils;
-
-import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import com.opensymphony.xwork2.util.CompoundRoot;
Added: struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/ExpressionFactoryLocator.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/ExpressionFactoryLocator.java?rev=592241&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/ExpressionFactoryLocator.java (added)
+++ struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/ExpressionFactoryLocator.java Mon Nov 5 19:30:25 2007
@@ -0,0 +1,46 @@
+package com.googlecode.struts2juel;
+
+import javax.el.ExpressionFactory;
+import javax.servlet.ServletContext;
+import javax.servlet.jsp.JspApplicationContext;
+import javax.servlet.jsp.JspFactory;
+
+import org.apache.struts2.StrutsStatics;
+
+import com.opensymphony.xwork2.ActionContext;
+
+/**
+ * Locates the current ExpressFactory. The preference is to use the app server's
+ * built-in ExpressFactory. If that isn't available, then JUEL's ExpressFactory
+ * will be used.
+ */
+public class ExpressionFactoryLocator {
+ private static final String JUEL_FACTORY = "de.odysseus.el.ExpressionFactoryImpl";
+
+ public static ExpressionFactory locateExpressFactory() {
+ ExpressionFactory factory = null;
+ // first try to load the default ExpressFactory from the JSP engine
+ try {
+ ActionContext actionContext = ActionContext.getContext();
+ ServletContext servletContext = (ServletContext) actionContext
+ .get(StrutsStatics.SERVLET_CONTEXT);
+ JspFactory jspFactory = JspFactory.getDefaultFactory();
+ JspApplicationContext jspAppCtx = jspFactory
+ .getJspApplicationContext(servletContext);
+ factory = jspAppCtx.getExpressionFactory();
+ } catch (Throwable t) {
+ // fallback to juel
+ try {
+ factory = (ExpressionFactory) Class.forName(JUEL_FACTORY)
+ .newInstance();
+ } catch (InstantiationException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return factory;
+ }
+}
Modified: struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/JuelReflectionProvider.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/JuelReflectionProvider.java?rev=592241&r1=592240&r2=592241&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/JuelReflectionProvider.java (original)
+++ struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/JuelReflectionProvider.java Mon Nov 5 19:30:25 2007
@@ -14,10 +14,17 @@
* A OgnlReflectionProvider based on Juel.
*/
public class JuelReflectionProvider extends OgnlReflectionProvider {
- ExpressionFactory factory = new de.odysseus.el.ExpressionFactoryImpl();
+ private ExpressionFactory factory;
+ public void initExpressionFactory() {
+ if (factory == null) {
+ factory = ExpressionFactoryLocator.locateExpressFactory();
+ }
+ }
+
@Override
public Object getValue(String expr, Map context, Object root) throws ReflectionException {
+ initExpressionFactory();
CompoundRoot compoundRoot = new CompoundRoot();
compoundRoot.add(root);
ELContext elContext = new CompoundRootELContext(compoundRoot);
@@ -29,6 +36,7 @@
@Override
public void setValue(String expr, Map context, Object root, Object value) throws ReflectionException {
+ initExpressionFactory();
CompoundRoot compoundRoot = new CompoundRoot();
compoundRoot.add(root);
ELContext elContext = new CompoundRootELContext(compoundRoot);
Modified: struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/JuelValueStack.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/JuelValueStack.java?rev=592241&r1=592240&r2=592241&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/JuelValueStack.java (original)
+++ struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/JuelValueStack.java Mon Nov 5 19:30:25 2007
@@ -21,15 +21,17 @@
private Class defaultType;
private Map overrides;
- private ExpressionFactory factory = new de.odysseus.el.ExpressionFactoryImpl();
+ private ExpressionFactory factory;
private ELContext elContext;
- public JuelValueStack() {
+ public JuelValueStack(ExpressionFactory factory) {
+ this.factory = factory;
setRoot(new CompoundRoot());
}
- public JuelValueStack(ValueStack vs) {
+ public JuelValueStack(ExpressionFactory factory, ValueStack vs) {
+ this.factory = factory;
setRoot(new CompoundRoot(vs.getRoot()));
}
Modified: struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/JuelValueStackFactory.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/JuelValueStackFactory.java?rev=592241&r1=592240&r2=592241&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/JuelValueStackFactory.java (original)
+++ struts/sandbox/trunk/struts2-juel-plugin/src/main/java/com/googlecode/struts2juel/JuelValueStackFactory.java Mon Nov 5 19:30:25 2007
@@ -1,5 +1,7 @@
package com.googlecode.struts2juel;
+import javax.el.ExpressionFactory;
+
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.ValueStackFactory;
@@ -7,12 +9,21 @@
* Creates JuelValueStacks.
*/
public class JuelValueStackFactory implements ValueStackFactory {
+ private ExpressionFactory factory;
+ public void initExpressionFactory() {
+ if (factory == null) {
+ factory = ExpressionFactoryLocator.locateExpressFactory();
+ }
+ }
+
public ValueStack createValueStack() {
- return new JuelValueStack();
+ initExpressionFactory();
+ return new JuelValueStack(factory);
}
public ValueStack createValueStack(ValueStack stack) {
- return new JuelValueStack(stack);
+ initExpressionFactory();
+ return new JuelValueStack(factory, stack);
}
}