1 16 package org.springframework.webflow.engine.builder.xml; 17 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 import java.util.Map ; 22 import java.util.Properties ; 23 24 import org.springframework.core.io.Resource; 25 import org.springframework.webflow.definition.registry.FlowDefinitionRegistry; 26 import org.springframework.webflow.definition.registry.FlowDefinitionResource; 27 import org.springframework.webflow.engine.builder.AbstractFlowBuildingFlowRegistryFactoryBean; 28 import org.springframework.webflow.engine.builder.DefaultFlowServiceLocator; 29 import org.springframework.webflow.engine.builder.FlowServiceLocator; 30 31 63 public class XmlFlowRegistryFactoryBean extends AbstractFlowBuildingFlowRegistryFactoryBean { 64 65 68 private XmlFlowRegistrar flowRegistrar = new XmlFlowRegistrar(); 69 70 73 private Properties flowDefinitions; 74 75 78 protected XmlFlowRegistrar getXmlFlowRegistrar() { 79 return flowRegistrar; 80 } 81 82 110 public void setFlowLocations(Resource[] locations) { 111 getXmlFlowRegistrar().setLocations(locations); 112 } 113 114 143 public void setFlowDefinitions(Properties flowDefinitions) { 144 this.flowDefinitions = flowDefinitions; 145 } 146 147 153 public void setDocumentLoader(DocumentLoader documentLoader) { 154 getXmlFlowRegistrar().setDocumentLoader(documentLoader); 155 } 156 157 protected void init(FlowServiceLocator flowServiceLocator) { 158 flowRegistrar.setFlowServiceLocator(flowServiceLocator); 160 } 161 162 protected void doPopulate(FlowDefinitionRegistry registry) { 163 addFlowDefinitionsFromProperties(); 164 getXmlFlowRegistrar().registerFlowDefinitions(registry); 165 } 166 167 171 private void addFlowDefinitionsFromProperties() { 172 if (flowDefinitions != null && flowDefinitions.size() > 0) { 173 List flows = new ArrayList (flowDefinitions.size()); 174 Iterator it = flowDefinitions.entrySet().iterator(); 175 while (it.hasNext()) { 176 Map.Entry entry = (Map.Entry )it.next(); 177 String flowId = (String )entry.getKey(); 178 String location = (String )entry.getValue(); 179 Resource resource = getFlowServiceLocator().getResourceLoader().getResource(location); 180 flows.add(new FlowDefinitionResource(flowId, resource)); 181 } 182 getXmlFlowRegistrar().addResources( 183 (FlowDefinitionResource[])flows.toArray(new FlowDefinitionResource[flows.size()])); 184 flowDefinitions = null; 186 } 187 } 188 } | Popular Tags |