Upgrade to Spring Framework 4.0

The build now compiles with Servlet API 3.0 and JPA 2.0 both of which
are required with Spring Framework 4.0. However there are no hard
dependencies in Web Flow on either.

Issue: SWF-1600
This commit is contained in:
Rossen Stoyanchev
2013-12-18 14:36:54 -05:00
parent ac57904bf8
commit 42863a3b62
22 changed files with 492 additions and 141 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2004-2008 the original author or authors.
* Copyright 2004-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,25 +16,124 @@
package org.springframework.faces.webflow;
import javax.faces.context.FacesContext;
import javax.faces.el.EvaluationException;
import javax.faces.el.VariableResolver;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.StaticListableBeanFactory;
import org.springframework.web.jsf.SpringBeanVariableResolver;
import org.springframework.util.Assert;
import org.springframework.webflow.execution.RequestContext;
import org.springframework.webflow.execution.RequestContextHolder;
/**
* JSF 1.1 variable resolver for Spring Beans accessible to the flow's local bean factory.
* JSF 1.1 {@code VariableResolver} that delegates to the
* flow's local Spring bean factory (for resolving Spring beans) and then
* to the original resolver of the underlying JSF implementation
* (for resolving managed-bean objects as defined in {@code faces-config.xml}
* as well as well-known implicit EL attributes).
*
* <p>Configure this resolver in your {@code faces-config.xml} file as follows:
*
* <pre>
* &lt;application>
* ...
* &lt;variable-resolver>org.springframework.faces.webflow.SpringBeanWebFlowVariableResolver&lt;/variable-resolver>
* &lt;/application></pre>
*
* All your JSF expressions can then implicitly refer to the names of
* Spring-managed service layer beans, for example in property values of
* JSF-managed beans:
*
* <pre>
* &lt;managed-bean>
* &lt;managed-bean-name>myJsfManagedBean&lt;/managed-bean-name>
* &lt;managed-bean-class>example.MyJsfManagedBean&lt;/managed-bean-class>
* &lt;managed-bean-scope>session&lt;/managed-bean-scope>
* &lt;managed-property>
* &lt;property-name>mySpringManagedBusinessObject&lt;/property-name>
* &lt;value>#{mySpringManagedBusinessObject}&lt;/value>
* &lt;/managed-property>
* &lt;/managed-bean></pre>
*
* with "mySpringManagedBusinessObject" defined as Spring bean in
* applicationContext.xml:
*
* <pre>
* &lt;bean id="mySpringManagedBusinessObject" class="example.MySpringManagedBusinessObject">
* ...
* &lt;/bean></pre>
*
* @author Jeremy Grelle
*/
public class SpringBeanWebFlowVariableResolver extends SpringBeanVariableResolver {
public class SpringBeanWebFlowVariableResolver extends VariableResolver {
private static final BeanFactory EMPTY_BEAN_FACTORY = new StaticListableBeanFactory();
/** Logger available to subclasses */
protected final Log logger = LogFactory.getLog(getClass());
protected final VariableResolver originalVariableResolver;
public SpringBeanWebFlowVariableResolver(VariableResolver originalVariableResolver) {
super(originalVariableResolver);
Assert.notNull(originalVariableResolver, "Original JSF VariableResolver must not be null");
this.originalVariableResolver = originalVariableResolver;
}
/**
* Return the original JSF VariableResolver that this resolver delegates to.
* Used to resolve standard JSF-managed beans.
*/
protected final VariableResolver getOriginalVariableResolver() {
return this.originalVariableResolver;
}
/**
* Try to resolve the variable as Spring bean in the flow local bean factory.
* Then delegate to the original VariableResolver.
*/
@Override
public Object resolveVariable(FacesContext facesContext, String name) throws EvaluationException {
Object bean = resolveSpringBean(facesContext, name);
if (bean != null) {
return bean;
}
Object value = resolveOriginal(facesContext, name);
if (value != null) {
return value;
}
return null;
}
/**
* Resolve the attribute via the original JSF VariableResolver.
*/
protected Object resolveOriginal(FacesContext facesContext, String name) {
Object value = getOriginalVariableResolver().resolveVariable(facesContext, name);
if (value != null && logger.isTraceEnabled()) {
logger.trace("Successfully resolved variable '" + name + "' via original VariableResolver");
}
return value;
}
/**
* Resolve the attribute as a Spring bean in the ApplicationContext.
*/
protected Object resolveSpringBean(FacesContext facesContext, String name) {
BeanFactory bf = getBeanFactory(facesContext);
if (bf.containsBean(name)) {
if (logger.isTraceEnabled()) {
logger.trace("Successfully resolved variable '" + name + "' in Spring BeanFactory");
}
return bf.getBean(name);
}
else {
return null;
}
}
protected BeanFactory getBeanFactory(FacesContext facesContext) {

View File

@@ -94,7 +94,7 @@ class TreeStructureManager {
String compId = treeStructComp.getComponentId();
UIComponent component;
try {
component = (UIComponent) BeanUtils.instantiateClass(ClassUtils.forName(compClass));
component = (UIComponent) BeanUtils.instantiateClass(ClassUtils.forName(compClass, TreeStructureManager.class.getClassLoader()));
} catch (Exception ex) {
throw new FacesException("Could not restore the component tree structure.", ex);
}