Author: skitching Date: Tue Feb 15 20:51:55 2005 New Revision: 153990 URL: http://svn.apache.org/viewcvs?view=rev&rev=153990 Log: Support "target offset" feature of CallMethodRule in xmlrules. Patch by Wendy Smoak (with minor alterations). See bugzilla #33550.
Modified: jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/xmlrules/digester-rules.dtd Modified: jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java?view=diff&r1=153989&r2=153990 ============================================================================== --- jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java (original) +++ jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java Tue Feb 15 20:51:55 2005 @@ -1,4 +1,4 @@ -/* $Id: DigesterRuleParser.java,v 1.32 2005/01/18 00:11:12 skitching Exp $ +/* $Id$ * * Copyright 2001-2004 The Apache Software Foundation. * @@ -540,31 +540,53 @@ public Object createObject(Attributes attributes) { Rule callMethodRule = null; String methodName = attributes.getValue("methodname"); + + // Select which element is to be the target. Default to zero, + // ie the top object on the stack. + int targetOffset = 0; + String targetOffsetStr = attributes.getValue("targetoffset"); + if (targetOffsetStr != null) { + targetOffset = Integer.parseInt(targetOffsetStr); + } + if (attributes.getValue("paramcount") == null) { // call against empty method - callMethodRule = new CallMethodRule(methodName); + callMethodRule = new CallMethodRule(targetOffset, methodName); } else { int paramCount = Integer.parseInt(attributes.getValue("paramcount")); String paramTypesAttr = attributes.getValue("paramtypes"); if (paramTypesAttr == null || paramTypesAttr.length() == 0) { - callMethodRule = new CallMethodRule(methodName, paramCount); + callMethodRule = new CallMethodRule(targetOffset, methodName, paramCount); } else { - // Process the comma separated list or paramTypes - // into an array of String class names - ArrayList paramTypes = new ArrayList(); - StringTokenizer tokens = new StringTokenizer(paramTypesAttr, " \t\n\r,"); - while (tokens.hasMoreTokens()) { - paramTypes.add(tokens.nextToken()); - } - callMethodRule = new CallMethodRule( methodName, - paramCount, - (String[])paramTypes.toArray(new String[0])); + String[] paramTypes = getParamTypes(paramTypesAttr); + callMethodRule = new CallMethodRule( + targetOffset, methodName, paramCount, paramTypes); } } return callMethodRule; } + + /** + * Process the comma separated list of paramTypes + * into an array of String class names + */ + private String[] getParamTypes(String paramTypes) { + String[] paramTypesArray; + if( paramTypes != null ) { + ArrayList paramTypesList = new ArrayList(); + StringTokenizer tokens = new StringTokenizer( + paramTypes, " \t\n\r,"); + while (tokens.hasMoreTokens()) { + paramTypesList.add(tokens.nextToken()); + } + paramTypesArray = (String[])paramTypesList.toArray(new String[0]); + } else { + paramTypesArray = new String[0]; + } + return paramTypesArray; + } } /** @@ -791,4 +813,5 @@ rule.addAlias(attrName, propName); } } + } Modified: jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/xmlrules/digester-rules.dtd URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/xmlrules/digester-rules.dtd?view=diff&r1=153989&r2=153990 ============================================================================== --- jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/xmlrules/digester-rules.dtd (original) +++ jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/xmlrules/digester-rules.dtd Tue Feb 15 20:51:55 2005 @@ -1,8 +1,8 @@ <?xml version="1.0" encoding="UTF-8" ?> -<!-- $Id: digester-rules.dtd,v 1.15 2005/01/18 00:11:12 skitching Exp $ +<!-- $Id$ - Copyright 2001-2004 The Apache Software Foundation. + Copyright 2001-2005 The Apache Software Foundation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ <!-- "Digester" component of the Jakarta Commons Subproject DTD for the definition of Digester rules in XML. - $Id: digester-rules.dtd,v 1.15 2005/01/18 00:11:12 skitching Exp $ + $Id$ Applications wishing to reference this DTD in their own documents should use the following DOCTYPE declaration: @@ -96,13 +96,17 @@ pattern CDATA #IMPLIED propertyname CDATA #IMPLIED> -<!-- CallMethodRule --> +<!-- CallMethodRule + - + - Note that paramtypes is ignored unless paramcount is defined. + --> <!ELEMENT call-method-rule EMPTY> <!ATTLIST call-method-rule - pattern CDATA #IMPLIED - methodname CDATA #REQUIRED - paramcount CDATA #IMPLIED - paramtypes CDATA #IMPLIED> + pattern CDATA #IMPLIED + targetoffset CDATA #IMPLIED + methodname CDATA #REQUIRED + paramcount CDATA #IMPLIED + paramtypes CDATA #IMPLIED> <!-- CallParamRule --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]