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