Author: markt Date: Wed Jul 3 12:45:46 2013 New Revision: 1499371 URL: http://svn.apache.org/r1499371 Log: EL 3.0 Implement new EvaluationListener class Create new Util class Refactor i18n support
Added: tomcat/trunk/java/javax/el/EvaluationListener.java (with props) tomcat/trunk/java/javax/el/Util.java (with props) Modified: tomcat/trunk/java/javax/el/ArrayELResolver.java tomcat/trunk/java/javax/el/BeanELResolver.java tomcat/trunk/java/javax/el/ELContext.java tomcat/trunk/java/javax/el/ELResolver.java tomcat/trunk/java/javax/el/ImportHandler.java tomcat/trunk/java/javax/el/ListELResolver.java tomcat/trunk/java/javax/el/MapELResolver.java tomcat/trunk/java/javax/el/ResourceBundleELResolver.java Modified: tomcat/trunk/java/javax/el/ArrayELResolver.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/ArrayELResolver.java?rev=1499371&r1=1499370&r2=1499371&view=diff ============================================================================== --- tomcat/trunk/java/javax/el/ArrayELResolver.java (original) +++ tomcat/trunk/java/javax/el/ArrayELResolver.java Wed Jul 3 12:45:46 2013 @@ -83,7 +83,7 @@ public class ArrayELResolver extends ELR context.setPropertyResolved(true); if (this.readOnly) { - throw new PropertyNotWritableException(message(context, + throw new PropertyNotWritableException(Util.message(context, "resolverNotWriteable", base.getClass().getName())); } @@ -92,7 +92,7 @@ public class ArrayELResolver extends ELR if (value != null && !base.getClass().getComponentType().isAssignableFrom( value.getClass())) { - throw new ClassCastException(message(context, + throw new ClassCastException(Util.message(context, "objectNotAssignable", value.getClass().getName(), base.getClass().getComponentType().getName())); } Modified: tomcat/trunk/java/javax/el/BeanELResolver.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/BeanELResolver.java?rev=1499371&r1=1499370&r2=1499371&view=diff ============================================================================== --- tomcat/trunk/java/javax/el/BeanELResolver.java (original) +++ tomcat/trunk/java/javax/el/BeanELResolver.java Wed Jul 3 12:45:46 2013 @@ -109,7 +109,7 @@ public class BeanELResolver extends ELRe if (cause instanceof VirtualMachineError) { throw (VirtualMachineError) cause; } - throw new ELException(message(context, "propertyReadError", + throw new ELException(Util.message(context, "propertyReadError", base.getClass().getName(), property.toString()), cause); } catch (Exception e) { throw new ELException(e); @@ -131,7 +131,7 @@ public class BeanELResolver extends ELRe context.setPropertyResolved(true); if (this.readOnly) { - throw new PropertyNotWritableException(message(context, + throw new PropertyNotWritableException(Util.message(context, "resolverNotWriteable", base.getClass().getName())); } @@ -148,7 +148,7 @@ public class BeanELResolver extends ELRe if (cause instanceof VirtualMachineError) { throw (VirtualMachineError) cause; } - throw new ELException(message(context, "propertyWriteError", + throw new ELException(Util.message(context, "propertyWriteError", base.getClass().getName(), property.toString()), cause); } catch (Exception e) { throw new ELException(e); @@ -338,7 +338,7 @@ public class BeanELResolver extends ELRe private BeanProperty get(ELContext ctx, String name) { BeanProperty property = this.properties.get(name); if (property == null) { - throw new PropertyNotFoundException(message(ctx, + throw new PropertyNotFoundException(Util.message(ctx, "propertyNotFound", type.getName(), name)); } return property; @@ -393,7 +393,7 @@ public class BeanELResolver extends ELRe if (this.write == null) { this.write = getMethod(this.owner, descriptor.getWriteMethod()); if (this.write == null) { - throw new PropertyNotFoundException(message(ctx, + throw new PropertyNotFoundException(Util.message(ctx, "propertyNotWritable", new Object[] { owner.getName(), descriptor.getName() })); } @@ -405,7 +405,7 @@ public class BeanELResolver extends ELRe if (this.read == null) { this.read = getMethod(this.owner, descriptor.getReadMethod()); if (this.read == null) { - throw new PropertyNotFoundException(message(ctx, + throw new PropertyNotFoundException(Util.message(ctx, "propertyNotReadable", new Object[] { owner.getName(), descriptor.getName() })); } Modified: tomcat/trunk/java/javax/el/ELContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/ELContext.java?rev=1499371&r1=1499370&r2=1499371&view=diff ============================================================================== --- tomcat/trunk/java/javax/el/ELContext.java (original) +++ tomcat/trunk/java/javax/el/ELContext.java Wed Jul 3 12:45:46 2013 @@ -16,7 +16,9 @@ */ package javax.el; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; @@ -28,6 +30,10 @@ public abstract class ELContext { private boolean resolved; + private ImportHandler importHandler = null; + + private List<EvaluationListener> listeners = new ArrayList<>(); + public ELContext() { this.resolved = false; } @@ -36,6 +42,14 @@ public abstract class ELContext { this.resolved = resolved; } + /** + * @since EL 3.0 + */ + public void setPropertyResolved(Object base, Object property) { + setPropertyResolved(true); + notifyPropertyResolved(base, property); + } + public boolean isPropertyResolved() { return this.resolved; } @@ -64,6 +78,16 @@ public abstract class ELContext { public abstract ELResolver getELResolver(); + /** + * @since EL 3.0 + */ + public ImportHandler getImportHandler() { + if (importHandler == null) { + importHandler = new ImportHandler(); + } + return importHandler; + } + public abstract FunctionMapper getFunctionMapper(); public Locale getLocale() { @@ -75,4 +99,60 @@ public abstract class ELContext { } public abstract VariableMapper getVariableMapper(); + + /** + * @since EL 3.0 + */ + public void addEvaluationListener(EvaluationListener listener) { + listeners.add(listener); + } + + /** + * @since EL 3.0 + */ + public List<EvaluationListener> getEvaluationListeners() { + return listeners; + } + + /** + * @since EL 3.0 + */ + public void notifyBeforeEvaluation(String expression) { + for (EvaluationListener listener : listeners) { + try { + listener.beforeEvaluation(this, expression); + } catch (Throwable t) { + Util.handleThrowable(t); + // Ignore - no option to log + } + } + } + + /** + * @since EL 3.0 + */ + public void notifyAfterEvaluation(String expression) { + for (EvaluationListener listener : listeners) { + try { + listener.afterEvaluation(this, expression); + } catch (Throwable t) { + Util.handleThrowable(t); + // Ignore - no option to log + } + } + } + + /** + * @since EL 3.0 + */ + public void notifyPropertyResolved(Object base, Object property) { + for (EvaluationListener listener : listeners) { + try { + listener.propertyResolved(this, base, property); + } catch (Throwable t) { + Util.handleThrowable(t); + // Ignore - no option to log + } + } + } } Modified: tomcat/trunk/java/javax/el/ELResolver.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/ELResolver.java?rev=1499371&r1=1499370&r2=1499371&view=diff ============================================================================== --- tomcat/trunk/java/javax/el/ELResolver.java (original) +++ tomcat/trunk/java/javax/el/ELResolver.java Wed Jul 3 12:45:46 2013 @@ -14,14 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package javax.el; -import java.text.MessageFormat; import java.util.Iterator; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; /** * @author Jacob Hookom [jacob/hookom.net] @@ -29,31 +24,6 @@ import java.util.ResourceBundle; */ public abstract class ELResolver { - static String message(ELContext context, String name, Object... props) { - Locale locale = null; - if (context != null) { - locale = context.getLocale(); - } - if (locale == null) { - locale = Locale.getDefault(); - if (locale == null) { - return ""; - } - } - ResourceBundle bundle = ResourceBundle.getBundle( - "javax.el.LocalStrings", locale); - try { - String template = bundle.getString(name); - if (props != null) { - template = MessageFormat.format(template, props); - } - return template; - } catch (MissingResourceException e) { - return "Missing Resource: '" + name + "' for Locale " - + locale.getDisplayName(); - } - } - public static final String TYPE = "type"; public static final String RESOLVABLE_AT_DESIGN_TIME = "resolvableAtDesignTime"; Added: tomcat/trunk/java/javax/el/EvaluationListener.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/EvaluationListener.java?rev=1499371&view=auto ============================================================================== --- tomcat/trunk/java/javax/el/EvaluationListener.java (added) +++ tomcat/trunk/java/javax/el/EvaluationListener.java Wed Jul 3 12:45:46 2013 @@ -0,0 +1,54 @@ +/* + * 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; + +/** + * @since EL 3.0 + */ +public abstract class EvaluationListener { + + /** + * Fired before the evaluation of the expression. + * + * @param context + * @param expression + */ + public void beforeEvaluation(ELContext context, String expression) { + // NO-OP + } + + /** + * Fired after the evaluation of the expression. + * + * @param context + * @param expression + */ + public void afterEvaluation(ELContext context, String expression) { + // NO-OP + } + + /** + * Fired after a property has been resolved. + * + * @param context + * @param base + * @param property + */ + public void propertyResolved(ELContext context, Object base, Object property) { + // NO-OP + } +} Propchange: tomcat/trunk/java/javax/el/EvaluationListener.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/java/javax/el/ImportHandler.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/ImportHandler.java?rev=1499371&r1=1499370&r2=1499371&view=diff ============================================================================== --- tomcat/trunk/java/javax/el/ImportHandler.java (original) +++ tomcat/trunk/java/javax/el/ImportHandler.java Wed Jul 3 12:45:46 2013 @@ -43,7 +43,7 @@ public class ImportHandler { int lastPeriod = name.lastIndexOf('.'); if (lastPeriod < 0) { - throw new ELException(ELResolver.message( + throw new ELException(Util.message( null, "importHandler.invalidStaticName", name)); } @@ -53,7 +53,7 @@ public class ImportHandler { Class<?> clazz = findClass(className); if (clazz == null) { - throw new ELException(ELResolver.message( + throw new ELException(Util.message( null, "importHandler.invalidClassNameForStatic", className, name)); } @@ -77,14 +77,14 @@ public class ImportHandler { } if (!found) { - throw new ELException(ELResolver.message(null, + throw new ELException(Util.message(null, "importHandler.staticNotFound", fieldOrMethodName, className, name)); } Class<?> conflict = statics.get(fieldOrMethodName); if (conflict != null) { - throw new ELException(ELResolver.message(null, + throw new ELException(Util.message(null, "importHandler.ambiguousStaticImport", name, conflict.getName() + '.' + fieldOrMethodName)); } @@ -95,14 +95,14 @@ public class ImportHandler { public void importClass(String name) throws javax.el.ELException { if (!name.contains(".")) { - throw new ELException(ELResolver.message( + throw new ELException(Util.message( null, "importHandler.invalidClassName", name)); } Class<?> clazz = findClass(name); if (clazz == null) { - throw new ELException(ELResolver.message( + throw new ELException(Util.message( null, "importHandler.classNotFound", name)); } } @@ -112,7 +112,7 @@ public class ImportHandler { // Import ambiguity is handled at resolution, not at import Package p = Package.getPackage(name); if (p == null) { - throw new IllegalArgumentException(ELResolver.message( + throw new IllegalArgumentException(Util.message( null, "importHandler.invalidPackage", name)); } packages.add(name); @@ -154,7 +154,7 @@ public class ImportHandler { int modifiers = clazz.getModifiers(); if (!Modifier.isPublic(modifiers) || Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) { - throw new ELException(ELResolver.message( + throw new ELException(Util.message( null, "importHandler.invalidClass", name)); } @@ -162,7 +162,7 @@ public class ImportHandler { Class<?> conflict = clazzes.get(simpleName); if (conflict != null) { - throw new ELException(ELResolver.message(null, + throw new ELException(Util.message(null, "importHandler.ambiguousImport", name, conflict.getName())); } Modified: tomcat/trunk/java/javax/el/ListELResolver.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/ListELResolver.java?rev=1499371&r1=1499370&r2=1499371&view=diff ============================================================================== --- tomcat/trunk/java/javax/el/ListELResolver.java (original) +++ tomcat/trunk/java/javax/el/ListELResolver.java Wed Jul 3 12:45:46 2013 @@ -95,7 +95,7 @@ public class ListELResolver extends ELRe List<Object> list = (List<Object>) base; if (this.readOnly) { - throw new PropertyNotWritableException(message(context, + throw new PropertyNotWritableException(Util.message(context, "resolverNotWriteable", base.getClass().getName())); } Modified: tomcat/trunk/java/javax/el/MapELResolver.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/MapELResolver.java?rev=1499371&r1=1499370&r2=1499371&view=diff ============================================================================== --- tomcat/trunk/java/javax/el/MapELResolver.java (original) +++ tomcat/trunk/java/javax/el/MapELResolver.java Wed Jul 3 12:45:46 2013 @@ -83,7 +83,7 @@ public class MapELResolver extends ELRes context.setPropertyResolved(true); if (this.readOnly) { - throw new PropertyNotWritableException(message(context, + throw new PropertyNotWritableException(Util.message(context, "resolverNotWriteable", base.getClass().getName())); } Modified: tomcat/trunk/java/javax/el/ResourceBundleELResolver.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/ResourceBundleELResolver.java?rev=1499371&r1=1499370&r2=1499371&view=diff ============================================================================== --- tomcat/trunk/java/javax/el/ResourceBundleELResolver.java (original) +++ tomcat/trunk/java/javax/el/ResourceBundleELResolver.java Wed Jul 3 12:45:46 2013 @@ -81,7 +81,7 @@ public class ResourceBundleELResolver ex if (base instanceof ResourceBundle) { context.setPropertyResolved(true); - throw new PropertyNotWritableException(message(context, + throw new PropertyNotWritableException(Util.message(context, "resolverNotWriteable", base.getClass().getName())); } } Added: tomcat/trunk/java/javax/el/Util.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/Util.java?rev=1499371&view=auto ============================================================================== --- tomcat/trunk/java/javax/el/Util.java (added) +++ tomcat/trunk/java/javax/el/Util.java Wed Jul 3 12:45:46 2013 @@ -0,0 +1,67 @@ +/* + * 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.text.MessageFormat; +import java.util.Locale; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +class Util { + + /** + * Checks whether the supplied Throwable is one that needs to be + * rethrown and swallows all others. + * @param t the Throwable to check + */ + static void handleThrowable(Throwable t) { + if (t instanceof ThreadDeath) { + throw (ThreadDeath) t; + } + if (t instanceof VirtualMachineError) { + throw (VirtualMachineError) t; + } + // All other instances of Throwable will be silently swallowed + } + + static String message(ELContext context, String name, Object... props) { + Locale locale = null; + if (context != null) { + locale = context.getLocale(); + } + if (locale == null) { + locale = Locale.getDefault(); + if (locale == null) { + return ""; + } + } + ResourceBundle bundle = ResourceBundle.getBundle( + "javax.el.LocalStrings", locale); + try { + String template = bundle.getString(name); + if (props != null) { + template = MessageFormat.format(template, props); + } + return template; + } catch (MissingResourceException e) { + return "Missing Resource: '" + name + "' for Locale " + + locale.getDisplayName(); + } + } + + +} Propchange: tomcat/trunk/java/javax/el/Util.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org