1 17 package org.apache.commons.digester.plugins; 18 19 import java.util.Properties ; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.digester.Digester; 23 24 31 public class Declaration { 32 33 34 private Class pluginClass; 35 36 37 private String pluginClassName; 38 39 40 private String id; 41 42 43 private Properties properties = new Properties (); 44 45 46 private boolean initialized = false; 47 48 52 private RuleLoader ruleLoader = null; 53 54 56 59 public Declaration(String pluginClassName) { 60 this.pluginClassName = pluginClassName; 65 } 66 67 70 public Declaration(Class pluginClass) { 71 this.pluginClass = pluginClass; 72 this.pluginClassName = pluginClass.getName(); 73 } 74 75 80 public Declaration(Class pluginClass, RuleLoader ruleLoader) { 81 this.pluginClass = pluginClass; 82 this.pluginClassName = pluginClass.getName(); 83 this.ruleLoader = ruleLoader; 84 } 85 86 88 95 public void setId(String id) { 96 this.id = id; 97 } 98 99 105 public String getId() { 106 return id; 107 } 108 109 122 public void setProperties(Properties p) { 123 properties.putAll(p); 124 } 125 126 131 public Class getPluginClass() { 132 return pluginClass; 133 } 134 135 137 141 public void init(Digester digester, PluginManager pm) throws PluginException { 142 Log log = digester.getLogger(); 143 boolean debug = log.isDebugEnabled(); 144 if (debug) { 145 log.debug("init being called!"); 146 } 147 148 if (initialized) { 149 throw new PluginAssertionFailure("Init called multiple times."); 150 } 151 152 if ((pluginClass == null) && (pluginClassName != null)) { 153 try { 154 pluginClass = 156 digester.getClassLoader().loadClass(pluginClassName); 157 } catch(ClassNotFoundException cnfe) { 158 throw new PluginException( 159 "Unable to load class " + pluginClassName, cnfe); 160 } 161 } 162 163 if (ruleLoader == null) { 164 log.debug("Searching for ruleloader..."); 167 ruleLoader = pm.findLoader(digester, id, pluginClass, properties); 168 } else { 169 log.debug("This declaration has an explicit ruleLoader."); 170 } 171 172 if (debug) { 173 if (ruleLoader == null) { 174 log.debug( 175 "No ruleLoader found for plugin declaration" 176 + " id [" + id + "]" 177 + ", class [" + pluginClass.getClass().getName() + "]."); 178 } else { 179 log.debug( 180 "RuleLoader of type [" + ruleLoader.getClass().getName() 181 + "] associated with plugin declaration" 182 + " id [" + id + "]" 183 + ", class [" + pluginClass.getClass().getName() + "]."); 184 } 185 } 186 187 initialized = true; 188 } 189 190 198 199 public void configure(Digester digester, String pattern) 200 throws PluginException { 201 Log log = digester.getLogger(); 202 boolean debug = log.isDebugEnabled(); 203 if (debug) { 204 log.debug("configure being called!"); 205 } 206 207 if (!initialized) { 208 throw new PluginAssertionFailure("Not initialized."); 209 } 210 211 if (ruleLoader != null) { 212 ruleLoader.addRules(digester, pattern); 213 } 214 } 215 } 216 | Popular Tags |