1 57 58 package org.apache.commons.discovery.resource.names; 59 60 import java.util.HashMap ; 61 62 import org.apache.commons.discovery.ResourceNameDiscover; 63 import org.apache.commons.discovery.ResourceNameIterator; 64 import org.apache.commons.discovery.log.DiscoveryLogFactory; 65 import org.apache.commons.discovery.tools.ManagedProperties; 66 import org.apache.commons.logging.Log; 67 68 69 81 public class DiscoverNamesInAlternateManagedProperties 82 extends ResourceNameDiscoverImpl 83 implements ResourceNameDiscover 84 { 85 private static Log log = DiscoveryLogFactory.newLog(DiscoverNamesInAlternateManagedProperties.class); 86 public static void setLog(Log _log) { 87 log = _log; 88 } 89 90 HashMap mapping = new HashMap (); 91 92 94 public DiscoverNamesInAlternateManagedProperties() { 95 } 96 97 99 public void addClassToPropertyNameMapping(String className, String propertyName) { 100 mapping.put(className, propertyName); 101 } 102 103 106 public ResourceNameIterator findResourceNames(final String resourceName) { 107 final String mappedName = (String )mapping.get(resourceName); 108 109 if (log.isDebugEnabled()) { 110 if (mappedName == null) { 111 log.debug("find: resourceName='" + resourceName + "', no mapping"); 112 } else { 113 log.debug("find: resourceName='" + resourceName + "', lookup property '" + mappedName + "'"); 114 } 115 } 116 117 return new ResourceNameIterator() { 118 private String resource = 119 (mappedName == null) ? null : ManagedProperties.getProperty(mappedName); 120 121 public boolean hasNext() { 122 return resource != null; 123 } 124 125 public String nextResourceName() { 126 String element = resource; 127 resource = null; 128 return element; 129 } 130 }; 131 } 132 } 133 | Popular Tags |