You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by de...@apache.org on 2006/06/04 23:32:32 UTC
svn commit: r411600 - in
/myfaces/core/branches/jsf12/api/src/main/java/javax/faces: component/
validator/
Author: dennisbyrne
Date: Sun Jun 4 14:32:31 2006
New Revision: 411600
URL: http://svn.apache.org/viewvc?rev=411600&view=rev
Log:
Removed all build dependencies on the implementation.
Moved many public classes from org.apache.myfaces.el.convert to private classes in javax.faces.component
Copied three public classes from org.apache.myfaces.el.convert to private classes in javax.faces.component ( just like in _SharedRendererUtils )
removed dep on javax.el.MethodInfo from MethodExpressionValidator
the api project now builds fresh out of maven
Added:
myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToActionListener.java
myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToListener.java
myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToMethodExpression.java
myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToValueChangeListener.java
myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodExpressionToMethodBinding.java
myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_ValueBindingToValueExpression.java
myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_ValueExpressionToValueBinding.java
Modified:
myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UICommand.java
myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UIComponentBase.java
myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UIInput.java
myfaces/core/branches/jsf12/api/src/main/java/javax/faces/validator/MethodExpressionValidator.java
Modified: myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UICommand.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UICommand.java?rev=411600&r1=411599&r2=411600&view=diff
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UICommand.java (original)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UICommand.java Sun Jun 4 14:32:31 2006
@@ -20,9 +20,6 @@
import javax.faces.el.MethodBinding;
import javax.faces.el.ValueBinding;
import javax.faces.event.*;
-import org.apache.myfaces.el.convert.MethodBindingToActionListener;
-import org.apache.myfaces.el.convert.MethodBindingToMethodExpression;
-import org.apache.myfaces.el.convert.MethodExpressionToMethodBinding;
/**
* see Javadoc of <a href="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/api/index.html">JSF Specification</a>
@@ -34,7 +31,7 @@
extends UIComponentBase
implements ActionSource2
{
- private MethodBindingToActionListener _actionListener = null;
+ private _MethodBindingToActionListener _actionListener = null;
private MethodExpression _action = null;
/**
@@ -42,7 +39,7 @@
*/
public void setAction(MethodBinding action)
{
- setActionExpression(new MethodBindingToMethodExpression(action));
+ setActionExpression(new _MethodBindingToMethodExpression(action));
}
/**
@@ -51,11 +48,11 @@
public MethodBinding getAction()
{
MethodExpression actionExpression = getActionExpression();
- if (actionExpression instanceof MethodBindingToMethodExpression) {
- return ((MethodBindingToMethodExpression)actionExpression).getMethodBinding();
+ if (actionExpression instanceof _MethodBindingToMethodExpression) {
+ return ((_MethodBindingToMethodExpression)actionExpression).getMethodBinding();
}
- return new MethodExpressionToMethodBinding(actionExpression);
+ return new _MethodExpressionToMethodBinding(actionExpression);
}
/**
@@ -68,7 +65,7 @@
removeActionListener(_actionListener);
}
- _actionListener = new MethodBindingToActionListener(actionListener);
+ _actionListener = new _MethodBindingToActionListener(actionListener);
addActionListener(_actionListener);
}
@@ -209,7 +206,7 @@
Object values[] = (Object[])state;
super.restoreState(context, values[0]);
_action = (MethodExpression)restoreAttachedState(context, values[1]); // changed this line - TODO: fix src generator
- _actionListener = (MethodBindingToActionListener)restoreAttachedState(context, values[2]); // changed this line - TODO: fix src generator
+ _actionListener = (_MethodBindingToActionListener)restoreAttachedState(context, values[2]); // changed this line - TODO: fix src generator
_immediate = (Boolean)values[3];
_value = (Object)values[4];
}
Modified: myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UIComponentBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UIComponentBase.java?rev=411600&r1=411599&r2=411600&view=diff
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UIComponentBase.java (original)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UIComponentBase.java Sun Jun 4 14:32:31 2006
@@ -38,9 +38,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.el.convert.ValueBindingToValueExpression;
-import org.apache.myfaces.el.convert.ValueExpressionToValueBinding;
-
/**
* Standard implementation of the UIComponent base class; all standard JSF
@@ -153,12 +150,12 @@
ValueExpression expression = _valueExpressionMap.get(name);
if (expression == null) return null;
- if (expression instanceof ValueBindingToValueExpression) {
- ValueBindingToValueExpression bindingToExpression = (ValueBindingToValueExpression)expression;
+ if (expression instanceof _ValueBindingToValueExpression) {
+ _ValueBindingToValueExpression bindingToExpression = (_ValueBindingToValueExpression)expression;
return bindingToExpression.getValueBinding();
}
- return new ValueExpressionToValueBinding(expression);
+ return new _ValueExpressionToValueBinding(expression);
}
public ValueExpression getValueExpression(String name) {
@@ -178,7 +175,7 @@
public void setValueBinding(String name,
ValueBinding binding)
{
- setValueExpression(name, new ValueBindingToValueExpression(binding));
+ setValueExpression(name, new _ValueBindingToValueExpression(binding));
}
public void setValueExpression(String name, ValueExpression binding) {
Modified: myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UIInput.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UIInput.java?rev=411600&r1=411599&r2=411600&view=diff
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UIInput.java (original)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UIInput.java Sun Jun 4 14:32:31 2006
@@ -30,7 +30,6 @@
import javax.faces.validator.Validator;
import java.util.ArrayList;
import java.util.List;
-import org.apache.myfaces.el.convert.MethodBindingToValueChangeListener;
/**
* see Javadoc of <a href="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/api/index.html">JSF Specification</a>
@@ -53,7 +52,7 @@
private boolean _localValueSet = false;
private boolean _valid = true;
private MethodBinding _validator = null;
- private MethodBindingToValueChangeListener _valueChangeListener = null;
+ private _MethodBindingToValueChangeListener _valueChangeListener = null;
private List _validatorList = null;
// use javadoc inherited from EditableValueHolder
@@ -147,7 +146,7 @@
removeValueChangeListener(_valueChangeListener);
}
- _valueChangeListener = new MethodBindingToValueChangeListener(valueChangeListener);
+ _valueChangeListener = new _MethodBindingToValueChangeListener(valueChangeListener);
addValueChangeListener(_valueChangeListener);
}
@@ -514,7 +513,7 @@
_submittedValue = (Object)values[4];
_valid = ((Boolean)values[5]).booleanValue();
_validator = (MethodBinding)restoreAttachedState(context, values[6]);
- _valueChangeListener = (MethodBindingToValueChangeListener)restoreAttachedState(context, values[7]); // changed line - TODO: fix w/ src gen
+ _valueChangeListener = (_MethodBindingToValueChangeListener)restoreAttachedState(context, values[7]); // changed line - TODO: fix w/ src gen
_validatorList = (List)restoreAttachedState(context, values[8]);
}
Added: myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToActionListener.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToActionListener.java?rev=411600&view=auto
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToActionListener.java (added)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToActionListener.java Sun Jun 4 14:32:31 2006
@@ -0,0 +1,42 @@
+/*
+ * 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 javax.faces.component;
+
+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
+ */
+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/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToListener.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToListener.java?rev=411600&view=auto
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToListener.java (added)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToListener.java Sun Jun 4 14:32:31 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 javax.faces.component;
+
+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
+ */
+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/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToMethodExpression.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToMethodExpression.java?rev=411600&view=auto
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToMethodExpression.java (added)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToMethodExpression.java Sun Jun 4 14:32:31 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 javax.faces.component;
+
+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
+ */
+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/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToValueChangeListener.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToValueChangeListener.java?rev=411600&view=auto
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToValueChangeListener.java (added)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodBindingToValueChangeListener.java Sun Jun 4 14:32:31 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 javax.faces.component;
+
+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
+ */
+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/branches/jsf12/api/src/main/java/javax/faces/component/_MethodExpressionToMethodBinding.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodExpressionToMethodBinding.java?rev=411600&view=auto
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodExpressionToMethodBinding.java (added)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_MethodExpressionToMethodBinding.java Sun Jun 4 14:32:31 2006
@@ -0,0 +1,93 @@
+/*
+ * 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 javax.faces.component;
+
+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
+ *
+ * ATTENTION: If you make changes to this class, treat
+ * org.apache.myfaces.el.convert.MethodExpressionToMethodBinding
+ * accordingly.
+ *
+ * @author Stan Silvert
+ * @see org.apache.myfaces.el.convert.MethodExpressionToMethodBinding
+ */
+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/branches/jsf12/api/src/main/java/javax/faces/component/_ValueBindingToValueExpression.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_ValueBindingToValueExpression.java?rev=411600&view=auto
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_ValueBindingToValueExpression.java (added)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_ValueBindingToValueExpression.java Sun Jun 4 14:32:31 2006
@@ -0,0 +1,173 @@
+/*
+ * 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 javax.faces.component;
+
+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.
+ *
+ * ATTENTION: If you make changes to this class, treat
+ * org.apache.myfaces.el.converte.ValueBindingToValueExpression
+ * accordingly.
+ *
+ * @author Stan Silvert
+ * @see org.apache.myfaces.el.converte.ValueBindingToValueExpression
+ */
+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/branches/jsf12/api/src/main/java/javax/faces/component/_ValueExpressionToValueBinding.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_ValueExpressionToValueBinding.java?rev=411600&view=auto
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_ValueExpressionToValueBinding.java (added)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/_ValueExpressionToValueBinding.java Sun Jun 4 14:32:31 2006
@@ -0,0 +1,140 @@
+/*
+ * 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 javax.faces.component;
+
+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
+ *
+ * ATTENTION: If you make changes to this class, treat
+ * org.apache.myfaces.el.convert.ValueExpressionToValueBinding
+ * accordingly.
+ *
+ * @author Stan Silvert
+ * @see org.apache.myfaces.el.convert.ValueExpressionToValueBinding
+ */
+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;
+ }
+
+}
Modified: myfaces/core/branches/jsf12/api/src/main/java/javax/faces/validator/MethodExpressionValidator.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java/javax/faces/validator/MethodExpressionValidator.java?rev=411600&r1=411599&r2=411600&view=diff
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/validator/MethodExpressionValidator.java (original)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/validator/MethodExpressionValidator.java Sun Jun 4 14:32:31 2006
@@ -18,7 +18,6 @@
import javax.el.ELException;
import javax.el.MethodExpression;
-import javax.el.MethodInfo;
import javax.faces.application.FacesMessage;
import javax.faces.component.StateHolder;
import javax.faces.component.UIComponent;