KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > digester > PathCallParamRule


1 /* $Id: PathCallParamRule.java 155412 2005-02-26 12:58:36Z dirkv $
2  *
3  * Copyright 2003-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 package org.apache.commons.digester;
20
21
22 import org.xml.sax.Attributes JavaDoc;
23
24 /**
25  * <p>Rule implementation that saves a parameter containing the
26  * <code>Digester</code> matching path for use by a surrounding
27  * <code>CallMethodRule</code>. This Rule is most useful when making
28  * extensive use of wildcards in rule patterns.</p>
29  *
30  * @since 1.6
31  */

32
33 public class PathCallParamRule extends Rule {
34
35     // ----------------------------------------------------------- Constructors
36

37     /**
38      * Construct a "call parameter" rule that will save the body text of this
39      * element as the parameter value.
40      *
41      * @param paramIndex The zero-relative parameter number
42      */

43     public PathCallParamRule(int paramIndex) {
44
45         this.paramIndex = paramIndex;
46
47     }
48  
49     // ----------------------------------------------------- Instance Variables
50

51     /**
52      * The zero-relative index of the parameter we are saving.
53      */

54     protected int paramIndex = 0;
55
56     // --------------------------------------------------------- Public Methods
57

58
59     /**
60      * Process the start of this element.
61      *
62      * @param namespace the namespace URI of the matching element, or an
63      * empty string if the parser is not namespace aware or the element has
64      * no namespace
65      * @param name the local name if the parser is namespace aware, or just
66      * the element name otherwise
67      * @param attributes The attribute list for this element
68
69      */

70     public void begin(String JavaDoc namespace, String JavaDoc name, Attributes JavaDoc attributes) throws Exception JavaDoc {
71
72         String JavaDoc param = getDigester().getMatch();
73         
74         if(param != null) {
75             Object JavaDoc parameters[] = (Object JavaDoc[]) digester.peekParams();
76             parameters[paramIndex] = param;
77         }
78         
79     }
80
81     /**
82      * Render a printable version of this Rule.
83      */

84     public String JavaDoc toString() {
85
86         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("PathCallParamRule[");
87         sb.append("paramIndex=");
88         sb.append(paramIndex);
89         sb.append("]");
90         return (sb.toString());
91
92     }
93 }
94
Popular Tags