rdonkin 2004/09/20 14:59:23
Modified: digester build.xml
digester/src/java/org/apache/commons/digester
SetPropertiesRule.java
Log:
Allows exception throwing for mismatches to be switch on. Patch contributed by
Gabriele Carcassi.
Revision Changes Path
1.56 +7 -1 jakarta-commons/digester/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/digester/build.xml,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- build.xml 19 Sep 2004 16:51:18 -0000 1.55
+++ build.xml 20 Sep 2004 21:59:23 -0000 1.56
@@ -483,6 +483,12 @@
<arg value="org.apache.commons.digester.SetPropertyRuleTestCase"/>
<classpath refid="test.classpath"/>
</java>
+ <java classname="${test.runner}" fork="yes"
+ failonerror="${test.failonerror}">
+ <jvmarg value="-D${logopt}"/>
+ <arg value="org.apache.commons.digester.SetPropertiesRuleTestCase"/>
+ <classpath refid="test.classpath"/>
+ </java>
</target>
1.20 +42 -1
jakarta-commons/digester/src/java/org/apache/commons/digester/SetPropertiesRule.java
Index: SetPropertiesRule.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/SetPropertiesRule.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- SetPropertiesRule.java 10 May 2004 06:30:06 -0000 1.19
+++ SetPropertiesRule.java 20 Sep 2004 21:59:23 -0000 1.20
@@ -22,6 +22,7 @@
import java.util.HashMap;
import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.beanutils.PropertyUtils;
import org.xml.sax.Attributes;
@@ -144,6 +145,12 @@
*/
private String [] propertyNames;
+ /**
+ * Used to determine whether the parsing should fail if an property specified
+ * in the XML is missing from the bean. Default is true for backward
compatibility.
+ */
+ private boolean ignoreMissingProperty = true;
+
// --------------------------------------------------------- Public Methods
@@ -197,6 +204,14 @@
"} Setting property '" + name + "' to '" +
value + "'");
}
+
+ if ((!ignoreMissingProperty) && (name != null)) {
+ Object top = digester.peek();
+ boolean test = PropertyUtils.isWriteable(top, name);
+ if (!test)
+ throw new NoSuchMethodException("Property " + name + " can't be
set");
+ }
+
if (name != null) {
values.put(name, value);
}
@@ -265,6 +280,32 @@
sb.append("]");
return (sb.toString());
+ }
+
+ /**
+ * <p>Are attributes found in the xml without matching properties to be ignored?
+ * </p><p>
+ * If false, the parsing will interrupt with an
<code>NoSuchMethodException</code>
+ * if a property specified in the XML is not found. The default is true.
+ * </p>
+ * @return true if skipping the unmatched attributes.
+ */
+ public boolean isIgnoreMissingProperty() {
+
+ return this.ignoreMissingProperty;
+ }
+
+ /**
+ * Sets whether attributes found in the xml without matching properties
+ * should be ignored.
+ * If set to false, the parsing will throw an <code>NoSuchMethodException</code>
+ * if an unmatched
+ * attribute is found. This allows to trap misspellings in the XML file.
+ * @param ignoreMissingProperty false to stop the parsing on unmatched
attributes.
+ */
+ public void setIgnoreMissingProperty(boolean ignoreMissingProperty) {
+
+ this.ignoreMissingProperty = ignoreMissingProperty;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]