org.apache.myfaces.component.MethodBindingToMethodExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tomahawk12 Show documentation
Show all versions of tomahawk12 Show documentation
JSF components and utilities that can be used with any JSF implementation.
This library is based on the JSF1.1 version of Tomahawk, but with minor source code and build
changes to take advantage of JSF1.2 features. A JSF1.2 implementation is required to use this
version of the Tomahawk library.
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.myfaces.component;
import javax.el.ELContext;
import javax.el.ELException;
import javax.el.MethodExpression;
import javax.el.MethodInfo;
import javax.el.MethodNotFoundException;
import javax.el.PropertyNotFoundException;
import javax.faces.component.StateHolder;
import javax.faces.context.FacesContext;
import javax.faces.el.EvaluationException;
import javax.faces.el.MethodBinding;
import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
/**
* Converts a MethodBinding to a MethodExpression
*
* TODO: find a way to share the implementation of class with impl.
*
* This class could be moved or changed in the future
*
* @since 1.1.7
* @author Stan Silvert
*/
@SuppressWarnings("deprecation")
public class MethodBindingToMethodExpression extends MethodExpression implements StateHolder
{
private static final Class[] EXPECTED_TYPES = new Class[] { MethodBinding.class, StateHolder.class };
private MethodBinding methodBinding;
private boolean _transientFlag;
private transient MethodInfo methodInfo;
/**
* No-arg constructor used during restoreState
*/
public MethodBindingToMethodExpression()
{
}
/** Creates a new instance of MethodBindingToMethodExpression */
public MethodBindingToMethodExpression(MethodBinding methodBinding)
{
checkNullArgument(methodBinding, "methodBinding");
this.methodBinding = methodBinding;
}
/**
* Return the wrapped MethodBinding.
*/
public MethodBinding getMethodBinding()
{
return methodBinding;
}
void setMethodBinding(MethodBinding methodBinding)
{
this.methodBinding = 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 PropertyNotFoundException, MethodNotFoundException,
ELException
{
checkNullArgument(context, "elcontext");
checkNullState(methodBinding, "methodBinding");
if (methodInfo == null)
{
final FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
if (facesContext != null)
{
methodInfo = invoke(new Invoker()
{
public MethodInfo invoke()
{
return new MethodInfo(null, methodBinding.getType(facesContext), null);
}
});
}
}
return methodInfo;
}
public Object invoke(ELContext context, final Object[] params) throws PropertyNotFoundException,
MethodNotFoundException, ELException
{
checkNullArgument(context, "elcontext");
checkNullState(methodBinding, "methodBinding");
final FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
if (facesContext != null)
{
return invoke(new Invoker