commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <robertdon...@mac.com>
Subject Re: Possible documention glitch in commons-digester?
Date Tue, 14 May 2002 17:01:42 GMT
hi ceki

what you say is only true when you're using the standard Rules 
implementation. other Rules implementations can return any Rule(s) they 
like for a given pattern but they must always honour the ordering (which 
is the content of the following paragraph).

you're right that that particular paragraph is garbage and needs rewriting 
(thanks).

- robert

On Tuesday, May 14, 2002, at 10:57 AM, Ceki Gülcü wrote:

>
> Hello,
>
> Looking at the source code of RulesBase.match(String, String) it can
> be seen that wildcard matching is performed if there was no exact
> match for the current pattern.
>
> But the digester documentation (at
> http://jakarta.apache.org/commons/digester/api/org/apache/commons/digester/
> package-summary.html)
> reads:
>
>   It is quite possible that, when a particular XML element is being
>   parsed, the pattern for more than one registered processing rule will
>   be matched either because you registered more than one processing rule
>   with the same matching pattern, or because one more more exact pattern
>   matches and wildcard pattern matches are satisfied by the same
>   element.
>
> This statement is misleading because only when there is no exact match
> for the current pattern are wildcard patterns taken into
> consideration. (Also watch out for the "more more" typo.)
>
> Here is a little experiment to make the case:
>
> --- File EchoRule.java ------------------
>
> import org.apache.commons.digester.*;
>
> public class EchoRule extends Rule {
>
>   String pat;
>
>   EchoRule(Digester digester, String pat) {
>     super(digester);
>     this.pat = pat;
>   }
>
>   public void body(String text) {
>     System.out.println("Body of EchoRule("+pat+") called with text 
> ["+text+"].");
>   }
>
>   public static void main(String[] args) throws Exception {
>
>     Digester digester = new Digester();
>
>     Rule aRule = new EchoRule(digester, "top/a");
>     digester.addRule("top/a", aRule);
>
>     Rule starARule = new EchoRule(digester, "*/a");
>     digester.addRule("*/a", starARule);
>
>     digester.parse(args[0]);
>   }
> }
> -----------------------------------------
>
> Here is a test xml file called a1.xml
>
> --- a1.xml --------
> <top>
>     <a>
>       immediate
>     </a>
> </top>
> -------------------
>
> Try it out:
>
> > javac EchoRule.java
> > java EchoRule a1.xml
> Body of EchoRule(top/a) called with text [immediate].
>
> You can also try it on a2.xml
>
> --- a2.xml --------
> <top>
>     <a>
>       immediate
>     </a>
>     <b>
>       <a>embedded within b</a>
>     </b>
> </top>
> -------------------
>
> The result is:
>
> > java EchoRule a2.xml
> Body of EchoRule(top/a) called with text [immediate].
> Body of EchoRule(*/a) called with text [embedded within b].
>
> In both tests you can see that EchoRule("*/a") is not called for
> "top/a".
>
>
> --
> Ceki
>
>
> --
> To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.
> org>
> For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.
> org>
>


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message