1 17 18 19 package org.apache.commons.digester; 20 21 22 import org.xml.sax.Attributes ; 23 24 25 30 31 public class ObjectCreateRule extends Rule { 32 33 34 36 37 46 public ObjectCreateRule(Digester digester, String className) { 47 48 this(className); 49 50 } 51 52 53 62 public ObjectCreateRule(Digester digester, Class clazz) { 63 64 this(clazz); 65 66 } 67 68 69 81 public ObjectCreateRule(Digester digester, String className, 82 String attributeName) { 83 84 this (className, attributeName); 85 86 } 87 88 89 101 public ObjectCreateRule(Digester digester, 102 String attributeName, 103 Class clazz) { 104 105 this(attributeName, clazz); 106 107 } 108 109 114 public ObjectCreateRule(String className) { 115 116 this(className, (String ) null); 117 118 } 119 120 121 126 public ObjectCreateRule(Class clazz) { 127 128 this(clazz.getName(), (String ) null); 129 130 } 131 132 133 141 public ObjectCreateRule(String className, 142 String attributeName) { 143 144 this.className = className; 145 this.attributeName = attributeName; 146 147 } 148 149 150 158 public ObjectCreateRule(String attributeName, 159 Class clazz) { 160 161 this(clazz.getName(), attributeName); 162 163 } 164 165 167 168 171 protected String attributeName = null; 172 173 174 177 protected String className = null; 178 179 180 182 183 188 public void begin(Attributes attributes) throws Exception { 189 190 String realClassName = className; 192 if (attributeName != null) { 193 String value = attributes.getValue(attributeName); 194 if (value != null) { 195 realClassName = value; 196 } 197 } 198 if (digester.log.isDebugEnabled()) { 199 digester.log.debug("[ObjectCreateRule]{" + digester.match + 200 "}New " + realClassName); 201 } 202 203 Class clazz = digester.getClassLoader().loadClass(realClassName); 205 Object instance = clazz.newInstance(); 206 digester.push(instance); 207 208 } 209 210 211 214 public void end() throws Exception { 215 216 Object top = digester.pop(); 217 if (digester.log.isDebugEnabled()) { 218 digester.log.debug("[ObjectCreateRule]{" + digester.match + 219 "} Pop " + top.getClass().getName()); 220 } 221 222 } 223 224 225 228 public String toString() { 229 230 StringBuffer sb = new StringBuffer ("ObjectCreateRule["); 231 sb.append("className="); 232 sb.append(className); 233 sb.append(", attributeName="); 234 sb.append(attributeName); 235 sb.append("]"); 236 return (sb.toString()); 237 238 } 239 240 241 } 242 | Popular Tags |