1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.discovery.resource.names;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import org.apache.commons.discovery.ResourceNameDiscover;
23 import org.apache.commons.discovery.ResourceNameIterator;
24 import org.apache.commons.discovery.tools.ManagedProperties;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28
29
30
31
32
33
34
35
36
37
38 public class DiscoverNamesInAlternateManagedProperties
39 extends ResourceNameDiscoverImpl
40 implements ResourceNameDiscover {
41
42 private static Log log = LogFactory.getLog(DiscoverNamesInAlternateManagedProperties.class);
43
44
45
46
47
48
49
50 @Deprecated
51 public static void setLog(Log _log) {
52 log = _log;
53 }
54
55 private final Map<String, String> mapping = new HashMap<String, String>();
56
57
58
59
60 public DiscoverNamesInAlternateManagedProperties() {
61 }
62
63
64
65
66
67
68
69 public void addClassToPropertyNameMapping(String className, String propertyName) {
70 mapping.put(className, propertyName);
71 }
72
73
74
75
76 @Override
77 public ResourceNameIterator findResourceNames(final String resourceName) {
78 final String mappedName = mapping.get(resourceName);
79
80 if (log.isDebugEnabled()) {
81 if (mappedName == null) {
82 log.debug("find: resourceName='" + resourceName + "', no mapping");
83 } else {
84 log.debug("find: resourceName='" + resourceName + "', lookup property '" + mappedName + "'");
85 }
86 }
87
88 return new ResourceNameIterator() {
89 private String resource =
90 (mappedName == null) ? null : ManagedProperties.getProperty(mappedName);
91
92 public boolean hasNext() {
93 return resource != null;
94 }
95
96 public String nextResourceName() {
97 String element = resource;
98 resource = null;
99 return element;
100 }
101 };
102 }
103
104 }