1 16 package org.springframework.webflow.engine.support; 17 18 import org.springframework.beans.factory.BeanFactory; 19 import org.springframework.util.Assert; 20 import org.springframework.util.StringUtils; 21 import org.springframework.webflow.engine.FlowVariable; 22 import org.springframework.webflow.execution.RequestContext; 23 import org.springframework.webflow.execution.ScopeType; 24 25 31 public class BeanFactoryFlowVariable extends FlowVariable { 32 33 37 private String beanName; 38 39 42 private BeanFactory beanFactory; 43 44 52 public BeanFactoryFlowVariable(String variableName, String beanName, BeanFactory beanFactory, ScopeType scope) { 53 super(variableName, scope); 54 if (StringUtils.hasText(beanName)) { 55 this.beanName = beanName; 56 } 57 else { 58 this.beanName = variableName; 59 } 60 Assert.notNull(beanFactory, "The bean factory is required"); 61 Assert.isTrue(!beanFactory.isSingleton(this.beanName), "The bean with name '" + this.beanName 62 + "' must be a prototype (singleton=false)"); 63 this.beanFactory = beanFactory; 64 } 65 66 protected Object createVariableValue(RequestContext context) { 67 return beanFactory.getBean(beanName); 68 } 69 } | Popular Tags |