1 17 18 19 package org.apache.commons.digester; 20 21 22 import org.apache.commons.beanutils.MethodUtils; 23 24 25 34 35 public class SetTopRule extends Rule { 36 37 38 40 41 52 public SetTopRule(Digester digester, String methodName) { 53 54 this(methodName); 55 56 } 57 58 59 72 public SetTopRule(Digester digester, String methodName, 73 String paramType) { 74 75 this(methodName, paramType); 76 77 } 78 79 86 public SetTopRule(String methodName) { 87 88 this(methodName, null); 89 90 } 91 92 93 102 public SetTopRule(String methodName, 103 String paramType) { 104 105 this.methodName = methodName; 106 this.paramType = paramType; 107 108 } 109 110 111 113 114 117 protected String methodName = null; 118 119 120 123 protected String paramType = null; 124 125 128 protected boolean useExactMatch = false; 129 130 131 133 153 public boolean isExactMatch() { 154 155 return useExactMatch; 156 } 157 158 166 public void setExactMatch(boolean useExactMatch) { 167 168 this.useExactMatch = useExactMatch; 169 } 170 171 174 public void end() throws Exception { 175 176 Object child = digester.peek(0); 178 Object parent = digester.peek(1); 179 180 if (digester.log.isDebugEnabled()) { 181 if (child == null) { 182 digester.log.debug("[SetTopRule]{" + digester.match + 183 "} Call [NULL CHILD]." + 184 methodName + "(" + parent + ")"); 185 } else { 186 digester.log.debug("[SetTopRule]{" + digester.match + 187 "} Call " + child.getClass().getName() + "." + 188 methodName + "(" + parent + ")"); 189 } 190 } 191 192 Class paramTypes[] = new Class [1]; 194 if (paramType != null) { 195 paramTypes[0] = 196 digester.getClassLoader().loadClass(paramType); 197 } else { 198 paramTypes[0] = parent.getClass(); 199 } 200 201 if (useExactMatch) { 202 203 MethodUtils.invokeExactMethod(child, methodName, 204 new Object []{ parent }, paramTypes); 205 206 } else { 207 208 MethodUtils.invokeMethod(child, methodName, 209 new Object []{ parent }, paramTypes); 210 211 } 212 } 213 214 215 218 public String toString() { 219 220 StringBuffer sb = new StringBuffer ("SetTopRule["); 221 sb.append("methodName="); 222 sb.append(methodName); 223 sb.append(", paramType="); 224 sb.append(paramType); 225 sb.append("]"); 226 return (sb.toString()); 227 228 } 229 230 231 } 232 | Popular Tags |