You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by jw...@apache.org on 2007/08/09 17:44:01 UTC
svn commit: r564247 - in
/myfaces/trinidad/branches/1.2.2-branch/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config:
ConfigParser.java LazyValueBinding.java LazyValueExpression.java
Author: jwaldman
Date: Thu Aug 9 08:44:01 2007
New Revision: 564247
URL: http://svn.apache.org/viewvc?view=rev&rev=564247
Log:
https://issues.apache.org/jira/browse/TRINIDAD-145
Added:
myfaces/trinidad/branches/1.2.2-branch/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/LazyValueExpression.java
Removed:
myfaces/trinidad/branches/1.2.2-branch/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/LazyValueBinding.java
Modified:
myfaces/trinidad/branches/1.2.2-branch/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/ConfigParser.java
Modified: myfaces/trinidad/branches/1.2.2-branch/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/ConfigParser.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.2-branch/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/ConfigParser.java?view=diff&rev=564247&r1=564246&r2=564247
==============================================================================
--- myfaces/trinidad/branches/1.2.2-branch/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/ConfigParser.java (original)
+++ myfaces/trinidad/branches/1.2.2-branch/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/ConfigParser.java Thu Aug 9 08:44:01 2007
@@ -24,6 +24,8 @@
import java.util.Map;
import java.util.TimeZone;
+import javax.el.ValueExpression;
+
import javax.faces.context.ExternalContext;
import javax.faces.el.ValueBinding;
import javax.xml.parsers.ParserConfigurationException;
@@ -189,9 +191,11 @@
}
else
{
- ValueBinding binding =
- LazyValueBinding.createValueBinding(_currentText);
- _bean.setValueBinding(key, binding);
+
+ ValueExpression expression =
+ LazyValueExpression.createValueExpression(_currentText,
+ key.getType());
+ _bean.setValueExpression(key, expression);
}
}
else
Added: myfaces/trinidad/branches/1.2.2-branch/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/LazyValueExpression.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.2-branch/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/LazyValueExpression.java?view=auto&rev=564247
==============================================================================
--- myfaces/trinidad/branches/1.2.2-branch/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/LazyValueExpression.java (added)
+++ myfaces/trinidad/branches/1.2.2-branch/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/LazyValueExpression.java Thu Aug 9 08:44:01 2007
@@ -0,0 +1,225 @@
+/*
+ * 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 org.apache.myfaces.trinidadinternal.config;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.FunctionMapper;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.context.FacesContext;
+import javax.el.ValueExpression;
+
+import javax.el.VariableMapper;
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+
+ /**
+ * A ValueExpression class that lazily parses the underlying EL expression
+ * (in case the Application object is not yet available). Unfortunately,
+ * this implementation means that errors in the syntax of the EL
+ * expression won't get detected until use.
+ *
+ */
+class LazyValueExpression extends ValueExpression
+{
+
+ /**
+ * Create a ValueExpression
+ */
+ static public ValueExpression createValueExpression(
+ String expression,
+ Class<?> expectedType)
+ {
+ // Try to create the ValueExpression from the Application object
+ // This will return null if the ApplicationFactory or Application
+ // objects are null.
+ ValueExpression valueExpression=
+ _createValueExpressionFromApplication(expression, expectedType);
+
+ if (valueExpression != null)
+ return valueExpression;
+
+ // We couldn't create a regular ValueExpression, so create a
+ // LazyValueExpression. This will try to create a regular
+ // ValueExpression later when a 'get' method is called.
+ return new LazyValueExpression(expression, expectedType);
+ }
+
+ @Override
+ public Object getValue(ELContext context)
+ {
+ return _getValueExpression().getValue(context);
+ }
+
+ @Override
+ public void setValue(ELContext context, java.lang.Object value)
+ {
+ _getValueExpression().setValue(context, value);
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext context)
+ {
+ return _getValueExpression().isReadOnly(context);
+ }
+
+ @Override
+ public java.lang.Class<?> getType(ELContext context)
+ {
+ return _getValueExpression().getType(context);
+ }
+
+ @Override
+ public java.lang.Class<?> getExpectedType()
+ {
+ return _expectedType;
+ }
+
+ @Override
+ public String getExpressionString()
+ {
+ return _expression;
+ }
+
+ @Override
+ public boolean isLiteralText()
+ {
+ return _getValueExpression().isLiteralText();
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ return _getValueExpression().equals(o);
+ }
+
+ @Override
+ public int hashCode ()
+ {
+ return _getValueExpression().hashCode();
+ }
+
+ private LazyValueExpression(
+ String expression,
+ Class<?> expectedType)
+ {
+ _expression = expression;
+ _expectedType = expectedType;
+
+ }
+
+ // Get the ELContext off of the FacesContext, if the FacesContext is not
+ // null. Otherwise, create a dummy ELContext and return that.
+ private static ELContext _getELContext(Application application)
+ {
+ FacesContext fContext = FacesContext.getCurrentInstance();
+
+ if (fContext != null)
+ {
+ return fContext.getELContext();
+ }
+ else
+ {
+ // use a dummy ELContext if FacesContext is null
+ return new MockELContext(application);
+ }
+ }
+
+ // This is called from the LazyValueExpression's 'get' methods.
+ // It will try to create a ValueExpression from the Application object
+ // if it hasn't done so already.
+ private ValueExpression _getValueExpression()
+ {
+
+ if (_valueExpression == null)
+ {
+ _valueExpression =
+ _createValueExpressionFromApplication(_expression, _expectedType);
+ }
+
+ return _valueExpression;
+ }
+
+ // Create a ValueExpression object from the Application object, if the
+ // ApplicationFactory and Application objects exist, and return it.
+ // Otherwise, return null.
+ private static ValueExpression _createValueExpressionFromApplication(
+ String expression,
+ Class<?> expectedType)
+ {
+ ApplicationFactory factory = (ApplicationFactory)
+ FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ if (factory != null)
+ {
+ Application application = factory.getApplication();
+ if (application != null)
+ {
+ ELContext elContext = _getELContext(application);
+
+ return
+ application.getExpressionFactory().
+ createValueExpression(elContext, expression, expectedType);
+
+ }
+ }
+
+ return null;
+ }
+
+ // This is used to mock up a dummy ELContext to pass into createValueExpression
+ // if the FacesContext is null and we can't get FacesContext.getELContext.
+ private static class MockELContext extends ELContext
+ {
+ public MockELContext(Application application)
+ {
+ _resolver = application.getELResolver();
+ }
+
+ @Override
+ public ELResolver getELResolver()
+ {
+ return _resolver;
+ }
+
+ @Override
+ public FunctionMapper getFunctionMapper()
+ {
+ return null;
+ }
+
+ @Override
+ public VariableMapper getVariableMapper()
+ {
+ return null;
+ }
+
+ private final ELResolver _resolver;
+ }
+
+
+ private ValueExpression _valueExpression;
+ private final String _expression;
+ private final Class<?> _expectedType;
+
+
+ static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(LazyValueExpression.class);
+}