1 16 17 package org.apache.catalina.storeconfig; 18 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 import javax.naming.directory.DirContext ; 23 24 import org.apache.catalina.LifecycleListener; 25 import org.apache.catalina.Manager; 26 import org.apache.catalina.Realm; 27 import org.apache.catalina.Valve; 28 import org.apache.catalina.cluster.CatalinaCluster; 29 import org.apache.catalina.cluster.ClusterDeployer; 30 import org.apache.catalina.cluster.ClusterReceiver; 31 import org.apache.catalina.cluster.ClusterSender; 32 import org.apache.catalina.cluster.MembershipService; 33 import org.apache.commons.logging.Log; 34 import org.apache.commons.logging.LogFactory; 35 36 42 public class StoreRegistry { 43 private static Log log = LogFactory.getLog(StoreRegistry.class); 44 45 private Map descriptors = new HashMap (); 46 47 private String encoding = "UTF-8"; 48 49 private String name; 50 51 private String version; 52 53 private static Class interfaces[] = { CatalinaCluster.class, 55 ClusterSender.class, ClusterReceiver.class, 56 MembershipService.class, ClusterDeployer.class, Realm.class, 57 Manager.class, DirContext .class, LifecycleListener.class, 58 Valve.class }; 59 60 63 public String getName() { 64 return name; 65 } 66 67 71 public void setName(String name) { 72 this.name = name; 73 } 74 75 78 public String getVersion() { 79 return version; 80 } 81 82 86 public void setVersion(String version) { 87 this.version = version; 88 } 89 90 97 public StoreDescription findDescription(String id) { 98 if (log.isDebugEnabled()) 99 log.debug("search descriptor " + id); 100 StoreDescription desc = (StoreDescription) descriptors.get(id); 101 if (desc == null) { 102 Class aClass = null; 103 try { 104 aClass = Class.forName(id, true, this.getClass() 105 .getClassLoader()); 106 } catch (ClassNotFoundException e) { 107 log.error("ClassName:" + id, e); 108 } 109 if (aClass != null) { 110 desc = (StoreDescription) descriptors.get(aClass.getName()); 111 for (int i = 0; desc == null && i < interfaces.length; i++) { 112 if (interfaces[i].isAssignableFrom(aClass)) { 113 desc = (StoreDescription) descriptors.get(interfaces[i] 114 .getName()); 115 } 116 } 117 } 118 } 119 if (log.isDebugEnabled()) 120 if (desc != null) 121 log.debug("find descriptor " + id + "#" + desc.getTag() + "#" 122 + desc.getStoreFactoryClass()); 123 else 124 log.debug(("Can't find descriptor for key " + id)); 125 return desc; 126 } 127 128 134 public StoreDescription findDescription(Class aClass) { 135 return findDescription(aClass.getName()); 136 } 137 138 144 public IStoreFactory findStoreFactory(String aClassName) { 145 StoreDescription desc = findDescription(aClassName); 146 if (desc != null) 147 return desc.getStoreFactory(); 148 else 149 return null; 150 151 } 152 153 159 public IStoreFactory findStoreFactory(Class aClass) { 160 return findStoreFactory(aClass.getName()); 161 } 162 163 168 public void registerDescription(StoreDescription desc) { 169 String key = desc.getId(); 170 if (key == null || "".equals(key)) 171 key = desc.getTagClass(); 172 descriptors.put(key, desc); 173 if (log.isDebugEnabled()) 174 log.debug("register store descriptor " + key + "#" + desc.getTag() 175 + "#" + desc.getTagClass()); 176 } 177 178 public StoreDescription unregisterDescription(StoreDescription desc) { 179 String key = desc.getId(); 180 if (key == null || "".equals(key)) 181 key = desc.getTagClass(); 182 return (StoreDescription) descriptors.remove(key); 183 } 184 185 187 190 public String getEncoding() { 191 return encoding; 192 } 193 194 197 public void setEncoding(String string) { 198 encoding = string; 199 } 200 201 } | Popular Tags |