1 18 19 20 package org.apache.tomcat.util.digester; 21 22 23 import org.apache.tomcat.util.IntrospectionUtils; 24 import org.xml.sax.Attributes ; 25 26 27 31 32 public class SetPropertyRule extends Rule { 33 34 35 37 38 51 public SetPropertyRule(Digester digester, String name, String value) { 52 53 this(name, value); 54 55 } 56 57 66 public SetPropertyRule(String name, String value) { 67 68 this.name = name; 69 this.value = value; 70 71 } 72 73 75 76 79 protected String name = null; 80 81 82 85 protected String value = null; 86 87 88 90 91 99 public void begin(Attributes attributes) throws Exception { 100 101 String actualName = null; 103 String actualValue = null; 104 for (int i = 0; i < attributes.getLength(); i++) { 105 String name = attributes.getLocalName(i); 106 if ("".equals(name)) { 107 name = attributes.getQName(i); 108 } 109 String value = attributes.getValue(i); 110 if (name.equals(this.name)) { 111 actualName = value; 112 } else if (name.equals(this.value)) { 113 actualValue = value; 114 } 115 } 116 117 Object top = digester.peek(); 119 120 if (digester.log.isDebugEnabled()) { 122 digester.log.debug("[SetPropertyRule]{" + digester.match + 123 "} Set " + top.getClass().getName() + " property " + 124 actualName + " to " + actualValue); 125 } 126 127 IntrospectionUtils.setProperty(top, actualName, actualValue); 130 131 } 132 133 134 137 public String toString() { 138 139 StringBuffer sb = new StringBuffer ("SetPropertyRule["); 140 sb.append("name="); 141 sb.append(name); 142 sb.append(", value="); 143 sb.append(value); 144 sb.append("]"); 145 return (sb.toString()); 146 147 } 148 149 150 } 151 | Popular Tags |