1 16 17 package org.apache.catalina.storeconfig; 18 19 import org.apache.tomcat.util.digester.Rule; 20 import org.xml.sax.Attributes ; 21 22 31 32 public class StoreFactoryRule extends Rule { 33 34 36 46 public StoreFactoryRule(String storeFactoryClass, String attributeName, 47 String storeAppenderClass, String appenderAttributeName) { 48 49 this.storeFactoryClass = storeFactoryClass; 50 this.attributeName = attributeName; 51 this.appenderAttributeName = appenderAttributeName; 52 this.storeAppenderClass = storeAppenderClass; 53 54 } 55 56 58 62 private String attributeName; 63 64 private String appenderAttributeName; 65 66 69 private String storeFactoryClass; 70 71 private String storeAppenderClass; 72 73 75 84 public void begin(String namespace, String name, Attributes attributes) 85 throws Exception { 86 87 IStoreFactory factory = (IStoreFactory) newInstance(attributeName, 88 storeFactoryClass, attributes); 89 StoreAppender storeAppender = (StoreAppender) newInstance( 90 appenderAttributeName, storeAppenderClass, attributes); 91 factory.setStoreAppender(storeAppender); 92 93 StoreDescription desc = (StoreDescription) digester.peek(0); 95 StoreRegistry registry = (StoreRegistry) digester.peek(1); 96 factory.setRegistry(registry); 97 desc.setStoreFactory(factory); 98 99 } 100 101 112 protected Object newInstance(String attr, String defaultName, 113 Attributes attributes) throws ClassNotFoundException , 114 InstantiationException , IllegalAccessException { 115 String className = defaultName; 116 if (attr != null) { 117 String value = attributes.getValue(attr); 118 if (value != null) 119 className = value; 120 } 121 Class clazz = Class.forName(className); 122 return clazz.newInstance(); 123 } 124 } | Popular Tags |