You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/07/03 23:16:41 UTC
svn commit: r1499561 - in /tomcat/trunk/java/javax/el: ELManager.java
ExpressionFactory.java StandardELContext.java
Author: markt
Date: Wed Jul 3 21:16:40 2013
New Revision: 1499561
URL: http://svn.apache.org/r1499561
Log:
EL 3.0
Add new classes and methods
Added:
tomcat/trunk/java/javax/el/ELManager.java (with props)
tomcat/trunk/java/javax/el/StandardELContext.java (with props)
Modified:
tomcat/trunk/java/javax/el/ExpressionFactory.java
Added: tomcat/trunk/java/javax/el/ELManager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/ELManager.java?rev=1499561&view=auto
==============================================================================
--- tomcat/trunk/java/javax/el/ELManager.java (added)
+++ tomcat/trunk/java/javax/el/ELManager.java Wed Jul 3 21:16:40 2013
@@ -0,0 +1,90 @@
+/*
+ * 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 javax.el;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+/**
+ * @since EL 3.0
+ */
+public class ELManager {
+
+ private StandardELContext context = null;
+
+ public static ExpressionFactory getExpressionFactory() {
+ return Util.getExpressionFactory();
+ }
+
+ public StandardELContext getELContext() {
+ if (context == null) {
+ context = new StandardELContext(getExpressionFactory());
+ }
+
+ return context;
+ }
+
+ public ELContext setELContext(ELContext context) {
+ StandardELContext oldContext = this.context;
+ this.context = new StandardELContext(context);
+ return oldContext;
+ }
+
+ public void addBeanNameResolver(BeanNameResolver beanNameResolver) {
+ getELContext().addELResolver(new BeanNameELResolver(beanNameResolver));
+ }
+
+ public void addELResolver(ELResolver resolver) {
+ getELContext().addELResolver(resolver);
+ }
+
+ public void mapFunction(String prefix, String function, Method method) {
+ getELContext().getFunctionMapper().mapFunction(
+ prefix, function, method);
+ }
+
+ public void setVariable(String variable, ValueExpression expression) {
+ getELContext().getVariableMapper().setVariable(variable, expression);
+ }
+
+ public void importStatic(String staticMemberName)
+ throws javax.el.ELException {
+ getELContext().getImportHandler().importStatic(staticMemberName);
+ }
+
+ public void importClass(String className) throws javax.el.ELException {
+ getELContext().getImportHandler().importClass(className);
+ }
+
+ public void importPackage(String packageName) {
+ getELContext().getImportHandler().importPackage(packageName);
+ }
+
+ public Object defineBean(String name, Object bean) {
+ Map<String,Object> localBeans = getELContext().getLocalBeans();
+
+ if (bean == null) {
+ return localBeans.remove(name);
+ } else {
+ return localBeans.put(name, bean);
+ }
+ }
+
+ public void addEvaluationListener(EvaluationListener listener) {
+ getELContext().addEvaluationListener(listener);
+ }
+}
Propchange: tomcat/trunk/java/javax/el/ELManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/java/javax/el/ExpressionFactory.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/ExpressionFactory.java?rev=1499561&r1=1499560&r2=1499561&view=diff
==============================================================================
--- tomcat/trunk/java/javax/el/ExpressionFactory.java (original)
+++ tomcat/trunk/java/javax/el/ExpressionFactory.java Wed Jul 3 21:16:40 2013
@@ -28,8 +28,10 @@ import java.io.UnsupportedEncodingExcept
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -86,21 +88,6 @@ public abstract class ExpressionFactory
}
}
- public abstract Object coerceToType(Object obj, Class<?> expectedType)
- throws ELException;
-
- public abstract ValueExpression createValueExpression(ELContext context,
- String expression, Class<?> expectedType)
- throws NullPointerException, ELException;
-
- public abstract ValueExpression createValueExpression(Object instance,
- Class<?> expectedType);
-
- public abstract MethodExpression createMethodExpression(ELContext context,
- String expression, Class<?> expectedReturnType,
- Class<?>[] expectedParamTypes) throws ELException,
- NullPointerException;
-
/**
* Create a new {@link ExpressionFactory}. The class to use is determined by
* the following search order:
@@ -229,6 +216,35 @@ public abstract class ExpressionFactory
return result;
}
+ public abstract ValueExpression createValueExpression(ELContext context,
+ String expression, Class<?> expectedType)
+ throws NullPointerException, ELException;
+
+ public abstract ValueExpression createValueExpression(Object instance,
+ Class<?> expectedType);
+
+ public abstract MethodExpression createMethodExpression(ELContext context,
+ String expression, Class<?> expectedReturnType,
+ Class<?>[] expectedParamTypes) throws ELException,
+ NullPointerException;
+
+ public abstract Object coerceToType(Object obj, Class<?> expectedType)
+ throws ELException;
+
+ /**
+ * @since EL 3.0
+ */
+ public ELResolver getStreamELResolver() {
+ return null;
+ }
+
+ /**
+ * @since EL 3.0
+ */
+ public Map<String,Method> getInitFunctionMap() {
+ return null;
+ }
+
/**
* Key used to cache ExpressionFactory discovery information per class
* loader. The class loader reference is never {@code null}, because
Added: tomcat/trunk/java/javax/el/StandardELContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/StandardELContext.java?rev=1499561&view=auto
==============================================================================
--- tomcat/trunk/java/javax/el/StandardELContext.java (added)
+++ tomcat/trunk/java/javax/el/StandardELContext.java Wed Jul 3 21:16:40 2013
@@ -0,0 +1,206 @@
+/*
+ * 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 javax.el;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @since EL 3.0
+ */
+public class StandardELContext extends ELContext {
+
+ private final ELContext wrappedContext;
+ private final VariableMapper variableMapper;
+ private final FunctionMapper functionMapper;
+ private final CompositeELResolver standardResolver;
+ private final CompositeELResolver customResolvers;
+ private final Map<String,Object> localBeans = new HashMap<>();
+
+
+ public StandardELContext(ExpressionFactory factory) {
+ wrappedContext = null;
+ variableMapper = new StandardVariableMapper();
+ functionMapper =
+ new StandardFunctionMapper(factory.getInitFunctionMap());
+ standardResolver = new CompositeELResolver();
+ customResolvers = new CompositeELResolver();
+
+ ELResolver streamResolver = factory.getStreamELResolver();
+
+ // Add resolvers in order
+ standardResolver.add(new BeanNameELResolver(
+ new StandardBeanNameResolver(localBeans)));
+ standardResolver.add(customResolvers);
+ if (streamResolver != null) {
+ standardResolver.add(streamResolver);
+ }
+ standardResolver.add(new StaticFieldELResolver());
+ standardResolver.add(new MapELResolver());
+ standardResolver.add(new ResourceBundleELResolver());
+ standardResolver.add(new ListELResolver());
+ standardResolver.add(new ArrayELResolver());
+ standardResolver.add(new BeanELResolver());
+ }
+
+ public StandardELContext(ELContext context) {
+ wrappedContext = context;
+ variableMapper = context.getVariableMapper();
+ functionMapper = context.getFunctionMapper();
+ standardResolver = new CompositeELResolver();
+ customResolvers = new CompositeELResolver();
+
+ // Add resolvers in order
+ standardResolver.add(new BeanNameELResolver(
+ new StandardBeanNameResolver(localBeans)));
+ standardResolver.add(customResolvers);
+ // No stream resolver
+ // Use resolvers from context from this point on
+ standardResolver.add(context.getELResolver());
+ }
+
+ // Can't use Class<?> because API needs to match specification
+ @Override
+ public void putContext(Class key, Object contextObject) {
+ if (wrappedContext == null) {
+ super.putContext(key, contextObject);
+ } else {
+ wrappedContext.putContext(key, contextObject);
+ }
+ }
+
+ @Override
+ public Object getContext(Class key) {
+ if (wrappedContext == null) {
+ return super.getContext(key);
+ } else {
+ return wrappedContext.getContext(key);
+ }
+ }
+
+ @Override
+ public ELResolver getELResolver() {
+ return standardResolver;
+ }
+
+ public void addELResolver(ELResolver resolver) {
+ customResolvers.add(resolver);
+ }
+
+ @Override
+ public FunctionMapper getFunctionMapper() {
+ return functionMapper;
+ }
+
+ @Override
+ public VariableMapper getVariableMapper() {
+ return variableMapper;
+ }
+
+
+ Map<String,Object> getLocalBeans() {
+ return localBeans;
+ }
+
+
+ private static class StandardVariableMapper extends VariableMapper {
+
+ private Map<String, ValueExpression> vars;
+
+ @Override
+ public ValueExpression resolveVariable(String variable) {
+ if (vars == null) {
+ return null;
+ }
+ return vars.get(variable);
+ }
+
+ @Override
+ public ValueExpression setVariable(String variable,
+ ValueExpression expression) {
+ if (vars == null)
+ vars = new HashMap<>();
+ if (expression == null) {
+ return vars.remove(variable);
+ } else {
+ return vars.put(variable, expression);
+ }
+ }
+ }
+
+
+ private static class StandardBeanNameResolver extends BeanNameResolver {
+
+ private final Map<String,Object> beans;
+
+ public StandardBeanNameResolver(Map<String,Object> beans) {
+ this.beans = beans;
+ }
+
+ @Override
+ public boolean isNameResolved(String beanName) {
+ return beans.containsKey(beanName);
+ }
+
+ @Override
+ public Object getBean(String beanName) {
+ return beans.get(beanName);
+ }
+
+ @Override
+ public void setBeanValue(String beanName, Object value)
+ throws PropertyNotWritableException {
+ beans.put(beanName, value);
+ }
+
+ @Override
+ public boolean isReadOnly(String beanName) {
+ return false;
+ }
+
+ @Override
+ public boolean canCreateBean(String beanName) {
+ return true;
+ }
+ }
+
+
+ private static class StandardFunctionMapper extends FunctionMapper {
+
+ private final Map<String,Method> methods = new HashMap<>();
+
+ public StandardFunctionMapper(Map<String,Method> initFunctionMap) {
+ if (initFunctionMap != null) {
+ methods.putAll(initFunctionMap);
+ }
+ }
+
+ @Override
+ public Method resolveFunction(String prefix, String localName) {
+ String key = prefix + ':' + localName;
+ return methods.get(key);
+ }
+
+ @Override
+ public void mapFunction(String prefix, String localName,
+ Method method) {
+ String key = prefix + ':' + localName;
+ methods.put(key, method);
+ }
+ }
+}
Propchange: tomcat/trunk/java/javax/el/StandardELContext.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org