1 16 package org.springframework.webflow.engine.builder.xml; 17 18 import org.springframework.beans.factory.BeanFactory; 19 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; 20 import org.springframework.context.ApplicationContext; 21 import org.springframework.context.support.GenericApplicationContext; 22 import org.springframework.core.io.Resource; 23 import org.springframework.web.context.WebApplicationContext; 24 import org.springframework.web.context.support.GenericWebApplicationContext; 25 import org.springframework.webflow.engine.Flow; 26 import org.springframework.webflow.engine.builder.FlowServiceLocator; 27 28 40 class LocalFlowServiceRegistry { 41 42 45 private Flow flow; 46 47 50 private Resource[] resources; 51 52 55 private GenericApplicationContext context; 56 57 63 public LocalFlowServiceRegistry(Flow flow, Resource[] resources) { 64 this.flow = flow; 65 this.resources = resources; 66 } 67 68 71 public Flow getFlow() { 72 return flow; 73 } 74 75 78 public Resource[] getResources() { 79 return resources; 80 } 81 82 85 public ApplicationContext getContext() { 86 return context; 87 } 88 89 94 public void init(LocalFlowServiceLocator localFactory, FlowServiceLocator rootFactory) { 95 BeanFactory parent = null; 96 if (localFactory.isEmpty()) { 97 try { 98 parent = rootFactory.getBeanFactory(); 99 } 100 catch (UnsupportedOperationException e) { 101 } 103 } 104 else { 105 parent = localFactory.top().context; 106 } 107 context = createLocalFlowContext(parent, rootFactory); 108 new XmlBeanDefinitionReader(context).loadBeanDefinitions(resources); 109 context.refresh(); 110 } 111 112 119 private GenericApplicationContext createLocalFlowContext(BeanFactory parent, FlowServiceLocator rootFactory) { 120 if (parent instanceof WebApplicationContext) { 121 GenericWebApplicationContext context = new GenericWebApplicationContext(); 122 context.setServletContext(((WebApplicationContext)parent).getServletContext()); 123 context.setParent((WebApplicationContext)parent); 124 context.setResourceLoader(rootFactory.getResourceLoader()); 125 return context; 126 } 127 else { 128 GenericApplicationContext context = new GenericApplicationContext(); 129 if (parent instanceof ApplicationContext) { 130 context.setParent((ApplicationContext)parent); 131 } 132 else { 133 if (parent != null) { 134 context.getBeanFactory().setParentBeanFactory(parent); 135 } 136 } 137 context.setResourceLoader(rootFactory.getResourceLoader()); 138 return context; 139 } 140 } 141 } | Popular Tags |