1 57 58 package org.apache.commons.discovery.resource.names; 59 60 import java.util.Dictionary ; 61 import java.util.Hashtable ; 62 63 import org.apache.commons.discovery.ResourceNameDiscover; 64 import org.apache.commons.discovery.ResourceNameListener; 65 import org.apache.commons.discovery.log.DiscoveryLogFactory; 66 import org.apache.commons.logging.Log; 67 68 69 78 public class DiscoverNamesInDictionary extends ResourceNameDiscoverImpl 79 implements ResourceNameDiscover, ResourceNameListener 80 { 81 private static Log log = DiscoveryLogFactory.newLog(DiscoverNamesInDictionary.class); 82 public static void setLog(Log _log) { 83 log = _log; 84 } 85 86 private Dictionary dictionary; 87 88 90 public DiscoverNamesInDictionary() { 91 this(new Hashtable ()); 92 } 93 94 96 public DiscoverNamesInDictionary(Dictionary dictionary) { 97 setDictionary(dictionary); 98 } 99 100 protected Dictionary getDictionary() { 101 return dictionary; 102 } 103 104 107 public void setDictionary(Dictionary table) { 108 this.dictionary = dictionary; 109 } 110 111 public void addResource(String resourceName, String resource) { 112 dictionary.put(resourceName, resource); 113 } 114 115 public void addResource(String resourceName, String [] resources) { 116 dictionary.put(resourceName, resources); 117 } 118 119 122 public boolean find(String resourceName) { 123 if (log.isDebugEnabled()) 124 log.debug("find: resourceName='" + resourceName + "'"); 125 126 Object baseResource = dictionary.get(resourceName); 127 128 if (baseResource instanceof String ) { 129 return notifyListener((String )baseResource); 130 } else if (baseResource instanceof String []) { 131 String [] resources = (String [])baseResource; 132 for (int i = 0; i < resources.length; i++) { 133 if (!notifyListener(resources[i])) { 134 return false; 135 } 136 } 137 } 138 return true; 139 } 140 141 public boolean found(String resourceName) { 142 return find(resourceName); 143 } 144 } 145 | Popular Tags |