1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the  "License");
7 * you may not use this file except in compliance with the License.
8 * 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 * $Id: VarNameCollector.java 468643 2006-10-28 06:56:03Z minchau $
20 */
21package org.apache.xalan.templates;
22
23import java.util.Vector;
24
25import org.apache.xml.utils.QName;
26import org.apache.xpath.ExpressionOwner;
27import org.apache.xpath.XPathVisitor;
28import org.apache.xpath.operations.Variable;
29
30/**
31 * This class visits variable refs in an XPath and collects their QNames.
32 */
33public class VarNameCollector extends XPathVisitor
34{
35	Vector m_refs = new Vector();
36
37	/**
38	 * Reset the list for a fresh visitation and collection.
39	 */
40	public void reset()
41	{
42		m_refs.removeAllElements(); //.clear();
43	}
44
45	/**
46	 * Get the number of variable references that were collected.
47	 * @return the size of the list.
48	 */
49	public int getVarCount()
50	{
51		return m_refs.size();
52	}
53
54	/**
55	 * Tell if the given qualified name occurs in
56	 * the list of qualified names collected.
57	 *
58	 * @param refName Must be a valid qualified name.
59	 * @return true if the list contains the qualified name.
60	 */
61	boolean doesOccur(QName refName)
62	{
63		return m_refs.contains(refName);
64	}
65
66	/**
67	 * Visit a variable reference.
68	 * @param owner The owner of the expression, to which the expression can
69	 *              be reset if rewriting takes place.
70	 * @param var The variable reference object.
71	 * @return true if the sub expressions should be traversed.
72	 */
73	public boolean visitVariableRef(ExpressionOwner owner, Variable var)
74	{
75		m_refs.addElement(var.getQName());
76		return true;
77	}
78
79}
80
81