Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 93239 invoked from network); 30 Nov 2004 04:40:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 30 Nov 2004 04:40:58 -0000 Received: (qmail 84085 invoked by uid 500); 30 Nov 2004 04:40:56 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 84058 invoked by uid 500); 30 Nov 2004 04:40:56 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 84043 invoked by uid 500); 30 Nov 2004 04:40:56 -0000 Received: (qmail 84039 invoked by uid 99); 30 Nov 2004 04:40:55 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 29 Nov 2004 20:40:55 -0800 Received: (qmail 93224 invoked by uid 1786); 30 Nov 2004 04:40:54 -0000 Date: 30 Nov 2004 04:40:54 -0000 Message-ID: <20041130044054.93223.qmail@minotaur.apache.org> From: skitching@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/digester/src/java/org/apache/commons/digester SetNestedPropertiesRule.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N skitching 2004/11/29 20:40:54 Modified: digester/src/java/org/apache/commons/digester SetNestedPropertiesRule.java Log: Fix for bugzilla #31393, reported by James Pine. SetNestedPropertiesRule failed when executed re-entrantly; removed over-zealous optimisation that made it fail in that case (though it now runs slower in the usual case). Revision Changes Path 1.9 +45 -17 jakarta-commons/digester/src/java/org/apache/commons/digester/SetNestedPropertiesRule.java Index: SetNestedPropertiesRule.java =================================================================== RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/SetNestedPropertiesRule.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- SetNestedPropertiesRule.java 10 May 2004 06:52:50 -0000 1.8 +++ SetNestedPropertiesRule.java 30 Nov 2004 04:40:54 -0000 1.9 @@ -81,6 +81,11 @@ * underlying Rules implementation for the same pattern, so other rules * are not "disabled" during processing of a SetNestedPropertiesRule.

* + *

TODO: Optimise this class. Currently, each time begin is called, + * new AnyChildRules and AnyChildRule objects are created. It should be + * possible to cache these in normal use (though watch out for when a rule + * instance is invoked re-entrantly!).

+ * * @since 1.6 */ @@ -94,10 +99,6 @@ private Log log = null; - private AnyChildRule anyChildRule = new AnyChildRule(); - private AnyChildRules newRules = new AnyChildRules(anyChildRule); - private Rules oldRules = null; - private boolean trimData = true; private boolean allowUnknownChildElements = false; @@ -185,7 +186,6 @@ public void setDigester(Digester digester) { super.setDigester(digester); log = digester.getLogger(); - anyChildRule.setDigester(digester); } /** @@ -203,8 +203,16 @@ } /** - * When set to true, any child element for which there is no + * Determines whether an error is reported when a nested element is + * encountered for which there is no corresponding property-setter + * method. + *

+ * When set to false, any child element for which there is no * corresponding object property will cause an error to be reported. + *

+ * When set to false, any child element for which there is no + * corresponding object property will simply be ignored. + *

* The default value of this attribute is false (not allowed). */ public void setAllowUnknownChildElements(boolean allowUnknownChildElements) { @@ -225,7 +233,10 @@ */ public void begin(String namespace, String name, Attributes attributes) throws Exception { - oldRules = digester.getRules(); + Rules oldRules = digester.getRules(); + AnyChildRule anyChildRule = new AnyChildRule(); + anyChildRule.setDigester(digester); + AnyChildRules newRules = new AnyChildRules(anyChildRule); newRules.init(digester.getMatch()+"/", oldRules); digester.setRules(newRules); } @@ -236,7 +247,8 @@ * child-element-matching. */ public void body(String bodyText) throws Exception { - digester.setRules(oldRules); + AnyChildRules newRules = (AnyChildRules) digester.getRules(); + digester.setRules(newRules.getOldRules()); } /** @@ -293,21 +305,25 @@ (matchPath.indexOf('/', matchPrefix.length()) == -1)) { // The current element is a direct child of the element - // specified in the init method, so include it as the - // first rule in the matches list. The way that - // SetNestedPropertiesRule is used, it is in fact very - // likely to be the only match, so we optimise that - // solution by keeping a list with only the AnyChildRule - // instance in it. + // specified in the init method, so we want to ensure that + // the rule passed to this object's constructor is included + // in the returned list of matching rules. if ((match == null || match.size()==0)) { + // The "real" rules class doesn't have any matches for + // the specified path, so we return a list containing + // just one rule: the one passed to this object's + // constructor. return rules; } else { - // it might not be safe to modify the returned list, + // The "real" rules class has rules that match the current + // node, so we return this list *plus* the rule passed to + // this object's constructor. + // + // It might not be safe to modify the returned list, // so clone it first. LinkedList newMatch = new LinkedList(match); - //newMatch.addFirst(rule); newMatch.addLast(rule); return newMatch; } @@ -327,6 +343,10 @@ matchPrefix = prefix; decoratedRules = rules; } + + public Rules getOldRules() { + return decoratedRules; + } } private class AnyChildRule extends Rule { @@ -395,7 +415,15 @@ } } + try + { BeanUtils.setProperty(top, propName, value); + } + catch(NullPointerException e) { + digester.log.error("NullPointerException: " + + "top=" + top + ",propName=" + propName + ",value=" + value + "!"); + throw e; + } } public void end(String namespace, String name) throws Exception { --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org