1 17 18 19 package org.apache.commons.digester; 20 21 22 import org.apache.commons.beanutils.MethodUtils; 23 24 25 43 44 public class SetNextRule extends Rule { 45 46 47 49 50 61 public SetNextRule(Digester digester, String methodName) { 62 63 this(methodName); 64 65 } 66 67 68 81 public SetNextRule(Digester digester, String methodName, 82 String paramType) { 83 84 this(methodName, paramType); 85 86 } 87 88 95 public SetNextRule(String methodName) { 96 97 this(methodName, null); 98 99 } 100 101 102 111 public SetNextRule(String methodName, 112 String paramType) { 113 114 this.methodName = methodName; 115 this.paramType = paramType; 116 117 } 118 119 120 122 123 126 protected String methodName = null; 127 128 129 132 protected String paramType = null; 133 134 137 protected boolean useExactMatch = false; 138 139 141 142 162 public boolean isExactMatch() { 163 164 return useExactMatch; 165 } 166 167 175 public void setExactMatch(boolean useExactMatch) { 176 177 this.useExactMatch = useExactMatch; 178 } 179 180 183 public void end() throws Exception { 184 185 Object child = digester.peek(0); 187 Object parent = digester.peek(1); 188 if (digester.log.isDebugEnabled()) { 189 if (parent == null) { 190 digester.log.debug("[SetNextRule]{" + digester.match + 191 "} Call [NULL PARENT]." + 192 methodName + "(" + child + ")"); 193 } else { 194 digester.log.debug("[SetNextRule]{" + digester.match + 195 "} Call " + parent.getClass().getName() + "." + 196 methodName + "(" + child + ")"); 197 } 198 } 199 200 Class paramTypes[] = new Class [1]; 202 if (paramType != null) { 203 paramTypes[0] = 204 digester.getClassLoader().loadClass(paramType); 205 } else { 206 paramTypes[0] = child.getClass(); 207 } 208 209 if (useExactMatch) { 210 211 MethodUtils.invokeExactMethod(parent, methodName, 212 new Object []{ child }, paramTypes); 213 214 } else { 215 216 MethodUtils.invokeMethod(parent, methodName, 217 new Object []{ child }, paramTypes); 218 219 } 220 } 221 222 223 226 public String toString() { 227 228 StringBuffer sb = new StringBuffer ("SetNextRule["); 229 sb.append("methodName="); 230 sb.append(methodName); 231 sb.append(", paramType="); 232 sb.append(paramType); 233 sb.append("]"); 234 return (sb.toString()); 235 236 } 237 238 239 } 240 | Popular Tags |