You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ss...@apache.org on 2006/05/29 05:59:49 UTC
svn commit: r410018 [3/4] - in /myfaces/core/trunk:
api/src/main/java/javax/faces/application/
api/src/main/java/javax/faces/component/
api/src/main/java/javax/faces/context/
api/src/main/java/javax/faces/convert/ api/src/main/java/javax/faces/el/
api/...
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/ELResolverToPropertyResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/ELResolverToPropertyResolver.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/ELResolverToPropertyResolver.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/ELResolverToPropertyResolver.java Sun May 28 20:59:46 2006
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.convert;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ELResolver;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
+import javax.faces.el.PropertyResolver;
+
+/**
+ *
+ * @author Stan Silvert
+ */
+public class ELResolverToPropertyResolver extends PropertyResolver {
+
+ private ELResolver elResolver;
+
+ /**
+ * Creates a new instance of ELResolverToPropertyResolver
+ */
+ public ELResolverToPropertyResolver(ELResolver elResolver) {
+ this.elResolver = elResolver;
+ }
+
+ public boolean isReadOnly(Object base, int index)
+ throws EvaluationException, PropertyNotFoundException {
+
+ try {
+ return elResolver.isReadOnly(elContext(), base, new Integer(index));
+ } catch (javax.el.PropertyNotFoundException e) {
+ throw new javax.faces.el.PropertyNotFoundException(e);
+ } catch (ELException e) {
+ throw new EvaluationException(e);
+ }
+
+ }
+
+ public boolean isReadOnly(Object base, Object property)
+ throws EvaluationException, PropertyNotFoundException {
+
+ try {
+ return elResolver.isReadOnly(elContext(), base, property);
+ } catch (javax.el.PropertyNotFoundException e) {
+ throw new javax.faces.el.PropertyNotFoundException(e);
+ } catch (ELException e) {
+ throw new EvaluationException(e);
+ }
+
+ }
+
+ public Object getValue(Object base, int index)
+ throws EvaluationException, PropertyNotFoundException {
+
+ try {
+ return elResolver.getValue(elContext(), base, new Integer(index));
+ } catch (javax.el.PropertyNotFoundException e) {
+ throw new javax.faces.el.PropertyNotFoundException(e);
+ } catch (ELException e) {
+ throw new EvaluationException(e);
+ }
+
+ }
+
+ public Object getValue(Object base, Object property)
+ throws EvaluationException, PropertyNotFoundException {
+
+ try {
+ return elResolver.getValue(elContext(), base, property);
+ } catch (javax.el.PropertyNotFoundException e) {
+ throw new javax.faces.el.PropertyNotFoundException(e);
+ } catch (ELException e) {
+ throw new EvaluationException(e);
+ }
+ }
+
+ public Class getType(Object base, int index)
+ throws EvaluationException, PropertyNotFoundException {
+
+ try {
+ return elResolver.getType(elContext(), base, new Integer(index));
+ } catch (javax.el.PropertyNotFoundException e) {
+ throw new javax.faces.el.PropertyNotFoundException(e);
+ } catch (ELException e) {
+ throw new EvaluationException(e);
+ }
+ }
+
+ public Class getType(Object base, Object property)
+ throws EvaluationException, PropertyNotFoundException {
+
+ try {
+ return elResolver.getType(elContext(), base, property);
+ } catch (javax.el.PropertyNotFoundException e) {
+ throw new javax.faces.el.PropertyNotFoundException(e);
+ } catch (ELException e) {
+ throw new EvaluationException(e);
+ }
+ }
+
+ public void setValue(Object base, Object property, Object value)
+ throws EvaluationException, PropertyNotFoundException {
+
+ try {
+ elResolver.setValue(elContext(), base, property, value);
+ } catch (javax.el.PropertyNotFoundException e) {
+ throw new javax.faces.el.PropertyNotFoundException(e);
+ } catch (ELException e) {
+ throw new EvaluationException(e);
+ }
+ }
+
+ public void setValue(Object base, int index, Object value)
+ throws EvaluationException, PropertyNotFoundException {
+
+ try {
+ elResolver.setValue(elContext(), base, new Integer(index), value);
+ } catch (javax.el.PropertyNotFoundException e) {
+ throw new javax.faces.el.PropertyNotFoundException(e);
+ } catch (ELException e) {
+ throw new EvaluationException(e);
+ }
+
+ }
+
+ private ELContext elContext() {
+ return FacesContext.getCurrentInstance().getELContext();
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/ELResolverToVariableResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/ELResolverToVariableResolver.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/ELResolverToVariableResolver.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/ELResolverToVariableResolver.java Sun May 28 20:59:46 2006
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.convert;
+
+import javax.el.ELException;
+import javax.el.ELResolver;
+import javax.el.PropertyNotFoundException;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.VariableResolver;
+
+/**
+ * Provides ELResolver wrapper so that legacy apps which rely on a
+ * VariableResolver can still work.
+ *
+ * @author Stan Silvert
+ */
+public class ELResolverToVariableResolver extends VariableResolver {
+
+ private ELResolver elResolver;
+
+ /**
+ * Creates a new instance of ELResolverToVariableResolver
+ */
+ public ELResolverToVariableResolver(ELResolver elResolver) {
+ if (elResolver == null) throw new NullPointerException();
+ this.elResolver = elResolver;
+ }
+
+ public Object resolveVariable(FacesContext facesContext, String name) throws EvaluationException {
+
+ try {
+ return elResolver.getValue(facesContext.getELContext(), null, name);
+ } catch (PropertyNotFoundException e) {
+ throw new EvaluationException(e);
+ } catch (ELException e) {
+ throw new EvaluationException(e);
+ }
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodBindingToActionListener.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodBindingToActionListener.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodBindingToActionListener.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodBindingToActionListener.java Sun May 28 20:59:46 2006
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.convert;
+
+import javax.faces.el.MethodBinding;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.ActionListener;
+
+/**
+ * Converts a MethodBinding to an ActionListener
+ *
+ * @author Stan Silvert
+ */
+public class MethodBindingToActionListener extends MethodBindingToListener implements ActionListener {
+
+ public MethodBindingToActionListener() {
+ super();
+ }
+
+ public MethodBindingToActionListener(MethodBinding methodBinding) {
+ super(methodBinding);
+ }
+
+ public void processAction(ActionEvent actionEvent) throws AbortProcessingException {
+ invokeMethodBinding(actionEvent);
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodBindingToListener.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodBindingToListener.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodBindingToListener.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodBindingToListener.java Sun May 28 20:59:46 2006
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.convert;
+
+import javax.faces.FacesException;
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.MethodBinding;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
+
+/**
+ * Common base class for converting a MethodBinding to a FacesListener
+ *
+ * @author Stan Silvert
+ */
+public abstract class MethodBindingToListener implements StateHolder {
+
+ protected MethodBinding methodBinding;
+
+ public MethodBindingToListener() {
+ }
+
+ /**
+ * Creates a new instance of MethodBindingToListener
+ */
+ public MethodBindingToListener(MethodBinding methodBinding) {
+ if (methodBinding == null) throw new NullPointerException("methodBinding can not be null");
+ if (!(methodBinding instanceof StateHolder)) throw new IllegalArgumentException("methodBinding must implement the StateHolder interface");
+
+ this.methodBinding = methodBinding;
+ }
+
+ private FacesContext getFacesContext() {
+ return FacesContext.getCurrentInstance();
+ }
+
+ protected void invokeMethodBinding(FacesEvent event) throws AbortProcessingException {
+ try {
+ methodBinding.invoke(getFacesContext(), new Object[] {event});
+ }
+ catch (EvaluationException e) {
+ Throwable cause = e.getCause();
+ if (cause != null && cause instanceof AbortProcessingException) {
+ throw (AbortProcessingException)cause;
+ }
+
+ throw e;
+ }
+ }
+
+ public MethodBinding getMethodBinding() {
+ return methodBinding;
+ }
+
+ public void restoreState(FacesContext context, Object state) {
+ Object[] stateArray = (Object[])state;
+ try {
+ methodBinding = (MethodBinding)Thread.currentThread()
+ .getContextClassLoader()
+ .loadClass((String)stateArray[0])
+ .newInstance();
+ } catch (Exception e) {
+ throw new FacesException(e);
+ }
+
+ ((StateHolder)methodBinding).restoreState(context, stateArray[1]);
+ }
+
+ public Object saveState(FacesContext context) {
+ Object[] stateArray = new Object[2];
+ stateArray[0] = methodBinding.getClass().getName();
+ stateArray[1] = ((StateHolder)methodBinding).saveState(context);
+ return stateArray;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ ((StateHolder)methodBinding).setTransient(newTransientValue);
+ }
+
+ public boolean isTransient() {
+ return ((StateHolder)methodBinding).isTransient();
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodBindingToMethodExpression.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodBindingToMethodExpression.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodBindingToMethodExpression.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodBindingToMethodExpression.java Sun May 28 20:59:46 2006
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.convert;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ExpressionFactory;
+import javax.el.MethodExpression;
+import javax.el.MethodInfo;
+import javax.el.MethodNotFoundException;
+import javax.el.PropertyNotFoundException;
+import javax.faces.FacesException;
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.el.MethodBinding;
+
+/**
+ * Converts a MethodBinding to a MethodExpression
+ *
+ * @author Stan Silvert
+ */
+public class MethodBindingToMethodExpression extends MethodExpression implements StateHolder {
+
+ private static final ExpressionFactory expFactory;
+
+ static {
+ ApplicationFactory appFactory =
+ (ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ Application application = appFactory.getApplication();
+ expFactory = application.getExpressionFactory();
+ }
+
+ private MethodBinding methodBinding;
+
+ private MethodExpression methodExpression;
+ private boolean paramTypesKnown = false;
+
+ /**
+ * No-arg constructor used during restoreState
+ */
+ public MethodBindingToMethodExpression() {
+
+ }
+
+ /** Creates a new instance of MethodBindingToMethodExpression */
+ public MethodBindingToMethodExpression(MethodBinding methodBinding) {
+ this.methodBinding = methodBinding;
+
+ if (!(methodBinding instanceof StateHolder)) {
+ throw new IllegalArgumentException("methodBinding must be an instance of StateHolder");
+ }
+
+ // We can't determine the expectecParamTypes from the MethodBinding
+ // until someone calls invoke.
+ // Therefore, we will just create a new one when invoke is called.
+ methodExpression = makeMethodExpression(methodBinding, new Class[0]);
+ }
+
+ private MethodExpression makeMethodExpression(MethodBinding methodBinding, Class[] expectedParamTypes) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ String expressionString = methodBinding.getExpressionString();
+ if (expressionString == null) expressionString = "null";
+ return expFactory.createMethodExpression(facesContext.getELContext(),
+ expressionString,
+ methodBinding.getType(facesContext),
+ expectedParamTypes);
+ }
+
+ /**
+ * Return the wrapped MethodBinding.
+ */
+ public MethodBinding getMethodBinding() {
+ return methodBinding;
+ }
+
+ /**
+ * Note: MethodInfo.getParamTypes() may incorrectly return an empty
+ * class array if invoke() has not been called.
+ *
+ * @throws IllegalStateException if expected params types have not been determined.
+ */
+ public MethodInfo getMethodInfo(ELContext context)
+ throws NullPointerException, PropertyNotFoundException, MethodNotFoundException, ELException {
+
+ if (!paramTypesKnown) throw new IllegalStateException("MethodInfo unavailable until invoke is called.");
+
+ return methodExpression.getMethodInfo(context);
+ }
+
+ public Object invoke(ELContext context, Object[] params)
+ throws NullPointerException, PropertyNotFoundException, MethodNotFoundException, ELException {
+
+ if (!paramTypesKnown) {
+ Class[] paramTypes = findParamTypes(params);
+ methodExpression = makeMethodExpression(methodBinding, paramTypes);
+ paramTypesKnown = true;
+ }
+
+ return methodExpression.invoke(context, params);
+ }
+
+ private Class[] findParamTypes(Object[] params) {
+ Class[] paramTypes = new Class[params.length];
+ for (int i = 0; i < params.length; i++) {
+ paramTypes[i] = params[i].getClass();
+ }
+
+ return paramTypes;
+ }
+
+ public boolean isLiteralText() {
+ return methodExpression.isLiteralText();
+ }
+
+ public String getExpressionString() {
+ return methodExpression.getExpressionString();
+ }
+
+ public boolean equals(Object obj) {
+ return methodExpression.equals(obj);
+ }
+
+ public int hashCode() {
+ return methodExpression.hashCode();
+ }
+
+ public void restoreState(FacesContext context, Object state) {
+ Object[] stateArray = (Object[])state;
+ try {
+ methodBinding = (MethodBinding)Thread.currentThread()
+ .getContextClassLoader()
+ .loadClass((String)stateArray[0])
+ .newInstance();
+ } catch (Exception e) {
+ throw new FacesException(e);
+ }
+
+ ((StateHolder)methodBinding).restoreState(context, stateArray[1]);
+ paramTypesKnown = ((Boolean)stateArray[2]).booleanValue();
+ methodExpression = makeMethodExpression(methodBinding, (Class[])stateArray[3]);
+ }
+
+ public Object saveState(FacesContext context) {
+ Object[] state = new Object[4];
+ state[0] = methodBinding.getClass().getName();
+ state[1] = ((StateHolder)methodBinding).saveState(context);
+ state[2] = Boolean.valueOf(paramTypesKnown);
+ state[3] = methodExpression.getMethodInfo(context.getELContext()).getParamTypes();
+ return state;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ ((StateHolder)methodBinding).setTransient(newTransientValue);
+ }
+
+ public boolean isTransient() {
+ return ((StateHolder)methodBinding).isTransient();
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodBindingToValueChangeListener.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodBindingToValueChangeListener.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodBindingToValueChangeListener.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodBindingToValueChangeListener.java Sun May 28 20:59:46 2006
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.convert;
+
+import javax.faces.el.MethodBinding;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ValueChangeEvent;
+import javax.faces.event.ValueChangeListener;
+
+/**
+ * Converts a MethodBinding to a ValueChangeListener
+ *
+ * @author Stan Silvert
+ */
+public class MethodBindingToValueChangeListener extends MethodBindingToListener implements ValueChangeListener {
+
+ public MethodBindingToValueChangeListener() {
+ super();
+ }
+
+ public MethodBindingToValueChangeListener(MethodBinding methodBinding) {
+ super(methodBinding);
+ }
+
+ public void processValueChange(ValueChangeEvent event) throws AbortProcessingException {
+ invokeMethodBinding(event);
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodExpressionToMethodBinding.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodExpressionToMethodBinding.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodExpressionToMethodBinding.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/MethodExpressionToMethodBinding.java Sun May 28 20:59:46 2006
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.convert;
+
+import javax.el.ELException;
+import javax.el.MethodExpression;
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.MethodBinding;
+import javax.faces.el.MethodNotFoundException;
+
+/**
+ * Converts a MethodExpression to a MethodBinding.
+ * See JSF 1.2 spec section 5.8.4
+ *
+ * @author Stan Silvert
+ */
+public class MethodExpressionToMethodBinding extends MethodBinding implements StateHolder {
+
+ private MethodExpression methodExpression;
+
+ private boolean isTransient = false;
+
+ public MethodExpressionToMethodBinding() {
+ methodExpression = null;
+ }
+
+ /** Creates a new instance of MethodExpressionToMethodBinding */
+ public MethodExpressionToMethodBinding(MethodExpression methodExpression) {
+ this.methodExpression = methodExpression;
+ }
+
+ public Class getType(FacesContext facesContext)
+ throws MethodNotFoundException {
+
+ try {
+ return methodExpression.getMethodInfo(facesContext.getELContext()).getReturnType();
+ } catch (javax.el.MethodNotFoundException e) {
+ throw new javax.faces.el.MethodNotFoundException(e);
+ }
+ }
+
+ public Object invoke(FacesContext facesContext, Object[] params)
+ throws EvaluationException, MethodNotFoundException {
+
+ try {
+ return methodExpression.invoke(facesContext.getELContext(), params);
+ } catch (javax.el.MethodNotFoundException e) {
+ throw new javax.faces.el.MethodNotFoundException(e);
+ } catch (ELException e) {
+ throw new EvaluationException(e);
+ }
+ }
+
+// -------- StateHolder methods -------------------------------------------
+
+ public void restoreState(FacesContext context, Object state) {
+ methodExpression = (MethodExpression)state;
+ }
+
+ public Object saveState(FacesContext context) {
+ return methodExpression;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ isTransient = newTransientValue;
+ }
+
+ public boolean isTransient() {
+ return isTransient;
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/PropertyResolverToELResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/PropertyResolverToELResolver.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/PropertyResolverToELResolver.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/PropertyResolverToELResolver.java Sun May 28 20:59:46 2006
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.convert;
+
+import java.util.Iterator;
+import java.util.List;
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ELResolver;
+import javax.el.ExpressionFactory;
+import javax.el.PropertyNotFoundException;
+import javax.el.PropertyNotWritableException;
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.el.PropertyResolver;
+
+/**
+ * Wrapper that converts a VariableResolver into an ELResolver.
+ * See JSF 1.2 spec section 5.6.1.6
+ *
+ * @author Stan Silvert
+ */
+public class PropertyResolverToELResolver extends ELResolver {
+ private PropertyResolver propertyResolver;
+
+ private ExpressionFactory expressionFactory;
+
+ /**
+ * Creates a new instance of PropertyResolverToELResolver
+ */
+ public PropertyResolverToELResolver(PropertyResolver propertyResolver) {
+ this.propertyResolver = propertyResolver;
+
+ ApplicationFactory appFactory = (ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ this.expressionFactory = appFactory.getApplication().getExpressionFactory();
+ }
+
+ public void setValue(ELContext context, Object base, Object property, Object value)
+ throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException {
+
+ if ( (base == null) || (property == null)) return;
+
+ context.setPropertyResolved(true);
+
+ try {
+ if (needsCoersion(base)) {
+ propertyResolver.setValue(base, coerceToInt(property), value);
+ return;
+ }
+
+ propertyResolver.setValue(base, property, value);
+
+ } catch (Exception e) {
+ context.setPropertyResolved(false);
+ throw new ELException(e);
+ }
+
+ }
+
+ public boolean isReadOnly(ELContext context, Object base, Object property)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ if ( (base == null) || (property == null)) return true;
+
+ context.setPropertyResolved(true);
+
+ try {
+ if (needsCoersion(base)) {
+ return propertyResolver.isReadOnly(base, coerceToInt(property));
+ }
+
+ return propertyResolver.isReadOnly(base, property);
+
+ } catch (Exception e) {
+ context.setPropertyResolved(false);
+ throw new ELException(e);
+ }
+ }
+
+ public Object getValue(ELContext context, Object base, Object property)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ if ( (base == null) || (property == null)) return null;
+
+ context.setPropertyResolved(true);
+
+ try {
+ if (needsCoersion(base)) {
+ return propertyResolver.getValue(base, coerceToInt(property));
+ }
+
+ return propertyResolver.getValue(base, property);
+
+ } catch (Exception e) {
+ context.setPropertyResolved(false);
+ throw new ELException(e);
+ }
+ }
+
+ public Class<?> getType(ELContext context, Object base, Object property)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ if ( (base == null) || (property == null)) return null;
+
+ context.setPropertyResolved(true);
+
+ try {
+ if (needsCoersion(base)) {
+ return propertyResolver.getType(base, coerceToInt(property));
+ }
+
+ return propertyResolver.getType(base, property);
+
+ } catch (Exception e) {
+ context.setPropertyResolved(false);
+ throw new ELException(e);
+ }
+ }
+
+ public Iterator getFeatureDescriptors(ELContext context, Object base) {
+
+ return null;
+ }
+
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+
+ if (base == null) return null;
+
+ return Object.class;
+ }
+
+ private boolean needsCoersion(Object base) {
+ return (base instanceof List) || base.getClass().isArray();
+ }
+
+ private int coerceToInt(Object property) throws Exception {
+ Integer coerced = (Integer)expressionFactory.coerceToType(property, Integer.class);
+ return coerced.intValue();
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/ValueBindingToValueExpression.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/ValueBindingToValueExpression.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/ValueBindingToValueExpression.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/ValueBindingToValueExpression.java Sun May 28 20:59:46 2006
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.convert;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ExpressionFactory;
+import javax.el.PropertyNotFoundException;
+import javax.el.PropertyNotWritableException;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+/**
+ * Wraps a ValueBinding inside a ValueExpression. Also allows access to
+ * the original ValueBinding object.
+ *
+ * Although ValueExpression implements Serializable, this class implements
+ * StateHolder instead.
+ *
+ * @author Stan Silvert
+ */
+public class ValueBindingToValueExpression extends ValueExpression implements StateHolder {
+
+
+ private static final ExpressionFactory expFactory;
+
+ static {
+ ApplicationFactory appFactory =
+ (ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ Application application = appFactory.getApplication();
+ expFactory = application.getExpressionFactory();
+ }
+
+ private ValueBinding valueBinding;
+
+ private ValueExpression valueExpression;
+
+ /**
+ * No-arg constructor used during restoreState
+ */
+ public ValueBindingToValueExpression() {
+
+ }
+
+ /** Creates a new instance of ValueBindingToValueExpression */
+ public ValueBindingToValueExpression(ValueBinding valueBinding) {
+
+ if (!(valueBinding instanceof StateHolder)) {
+ throw new IllegalArgumentException("valueBinding must be an instance of StateHolder");
+ }
+
+ this.valueBinding = valueBinding;
+ setValueExpression(valueBinding);
+ }
+
+
+ private void setValueExpression(ValueBinding valueBinding) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ String expressionString = valueBinding.getExpressionString();
+
+ // TODO: figure out if this is right. It seems to cause problems
+ // if I pass in the EL constant "null" as the expressionString
+ if (expressionString == null) expressionString = "";
+
+ valueExpression = expFactory.createValueExpression(facesContext.getELContext(),
+ expressionString,
+ valueBinding.getType(facesContext));
+ }
+
+ public ValueBinding getValueBinding() {
+ return valueBinding;
+ }
+
+ public boolean isReadOnly(ELContext context)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+ return valueExpression.isReadOnly(context);
+ }
+
+ public Object getValue(ELContext context)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ return valueExpression.getValue(context);
+ }
+
+ public Class<?> getType(ELContext context)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ return valueExpression.getType(context);
+ }
+
+ public void setValue(ELContext context, Object value)
+ throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException {
+
+ valueExpression.setValue(context, value);
+ }
+
+ public boolean equals(Object obj) {
+ return valueExpression.equals(obj);
+ }
+
+ public boolean isLiteralText() {
+ return valueExpression.isLiteralText();
+ }
+
+ public int hashCode() {
+ return valueExpression.hashCode();
+ }
+
+ public String getExpressionString() {
+ return valueExpression.getExpressionString();
+ }
+
+ public Class<?> getExpectedType() {
+ return valueExpression.getExpectedType();
+ }
+
+ public void restoreState(FacesContext context, Object state) {
+ Object[] stateArray = (Object[])state;
+ try {
+ valueBinding = (ValueBinding)Thread.currentThread()
+ .getContextClassLoader()
+ .loadClass((String)stateArray[0])
+ .newInstance();
+ } catch (Exception e) {
+ throw new FacesException(e);
+ }
+
+ ((StateHolder)valueBinding).restoreState(context, stateArray[1]);
+ setValueExpression(valueBinding);
+ }
+
+ public Object saveState(FacesContext context) {
+ Object[] state = new Object[2];
+ state[0] = valueBinding.getClass().getName();
+ state[1] = ((StateHolder)valueBinding).saveState(context);
+ return state;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ ((StateHolder)valueBinding).setTransient(newTransientValue);
+ }
+
+ public boolean isTransient() {
+ return ((StateHolder)valueBinding).isTransient();
+ }
+
+}
\ No newline at end of file
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/ValueExpressionToValueBinding.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/ValueExpressionToValueBinding.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/ValueExpressionToValueBinding.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/ValueExpressionToValueBinding.java Sun May 28 20:59:46 2006
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.convert;
+
+import javax.el.ELException;
+import javax.el.ExpressionFactory;
+import javax.el.ValueExpression;
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
+import javax.faces.el.ValueBinding;
+
+/**
+ * Converter for legacy ValueBinding objects. See JSF 1.2 section 5.8.3
+ *
+ * @author Stan Silvert
+ */
+public class ValueExpressionToValueBinding extends ValueBinding implements StateHolder {
+ private static final ExpressionFactory expFactory;
+
+ static {
+ ApplicationFactory appFactory =
+ (ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ Application application = appFactory.getApplication();
+ expFactory = application.getExpressionFactory();
+ }
+
+ private ValueExpression valueExpression;
+
+ private boolean isTransient = false;
+
+ // required no-arg constructor for StateHolder
+ public ValueExpressionToValueBinding() {
+ valueExpression = null;
+ }
+
+ /** Creates a new instance of ValueExpressionToValueBinding */
+ public ValueExpressionToValueBinding(ValueExpression valueExpression) {
+ this.valueExpression = valueExpression;
+ }
+
+ public void setValue(FacesContext facesContext, Object value)
+ throws EvaluationException, PropertyNotFoundException {
+
+ try {
+ valueExpression.setValue(facesContext.getELContext(), value);
+ } catch (javax.el.PropertyNotFoundException e) {
+ throw new javax.faces.el.PropertyNotFoundException(e);
+ } catch (ELException e) {
+ throw new EvaluationException(e);
+ }
+ }
+
+ public boolean isReadOnly(FacesContext facesContext)
+ throws EvaluationException, PropertyNotFoundException {
+
+ try {
+ return valueExpression.isReadOnly(facesContext.getELContext());
+ } catch (javax.el.PropertyNotFoundException e) {
+ throw new javax.faces.el.PropertyNotFoundException(e);
+ } catch (ELException e) {
+ throw new EvaluationException(e);
+ }
+
+ }
+
+ public Object getValue(FacesContext facesContext)
+ throws EvaluationException, PropertyNotFoundException {
+
+ try {
+ return valueExpression.getValue(facesContext.getELContext());
+ } catch (javax.el.PropertyNotFoundException e) {
+ throw new javax.faces.el.PropertyNotFoundException(e);
+ } catch (ELException e) {
+ throw new EvaluationException(e);
+ }
+ }
+
+ public Class getType(FacesContext facesContext)
+ throws EvaluationException, PropertyNotFoundException {
+
+ try {
+ return valueExpression.getExpectedType();
+ } catch (javax.el.PropertyNotFoundException e) {
+ throw new javax.faces.el.PropertyNotFoundException(e);
+ } catch (ELException e) {
+ throw new EvaluationException(e);
+ }
+ }
+
+// -------- StateHolder methods -------------------------------------------
+
+ public void restoreState(FacesContext facesContext, Object state) {
+ Object[] stateArray = (Object[])state;
+ String expressionString = (String)stateArray[0];
+ Class type = (Class)stateArray[1];
+ valueExpression = expFactory.createValueExpression(facesContext.getELContext(),
+ expressionString,
+ type);
+ }
+
+ public Object saveState(FacesContext context) {
+ Object[] stateArray = new Object[3];
+ stateArray[0] = valueExpression.getExpressionString();
+ stateArray[1] = valueExpression.getExpectedType();
+ return stateArray;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ isTransient = newTransientValue;
+ }
+
+ public boolean isTransient() {
+ return isTransient;
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/VariableResolverToELResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/VariableResolverToELResolver.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/VariableResolverToELResolver.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/convert/VariableResolverToELResolver.java Sun May 28 20:59:46 2006
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.convert;
+
+import java.util.Iterator;
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ELResolver;
+import javax.el.PropertyNotFoundException;
+import javax.el.PropertyNotWritableException;
+import javax.faces.context.FacesContext;
+import javax.faces.el.VariableResolver;
+
+/**
+ * Wrapper that converts a VariableResolver into an ELResolver.
+ * See JSF 1.2 spec section 5.6.1.5
+ *
+ * @author Stan Silvert
+ */
+public class VariableResolverToELResolver extends ELResolver {
+
+ private VariableResolver variableResolver;
+
+ /**
+ * Creates a new instance of VariableResolverToELResolver
+ */
+ public VariableResolverToELResolver(VariableResolver variableResolver) {
+ this.variableResolver = variableResolver;
+ }
+
+ public Object getValue(ELContext context, Object base, Object property)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ if (base != null) return null;
+ if (property == null) throw new PropertyNotFoundException();
+ if (! (property instanceof String)) return null;
+
+ String strProperty = (String)property;
+
+ // This differs from the spec slightly. I'm wondering if the spec is
+ // wrong because it is legal for the resolveVariable method to return
+ // null. In that case you would not want to setPropertyResolved(true).
+ try {
+ Object value = variableResolver.resolveVariable(facesContext(context), strProperty);
+ if (value != null) {
+ context.setPropertyResolved(true);
+ return value;
+ }
+ } catch (Exception e) {
+ context.setPropertyResolved(false);
+ throw new ELException(e);
+ }
+
+ return null;
+ }
+
+ // get the FacesContext from the ELContext
+ private FacesContext facesContext(ELContext context) {
+ return (FacesContext)context.getContext(FacesContext.class);
+ }
+
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+ if (base != null) return null;
+
+ return String.class;
+ }
+
+ public void setValue(ELContext context, Object base, Object property, Object value)
+ throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException {
+
+ if ( (base == null) && (property == null) ) throw new PropertyNotFoundException();
+ }
+
+ public boolean isReadOnly(ELContext context, Object base, Object property)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ if ( (base == null) && (property == null) ) throw new PropertyNotFoundException();
+
+ return false;
+ }
+
+ public Class<?> getType(ELContext context, Object base, Object property)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ if ( (base == null) && (property == null) ) throw new PropertyNotFoundException();
+
+ return null;
+ }
+
+ public Iterator getFeatureDescriptors(ELContext context, Object base) {
+ return null;
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/FacesELContext.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/FacesELContext.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/FacesELContext.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/FacesELContext.java Sun May 28 20:59:46 2006
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.unified;
+
+import java.util.Iterator;
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.FunctionMapper;
+import javax.el.VariableMapper;
+import javax.faces.context.FacesContext;
+import org.apache.el.lang.FunctionMapperImpl;
+import org.apache.el.lang.VariableMapperImpl;
+
+/**
+ * ELContext used for JSF.
+ *
+ * @author Stan Silvert
+ */
+public class FacesELContext extends ELContext {
+
+ private ELResolver elResolver;
+ private FunctionMapper functionMapper;
+ private VariableMapper variableMapper;
+
+ public FacesELContext(ELResolver elResolver,
+ FacesContext facesContext) {
+ this.elResolver = elResolver;
+ putContext(FacesContext.class, facesContext);
+
+ // TODO: decide if we need to implement our own FunctionMapperImpl and
+ // VariableMapperImpl instead of relying on Tomcat's version.
+ this.functionMapper = new FunctionMapperImpl();
+ this.variableMapper = new VariableMapperImpl();
+ }
+
+ public VariableMapper getVariableMapper() {
+ return variableMapper;
+ }
+
+ public FunctionMapper getFunctionMapper() {
+ return functionMapper;
+ }
+
+ public ELResolver getELResolver() {
+ return elResolver;
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ManagedBeanResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ManagedBeanResolver.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ManagedBeanResolver.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ManagedBeanResolver.java Sun May 28 20:59:46 2006
@@ -0,0 +1,279 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.unified.resolver;
+
+import java.beans.FeatureDescriptor;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ELResolver;
+import javax.el.PropertyNotFoundException;
+import javax.el.PropertyNotWritableException;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.config.ManagedBeanBuilder;
+import org.apache.myfaces.config.RuntimeConfig;
+import org.apache.myfaces.config.element.ManagedBean;
+
+/**
+ * See JSF 1.2 spec section 5.6.1.2
+ *
+ * @author Stan Silvert
+ */
+public class ManagedBeanResolver extends ELResolver {
+ private static final Log log = LogFactory.getLog(ManagedBeanResolver.class);
+ private static final String BEANS_UNDER_CONSTRUCTION = "org.apache.myfaces.el.unified.resolver.managedbean.beansUnderConstruction";
+
+ // adapted from Manfred's JSF 1.1 VariableResolverImpl
+ protected static final Map s_standardScopes = new HashMap(16);
+ static {
+ s_standardScopes.put(
+ "request",
+ new Scope()
+ {
+ public void put(ExternalContext extContext, String name, Object obj)
+ {
+ extContext.getRequestMap().put(name, obj);
+ }
+ });
+ s_standardScopes.put(
+ "session",
+ new Scope()
+ {
+ public void put(ExternalContext extContext, String name, Object obj)
+ {
+ extContext.getSessionMap().put(name, obj);
+ }
+ });
+ s_standardScopes.put(
+ "application",
+ new Scope()
+ {
+ public void put(ExternalContext extContext, String name, Object obj)
+ {
+ extContext.getApplicationMap().put(name, obj);
+ }
+ });
+ s_standardScopes.put(
+ "none",
+ new Scope()
+ {
+ public void put(ExternalContext extContext, String name, Object obj)
+ {
+ // do nothing
+ }
+ });
+ }
+
+ /**
+ * Stores all scopes defined for this instance of <code>VariableResolver</code>
+ * <p>
+ * Can store instances of <code>Scope</code> which have the ability to
+ * dynamically resolve against ExternalContext for put operations.
+ * </p>
+ * <p>
+ * WARNING: this implementation is not serialized as it is thread safe because
+ * it does not update/add to _scopes after object initialization.
+ * If you need to add your own scopes, either extend and add more
+ * in an initialization block, or add proper sychronization
+ * </p>
+ */
+ protected final Map _scopes = new HashMap(16);
+ {
+ _scopes.putAll(s_standardScopes);
+ }
+
+ /**
+ * RuntimeConfig is instantiated once per servlet and never changes--we can
+ * safely cache it
+ */
+ private RuntimeConfig runtimeConfig;
+
+ private ManagedBeanBuilder beanBuilder = new ManagedBeanBuilder();
+
+ /** Creates a new instance of ManagedBeanResolver */
+ public ManagedBeanResolver() {
+ }
+
+ public void setValue(ELContext context, Object base, Object property, Object value)
+ throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException {
+
+ if ( (base == null) && (property == null)) {
+ throw new PropertyNotFoundException();
+ }
+
+ }
+
+ public boolean isReadOnly(ELContext context, Object base, Object property)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ if ( (base == null) && (property == null)) {
+ throw new PropertyNotFoundException();
+ }
+
+ return false;
+ }
+
+ public Object getValue(ELContext context, Object base, Object property)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ if (base != null) return null;
+
+ if (property == null) {
+ throw new PropertyNotFoundException();
+ }
+
+ ExternalContext extContext = externalContext(context);
+
+ if (extContext.getRequestMap().containsKey(property)) return null;
+ if (extContext.getSessionMap().containsKey(property)) return null;
+ if (extContext.getApplicationMap().containsKey(property)) return null;
+
+ if ( !(property instanceof String) ) return null;
+
+ String strProperty = (String)property;
+
+ ManagedBean managedBean = runtimeConfig(context).getManagedBean(strProperty);
+ if (managedBean != null) {
+ storeManagedBean(managedBean, facesContext(context));
+ context.setPropertyResolved(true);
+ }
+
+ return null;
+ }
+
+ // adapted from Manfred's JSF 1.1 VariableResolverImpl
+ private void storeManagedBean(ManagedBean managedBean,
+ FacesContext facesContext)
+ throws ELException {
+
+ ExternalContext extContext = facesContext.getExternalContext();
+ Map requestMap = extContext.getRequestMap();
+
+ // check for cyclic references
+ List beansUnderConstruction = (List)requestMap.get(BEANS_UNDER_CONSTRUCTION);
+ if (beansUnderConstruction == null) {
+ beansUnderConstruction = new ArrayList();
+ requestMap.put(BEANS_UNDER_CONSTRUCTION, beansUnderConstruction);
+ }
+
+ String managedBeanName = managedBean.getManagedBeanName();
+ if (beansUnderConstruction.contains(managedBeanName)) {
+ throw new ELException( "Detected cyclic reference to managedBean " + managedBeanName);
+ }
+
+ beansUnderConstruction.add(managedBeanName);
+
+ Object obj = null;
+ try {
+ obj = beanBuilder.buildManagedBean(facesContext, managedBean);
+ } finally {
+ beansUnderConstruction.remove(managedBeanName);
+ }
+
+ // put in scope
+ String scopeKey = managedBean.getManagedBeanScope();
+
+ // find the scope handler object
+ Scope scope = (Scope) _scopes.get(scopeKey);
+ if (scope == null) {
+ log.error("Managed bean '" + managedBeanName + "' has illegal scope: "
+ + scopeKey);
+ } else {
+ scope.put(extContext, managedBeanName, obj);
+ }
+
+ if(obj==null && log.isDebugEnabled()) {
+ log.debug("Variable '" + managedBeanName + "' could not be resolved.");
+ }
+ }
+
+ // get the FacesContext from the ELContext
+ private FacesContext facesContext(ELContext context) {
+ return (FacesContext)context.getContext(FacesContext.class);
+ }
+
+ private ExternalContext externalContext(ELContext context) {
+ return facesContext(context).getExternalContext();
+ }
+
+ public Class<?> getType(ELContext context, Object base, Object property)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ if ( (base == null) && (property == null)) {
+ throw new PropertyNotFoundException();
+ }
+
+ return null;
+ }
+
+ public Iterator getFeatureDescriptors(ELContext context, Object base) {
+
+ if (base != null) return null;
+
+ ArrayList<FeatureDescriptor> descriptors = new ArrayList<FeatureDescriptor>();
+
+ Map<String, ManagedBean> managedBeans = runtimeConfig(context).getManagedBeans();
+ for (String beanName : managedBeans.keySet()) {
+ descriptors.add(makeDescriptor(beanName, managedBeans.get(beanName)));
+ }
+
+ return descriptors.iterator();
+ }
+
+ private FeatureDescriptor makeDescriptor(String beanName, ManagedBean managedBean) {
+ FeatureDescriptor fd = new FeatureDescriptor();
+ fd.setValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
+ fd.setValue(ELResolver.TYPE, managedBean.getManagedBeanClass());
+ fd.setName(beanName);
+ fd.setDisplayName(beanName);
+ fd.setShortDescription(managedBean.getDescription());
+ fd.setExpert(false);
+ fd.setHidden(false);
+ fd.setPreferred(true);
+ return fd;
+ }
+
+ protected RuntimeConfig runtimeConfig(ELContext context) {
+ FacesContext facesContext = facesContext(context);
+
+ // application-level singleton - we can safely cache this
+ if (this.runtimeConfig == null) {
+ this.runtimeConfig = RuntimeConfig.getCurrentInstance(facesContext.getExternalContext());
+ }
+
+ return runtimeConfig;
+ }
+
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+
+ if (base != null) return null;
+
+ return Object.class;
+ }
+
+ interface Scope {
+ public void put(ExternalContext extContext, String name, Object obj);
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResolverForFaces.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResolverForFaces.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResolverForFaces.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResolverForFaces.java Sun May 28 20:59:46 2006
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.unified.resolver;
+
+import javax.el.ArrayELResolver;
+import javax.el.BeanELResolver;
+import javax.el.CompositeELResolver;
+import javax.el.ELResolver;
+import javax.el.ListELResolver;
+import javax.el.MapELResolver;
+import javax.el.ResourceBundleELResolver;
+import javax.faces.el.PropertyResolver;
+import javax.faces.el.VariableResolver;
+import org.apache.myfaces.el.convert.PropertyResolverToELResolver;
+import org.apache.myfaces.el.convert.VariableResolverToELResolver;
+import org.apache.myfaces.el.unified.resolver.implicitobject.ImplicitObjectResolver;
+import org.apache.myfaces.el.unified.resolver.ManagedBeanResolver;
+import org.apache.myfaces.el.unified.resolver.ResourceBundleResolver;
+import org.apache.myfaces.el.unified.resolver.ScopedAttributeResolver;
+
+/**
+ * Provides an ELResolver for Faces.
+ *
+ * See JSF spec section 5.6.2
+ *
+ * @author Stan Silvert
+ */
+public class ResolverForFaces extends CompositeELResolver {
+
+ protected CompositeELResolver resolversFromAppConfig
+ = new CompositeELResolver();
+
+ protected CompositeELResolver resolversFromLegacyVariableResolvers
+ = new CompositeELResolver();
+
+ protected CompositeELResolver resolversFromLegacyPropertyResolvers
+ = new CompositeELResolver();
+
+ protected CompositeELResolver resolversFromApplicationAddResolver
+ = new CompositeELResolver();
+
+ /** Creates a new instance of ResolverForFaces */
+ public ResolverForFaces() {
+ add(ImplicitObjectResolver.makeResolverForFaces());
+
+ CompositeELResolver compResolver = new CompositeELResolver();
+ compResolver.add(resolversFromAppConfig);
+ compResolver.add(resolversFromLegacyVariableResolvers);
+ compResolver.add(resolversFromLegacyPropertyResolvers);
+ compResolver.add(resolversFromApplicationAddResolver);
+
+ add(compResolver);
+ add(new ManagedBeanResolver());
+ add(new ResourceBundleELResolver());
+ add(new ResourceBundleResolver());
+ add(new MapELResolver());
+ add(new ListELResolver());
+ add(new ArrayELResolver());
+ add(new BeanELResolver());
+ add(new ScopedAttributeResolver());
+
+ }
+
+ // The following methods allow resolvers to be added to the proper position in the
+ // chain at any time
+ public void addResolverFromAppConfig(ELResolver resolver) {
+ //TODO: implement
+ throw new RuntimeException("Not implemented yet");
+ }
+
+ // We allow more than one call, but it is expected that this will be
+ // called only once by passing in the fully-constructed VariableResolver chain
+ public void addResolverFromLegacyVariableResolver(VariableResolver resolver) {
+ resolversFromLegacyPropertyResolvers.add(new VariableResolverToELResolver(resolver));
+ }
+
+ public void addResolverFromLegacyPropertyResolver(PropertyResolver resolver) {
+ resolversFromLegacyPropertyResolvers.add(new PropertyResolverToELResolver(resolver));
+ }
+
+ public void addResolverFromApplicationAddResolver(ELResolver resolver) {
+ this.resolversFromApplicationAddResolver.add(resolver);
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResolverForJSP.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResolverForJSP.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResolverForJSP.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResolverForJSP.java Sun May 28 20:59:46 2006
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.unified.resolver;
+
+import org.apache.myfaces.el.unified.resolver.implicitobject.ImplicitObjectResolver;
+import org.apache.myfaces.el.unified.resolver.ManagedBeanResolver;
+import org.apache.myfaces.el.unified.resolver.ResourceBundleResolver;
+
+/**
+ * Provides an ELResolver for Faces.
+ *
+ * See JSF spec section 5.6.1
+ *
+ * @author Stan Silvert
+ */
+public class ResolverForJSP extends ResolverForFaces {
+
+ /** Creates a new instance of ResolverForJSP */
+ public ResolverForJSP() {
+ add(ImplicitObjectResolver.makeResolverForJSP());
+ add(new ManagedBeanResolver());
+ add(new ResourceBundleResolver());
+ add(resolversFromAppConfig);
+ add(resolversFromLegacyVariableResolvers);
+ add(resolversFromLegacyPropertyResolvers);
+ add(resolversFromApplicationAddResolver);
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResourceBundleResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResourceBundleResolver.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResourceBundleResolver.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResourceBundleResolver.java Sun May 28 20:59:46 2006
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.unified.resolver;
+
+import java.util.Iterator;
+import java.util.ResourceBundle;
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ELResolver;
+import javax.el.PropertyNotFoundException;
+import javax.el.PropertyNotWritableException;
+import javax.faces.application.Application;
+import javax.faces.context.FacesContext;
+
+/**
+ * See JSF 1.2 spec section 5.6.1.4
+ *
+ * @author Stan Silvert
+ */
+public class ResourceBundleResolver extends ELResolver {
+
+ /** Creates a new instance of ResourceBundleResolver */
+ public ResourceBundleResolver() {
+ }
+
+ public void setValue(ELContext context, Object base, Object property, Object value)
+ throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException {
+
+ if ((base == null) && (property == null)) throw new PropertyNotFoundException();
+
+ if (!(property instanceof String)) return;
+
+ ResourceBundle bundle = getResourceBundle(context, (String)property);
+
+ if (bundle != null) {
+ throw new PropertyNotWritableException("ResourceBundles are read-only");
+ }
+ }
+
+ public boolean isReadOnly(ELContext context, Object base, Object property)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ if (base != null) return false;
+ if (property == null) throw new PropertyNotFoundException();
+ if (!(property instanceof String)) return false;
+
+ ResourceBundle bundle = getResourceBundle(context, (String)property);
+
+ if (bundle != null) {
+ context.setPropertyResolved(true);
+ return true;
+ }
+
+ return false;
+ }
+
+ public Object getValue(ELContext context, Object base, Object property)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ if (base != null) return null;
+ if (property == null) throw new PropertyNotFoundException();
+ if (!(property instanceof String)) return null;
+
+ ResourceBundle bundle = getResourceBundle(context, (String)property);
+
+ if (bundle != null) {
+ context.setPropertyResolved(true);
+ return bundle;
+ }
+
+ return null;
+ }
+
+ public Class<?> getType(ELContext context, Object base, Object property)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ if (base != null) return null;
+ if (property == null) throw new PropertyNotFoundException();
+ if (!(property instanceof String)) return null;
+
+ ResourceBundle bundle = getResourceBundle(context, (String)property);
+
+ if (bundle != null) {
+ context.setPropertyResolved(true);
+ return ResourceBundle.class;
+ }
+
+ return null;
+ }
+
+ public Iterator getFeatureDescriptors(ELContext context, Object base) {
+
+ if (base != null) return null;
+
+ // TODO fix this?
+ // throw new UnsupportedOperationException("Can't implement without a list of all resource bundles??????");
+ return null; // noop
+ }
+
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+
+ if (base != null) return null;
+
+ return String.class;
+ }
+
+ // get the FacesContext from the ELContext
+ private FacesContext facesContext(ELContext context) {
+ return (FacesContext)context.getContext(FacesContext.class);
+ }
+
+ private ResourceBundle getResourceBundle(ELContext context, String property) {
+ FacesContext facesContext = facesContext(context);
+ Application application = facesContext.getApplication();
+ return application.getResourceBundle(facesContext, property);
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ScopedAttributeResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ScopedAttributeResolver.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ScopedAttributeResolver.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ScopedAttributeResolver.java Sun May 28 20:59:46 2006
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.unified.resolver;
+
+import java.beans.FeatureDescriptor;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ELResolver;
+import javax.el.PropertyNotFoundException;
+import javax.el.PropertyNotWritableException;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+/**
+ * See JSF 1.2 spec section 5.6.2.7
+ *
+ * @author Stan Silvert
+ */
+public class ScopedAttributeResolver extends ELResolver {
+
+ /**
+ * Creates a new instance of ScopedAttributeResolver
+ */
+ public ScopedAttributeResolver() {
+ }
+
+ public void setValue(ELContext context, Object base, Object property, Object value)
+ throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException {
+
+ if (base != null) return;
+ if (property == null) throw new PropertyNotFoundException();
+
+ Map scopedMap = findScopedMap(externalContext(context), property);
+ if (scopedMap != null) {
+ scopedMap.put(property, value);
+ } else {
+ externalContext(context).getRequestMap().put(property, value);
+ }
+
+ context.setPropertyResolved(true);
+ }
+
+ public boolean isReadOnly(ELContext context, Object base, Object property)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ if (base == null) context.setPropertyResolved(true);
+
+ return false;
+ }
+
+ public Object getValue(ELContext context, Object base, Object property)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ if (base != null) return null;
+ if (property == null) throw new PropertyNotFoundException();
+
+ Map scopedMap = findScopedMap(externalContext(context), property);
+ if (scopedMap != null) {
+ context.setPropertyResolved(true);
+ return scopedMap.get(property);
+ }
+
+ return null;
+ }
+
+ public Class<?> getType(ELContext context, Object base, Object property)
+ throws NullPointerException, PropertyNotFoundException, ELException {
+
+ if (base != null) return null;
+ if (property == null) throw new PropertyNotFoundException();
+
+ context.setPropertyResolved(true);
+ return Object.class;
+ }
+
+ public Iterator getFeatureDescriptors(ELContext context, Object base) {
+
+ if (base != null) return null;
+
+ List descriptorList = new ArrayList();
+ ExternalContext extContext = externalContext(context);
+ addDescriptorsToList(descriptorList, extContext.getRequestMap());
+ addDescriptorsToList(descriptorList, extContext.getSessionMap());
+ addDescriptorsToList(descriptorList, extContext.getApplicationMap());
+
+ return descriptorList.iterator();
+ }
+
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+
+ if (base != null) return null;
+
+ return String.class;
+ }
+
+ // side effect: modifies the list
+ private void addDescriptorsToList(List descriptorList, Map scopeMap) {
+ for (Object name: scopeMap.keySet()) {
+ String strName = (String)name;
+ Class runtimeType = scopeMap.get(strName).getClass();
+ descriptorList.add(makeDescriptor(strName, runtimeType));
+ }
+ }
+
+ private FeatureDescriptor makeDescriptor(String name, Class runtimeType) {
+ FeatureDescriptor fd = new FeatureDescriptor();
+ fd.setValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
+ fd.setValue(ELResolver.TYPE, runtimeType);
+ fd.setName(name);
+ fd.setDisplayName(name);
+ fd.setShortDescription(name);
+ fd.setExpert(false);
+ fd.setHidden(false);
+ fd.setPreferred(true);
+ return fd;
+ }
+
+ // returns null if not found
+ private Map findScopedMap(ExternalContext extContext, Object property) {
+
+ Map scopedMap = extContext.getRequestMap();
+ if (scopedMap.containsKey(property)) return scopedMap;
+
+ scopedMap = extContext.getSessionMap();
+ if (scopedMap.containsKey(property)) return scopedMap;
+
+ scopedMap = extContext.getApplicationMap();
+ if (scopedMap.containsKey(property)) return scopedMap;
+
+ return null;
+ }
+
+ // get the FacesContext from the ELContext
+ private FacesContext facesContext(ELContext context) {
+ return (FacesContext)context.getContext(FacesContext.class);
+ }
+
+ private ExternalContext externalContext(ELContext context) {
+ return facesContext(context).getExternalContext();
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ApplicationImplicitObject.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ApplicationImplicitObject.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ApplicationImplicitObject.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ApplicationImplicitObject.java Sun May 28 20:59:46 2006
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.unified.resolver.implicitobject;
+
+import java.beans.FeatureDescriptor;
+import javax.el.ELContext;
+
+/**
+ * Encapsulates information needed by the ImplicitObjectResolver
+ *
+ * @author Stan Silvert
+ */
+public class ApplicationImplicitObject extends ImplicitObject {
+
+ private static final String NAME = "application".intern();
+
+ /** Creates a new instance of ApplicationImplicitObject */
+ public ApplicationImplicitObject() {
+ }
+
+ public Object getValue(ELContext context) {
+ return externalContext(context).getContext();
+ }
+
+ public String getName() {
+ return NAME;
+ }
+
+ public Class getType() {
+ return null;
+ }
+
+ public FeatureDescriptor getDescriptor() {
+ return makeDescriptor(NAME,
+ "Represents the application environment",
+ Object.class);
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ApplicationScopeImplicitObject.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ApplicationScopeImplicitObject.java?rev=410018&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ApplicationScopeImplicitObject.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ApplicationScopeImplicitObject.java Sun May 28 20:59:46 2006
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.el.unified.resolver.implicitobject;
+
+import java.beans.FeatureDescriptor;
+import java.util.Map;
+import javax.el.ELContext;
+
+/**
+ * Encapsulates information needed by the ImplicitObjectResolver
+ *
+ * @author Stan Silvert
+ */
+public class ApplicationScopeImplicitObject extends ImplicitObject {
+
+ private static final String NAME = "applicationScope".intern();
+
+ /** Creates a new instance of ApplicationScopeImplicitObject */
+ public ApplicationScopeImplicitObject() {
+ }
+
+ public Object getValue(ELContext context) {
+ return externalContext(context).getApplicationMap();
+ }
+
+ public String getName() {
+ return NAME;
+ }
+
+ public Class getType() {
+ return Object.class;
+ }
+
+ public FeatureDescriptor getDescriptor() {
+ return makeDescriptor(NAME,
+ "Application scope attributes",
+ Map.class);
+ }
+
+}