From 7efec864e9d2eac91bce7ae3d20411f18fd8827d Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 1 Apr 2010 10:31:15 +0000 Subject: [PATCH] reintroduced two-arg constructor (making STS warning disappear); always use a ResourcePatternResolver (through ResourcePatternUtils) git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3212 50f2f4bb-b051-0410-bef5-90022cba6387 --- .../config/SortedResourcesFactoryBean.java | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/config/SortedResourcesFactoryBean.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/config/SortedResourcesFactoryBean.java index 5945dc92db3..9a54179854d 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/config/SortedResourcesFactoryBean.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/config/SortedResourcesFactoryBean.java @@ -28,11 +28,14 @@ import org.springframework.beans.factory.config.AbstractFactoryBean; import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.core.io.support.ResourcePatternUtils; /** - * {@link FactoryBean} implementation that takes a list of location strings and creates a sorted array - * of {@link Resource} instances. + * {@link FactoryBean} implementation that takes a list of location Strings + * and creates a sorted array of {@link Resource} instances. + * * @author Dave Syer * @author Juergen Hoeller * @author Christian Dupuis @@ -42,45 +45,48 @@ public class SortedResourcesFactoryBean extends AbstractFactoryBean private final List locations; - private ResourceLoader resourceLoader; + private ResourcePatternResolver resourcePatternResolver; + public SortedResourcesFactoryBean(List locations) { this.locations = locations; - setSingleton(true); + this.resourcePatternResolver = new PathMatchingResourcePatternResolver(); } + public SortedResourcesFactoryBean(ResourceLoader resourceLoader, List locations) { + this.locations = locations; + this.resourcePatternResolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader); + } + + + public void setResourceLoader(ResourceLoader resourceLoader) { + this.resourcePatternResolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader); + } + + @Override public Class getObjectType() { return Resource[].class; } - public void setResourceLoader(ResourceLoader resourceLoader) { - this.resourceLoader = resourceLoader; - } - @Override protected Resource[] createInstance() throws Exception { List scripts = new ArrayList(); - for (String location : locations) { - if (resourceLoader instanceof ResourcePatternResolver) { - List resources = new ArrayList(Arrays - .asList(((ResourcePatternResolver) resourceLoader).getResources(location))); - Collections.sort(resources, new Comparator() { - public int compare(Resource r1, Resource r2) { - try { - return r1.getURL().toString().compareTo(r2.getURL().toString()); - } - catch (IOException ex) { - return 0; - } + for (String location : this.locations) { + List resources = new ArrayList( + Arrays.asList(this.resourcePatternResolver.getResources(location))); + Collections.sort(resources, new Comparator() { + public int compare(Resource r1, Resource r2) { + try { + return r1.getURL().toString().compareTo(r2.getURL().toString()); + } + catch (IOException ex) { + return 0; } - }); - for (Resource resource : resources) { - scripts.add(resource); } - } - else { - scripts.add(resourceLoader.getResource(location)); + }); + for (Resource resource : resources) { + scripts.add(resource); } } return scripts.toArray(new Resource[scripts.size()]);