1 17 18 19 package org.apache.commons.digester; 20 21 22 import org.apache.commons.beanutils.MethodUtils; 23 24 25 35 36 public class SetRootRule extends Rule { 37 38 39 41 42 53 public SetRootRule(Digester digester, String methodName) { 54 55 this(methodName); 56 57 } 58 59 60 73 public SetRootRule(Digester digester, String methodName, 74 String paramType) { 75 76 this(methodName, paramType); 77 78 } 79 80 87 public SetRootRule(String methodName) { 88 89 this(methodName, null); 90 91 } 92 93 94 103 public SetRootRule(String methodName, 104 String paramType) { 105 106 this.methodName = methodName; 107 this.paramType = paramType; 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 134 154 public boolean isExactMatch() { 155 156 return useExactMatch; 157 } 158 159 160 168 public void setExactMatch(boolean useExactMatch) { 169 170 this.useExactMatch = useExactMatch; 171 } 172 173 176 public void end() throws Exception { 177 178 Object child = digester.peek(0); 180 Object parent = digester.root; 181 if (digester.log.isDebugEnabled()) { 182 if (parent == null) { 183 digester.log.debug("[SetRootRule]{" + digester.match + 184 "} Call [NULL ROOT]." + 185 methodName + "(" + child + ")"); 186 } else { 187 digester.log.debug("[SetRootRule]{" + digester.match + 188 "} Call " + parent.getClass().getName() + "." + 189 methodName + "(" + child + ")"); 190 } 191 } 192 193 Class paramTypes[] = new Class [1]; 195 if (paramType != null) { 196 paramTypes[0] = 197 digester.getClassLoader().loadClass(paramType); 198 } else { 199 paramTypes[0] = child.getClass(); 200 } 201 202 if (useExactMatch) { 203 204 MethodUtils.invokeExactMethod(parent, methodName, 205 new Object []{ child }, paramTypes); 206 207 } else { 208 209 MethodUtils.invokeMethod(parent, methodName, 210 new Object []{ child }, paramTypes); 211 212 } 213 } 214 215 216 219 public String toString() { 220 221 StringBuffer sb = new StringBuffer ("SetRootRule["); 222 sb.append("methodName="); 223 sb.append(methodName); 224 sb.append(", paramType="); 225 sb.append(paramType); 226 sb.append("]"); 227 return (sb.toString()); 228 229 } 230 231 232 } 233 | Popular Tags |