KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > templates > VarNameCollector


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

16 /*
17  * $Id: VarNameCollector.java,v 1.5 2004/02/16 20:32:33 minchau Exp $
18  */

19 package org.apache.xalan.templates;
20
21 import java.util.Vector JavaDoc;
22
23 import org.apache.xml.utils.QName;
24 import org.apache.xpath.ExpressionOwner;
25 import org.apache.xpath.XPathVisitor;
26 import org.apache.xpath.operations.Variable;
27
28 /**
29  * This class visits variable refs in an XPath and collects their QNames.
30  */

31 public class VarNameCollector extends XPathVisitor
32 {
33     Vector JavaDoc m_refs = new Vector JavaDoc();
34     
35     /**
36      * Reset the list for a fresh visitation and collection.
37      */

38     public void reset()
39     {
40         m_refs.removeAllElements(); //.clear();
41
}
42     
43     /**
44      * Get the number of variable references that were collected.
45      * @return the size of the list.
46      */

47     public int getVarCount()
48     {
49         return m_refs.size();
50     }
51     
52     /**
53      * Tell if the given qualified name occurs in
54      * the list of qualified names collected.
55      *
56      * @param refName Must be a valid qualified name.
57      * @return true if the list contains the qualified name.
58      */

59     boolean doesOccur(QName refName)
60     {
61         return m_refs.contains(refName);
62     }
63
64     /**
65      * Visit a variable reference.
66      * @param owner The owner of the expression, to which the expression can
67      * be reset if rewriting takes place.
68      * @param var The variable reference object.
69      * @return true if the sub expressions should be traversed.
70      */

71     public boolean visitVariableRef(ExpressionOwner owner, Variable var)
72     {
73         m_refs.addElement(var.getQName());
74         return true;
75     }
76
77 }
78
79
Popular Tags