1 40 package com.mvnforum.admin.importexport; 41 42 import org.apache.commons.beanutils.MethodUtils; 43 import org.apache.commons.digester.Digester; 44 import org.apache.commons.digester.Rule; 45 import org.xml.sax.Attributes ; 46 47 56 public class SetParentRule extends Rule { 57 58 protected String methodName = null; 59 protected String paramType = null; 60 protected boolean useExactMatch = false; 61 62 public SetParentRule(Digester digester, String methodName) { 63 this(methodName); 64 } 65 66 public SetParentRule(Digester digester, String methodName, String paramType) { 67 this(methodName, paramType); 68 } 69 70 public SetParentRule(String methodName) { 71 this(methodName, null); 72 } 73 74 public SetParentRule(String methodName, String paramType) { 75 this.methodName = methodName; 76 this.paramType = paramType; 77 } 78 79 public boolean isExactMatch() { 80 return useExactMatch; 81 } 82 83 public void setExactMatch(boolean useExactMatch) { 84 this.useExactMatch = useExactMatch; 85 } 86 87 public String toString() { 88 StringBuffer sb = new StringBuffer ("SetParentRule["); 89 sb.append("methodName="); 90 sb.append(methodName); 91 sb.append(", paramType="); 92 sb.append(paramType); 93 sb.append("]"); 94 return (sb.toString()); 95 } 96 97 public void begin(String namespace, String name, Attributes attributes) 98 throws Exception { 99 begin(attributes); 100 } 101 102 public void begin(Attributes attributes) throws Exception { 103 Object child = digester.peek(0); 105 Object parent = digester.peek(1); 106 107 119 120 Class paramTypes[] = new Class [1]; 122 if (paramType != null) { 123 paramTypes[0] = 124 digester.getClassLoader().loadClass(paramType); 125 } else { 126 paramTypes[0] = parent.getClass(); 127 } 128 129 if (useExactMatch) { 130 MethodUtils.invokeExactMethod(child, methodName, 131 new Object []{ parent }, paramTypes); 132 } else { 133 MethodUtils.invokeMethod(child, methodName, 134 new Object []{ parent }, paramTypes); 135 } 136 } 137 138 139 } 140 141
| Popular Tags
|