KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tomcat > util > digester > PathCallParamRule


1 /* $Id: PathCallParamRule.java 467222 2006-10-24 03:17:11Z markt $
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

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

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

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

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

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

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

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

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

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