1 17 18 package org.apache.commons.digester.plugins.strategies; 19 20 import java.util.Properties ; 21 import org.apache.commons.digester.Digester; 22 import org.apache.commons.digester.plugins.RuleFinder; 23 import org.apache.commons.digester.plugins.RuleLoader; 24 import org.apache.commons.digester.plugins.PluginException; 25 26 32 33 public class FinderFromClass extends RuleFinder { 34 public static String DFLT_RULECLASS_ATTR = "ruleclass"; 35 public static String DFLT_METHOD_ATTR = "method"; 36 public static String DFLT_METHOD_NAME = "addRules"; 37 38 private String ruleClassAttr; 39 private String methodAttr; 40 private String dfltMethodName; 41 42 45 public FinderFromClass() { 46 this(DFLT_RULECLASS_ATTR, DFLT_METHOD_ATTR, DFLT_METHOD_NAME); 47 } 48 49 58 public FinderFromClass(String ruleClassAttr, String methodAttr, 59 String dfltMethodName) { 60 this.ruleClassAttr = ruleClassAttr; 61 this.methodAttr = methodAttr; 62 this.dfltMethodName = dfltMethodName; 63 } 64 65 92 public RuleLoader findLoader(Digester digester, Class pluginClass, 93 Properties p) throws PluginException { 94 95 String ruleClassName = p.getProperty(ruleClassAttr); 96 if (ruleClassName == null) { 97 return null; 100 } 101 102 String methodName = null; 104 if (methodAttr != null) { 105 methodName = p.getProperty(methodAttr); 106 } 107 if (methodName == null) { 108 methodName = dfltMethodName; 109 } 110 if (methodName == null) { 111 methodName = DFLT_METHOD_NAME; 112 } 113 114 Class ruleClass; 115 try { 116 ruleClass = 118 digester.getClassLoader().loadClass(ruleClassName); 119 } catch(ClassNotFoundException cnfe) { 120 throw new PluginException( 121 "Unable to load class " + ruleClassName, cnfe); 122 } 123 124 return new LoaderFromClass(ruleClass, methodName); 125 } 126 } 127 128 | Popular Tags |