1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.osgi.extender.support.scanning;
18
19 import java.util.Enumeration;
20
21 import org.osgi.framework.Bundle;
22 import org.springframework.osgi.extender.support.internal.ConfigUtils;
23 import org.springframework.osgi.io.OsgiBundleResource;
24 import org.springframework.util.ObjectUtils;
25
26 /**
27 * Default implementation of {@link ConfigurationScanner} interface.
28 *
29 * <p/>Supports <tt>Spring-Context</tt> manifest header and
30 * <tt>META-INF/spring/*.xml</tt>.
31 *
32 * @author Costin Leau
33 *
34 */
35 public class DefaultConfigurationScanner implements ConfigurationScanner {
36
37 private static final String CONTEXT_DIR = "/META-INF/spring/";
38
39 private static final String CONTEXT_FILES = "*.xml";
40
41 /** Default configuration location */
42 public static final String DEFAULT_CONFIG = OsgiBundleResource.BUNDLE_URL_PREFIX + CONTEXT_DIR + CONTEXT_FILES;
43
44
45 public String[] getConfigurations(Bundle bundle) {
46 String[] locations = ConfigUtils.getHeaderLocations(bundle.getHeaders());
47
48
49 if (ObjectUtils.isEmpty(locations)) {
50
51 Enumeration defaultConfig = bundle.findEntries(CONTEXT_DIR, CONTEXT_FILES, false);
52 if (defaultConfig != null && defaultConfig.hasMoreElements()) {
53 return new String[] { DEFAULT_CONFIG };
54 }
55 else {
56 return new String[0];
57 }
58 }
59 else {
60 return locations;
61 }
62 }
63 }