1 16 package org.springframework.webflow.definition.registry; 17 18 import java.util.Arrays ; 19 import java.util.HashSet ; 20 import java.util.Iterator ; 21 import java.util.Set ; 22 23 import org.springframework.core.io.Resource; 24 import org.springframework.core.style.ToStringCreator; 25 26 53 public abstract class ExternalizedFlowDefinitionRegistrar implements FlowDefinitionRegistrar { 54 55 59 private Set locations = new HashSet (); 60 61 65 private Set resources = new HashSet (); 66 67 75 public void setLocations(Resource[] locations) { 76 this.locations = new HashSet (Arrays.asList(locations)); 77 } 78 79 87 public void setResources(FlowDefinitionResource[] resources) { 88 this.resources = new HashSet (Arrays.asList(resources)); 89 } 90 91 98 public boolean addLocation(Resource location) { 99 return locations.add(location); 100 } 101 102 109 public boolean addLocations(Resource[] locations) { 110 if (locations == null) { 111 return false; 112 } 113 return this.locations.addAll(Arrays.asList(locations)); 114 } 115 116 124 public boolean addResource(FlowDefinitionResource resource) { 125 return resources.add(resource); 126 } 127 128 136 public boolean addResources(FlowDefinitionResource[] resources) { 137 if (resources == null) { 138 return false; 139 } 140 return this.resources.addAll(Arrays.asList(resources)); 141 } 142 143 public void registerFlowDefinitions(FlowDefinitionRegistry registry) { 144 processLocations(registry); 145 processResources(registry); 146 } 147 148 150 154 private void processLocations(FlowDefinitionRegistry registry) { 155 Iterator it = locations.iterator(); 156 while (it.hasNext()) { 157 Resource location = (Resource)it.next(); 158 if (isFlowDefinitionResource(location)) { 159 FlowDefinitionResource resource = createFlowDefinitionResource(location); 160 register(resource, registry); 161 } 162 } 163 } 164 165 169 private void processResources(FlowDefinitionRegistry registry) { 170 Iterator it = resources.iterator(); 171 while (it.hasNext()) { 172 FlowDefinitionResource resource = (FlowDefinitionResource)it.next(); 173 register(resource, registry); 174 } 175 } 176 177 184 protected final void register(FlowDefinitionResource resource, FlowDefinitionRegistry registry) { 185 registry.registerFlowDefinition(createFlowDefinitionHolder(resource)); 186 } 187 188 190 198 protected boolean isFlowDefinitionResource(Resource resource) { 199 return true; 200 } 201 202 208 protected FlowDefinitionResource createFlowDefinitionResource(Resource location) { 209 return new FlowDefinitionResource(location); 210 } 211 212 218 protected abstract FlowDefinitionHolder createFlowDefinitionHolder(FlowDefinitionResource resource); 219 220 public String toString() { 221 return new ToStringCreator(this).append("locations", locations).append("resources", resources).toString(); 222 } 223 } | Popular Tags |