01: /*
02: * Copyright 1999-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
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: Vector m_refs = new Vector();
33:
34: /**
35: * Reset the list for a fresh visitation and collection.
36: */
37: public void reset() {
38: m_refs.removeAllElements(); //.clear();
39: }
40:
41: /**
42: * Get the number of variable references that were collected.
43: * @return the size of the list.
44: */
45: public int getVarCount() {
46: return m_refs.size();
47: }
48:
49: /**
50: * Tell if the given qualified name occurs in
51: * the list of qualified names collected.
52: *
53: * @param refName Must be a valid qualified name.
54: * @return true if the list contains the qualified name.
55: */
56: boolean doesOccur(QName refName) {
57: return m_refs.contains(refName);
58: }
59:
60: /**
61: * Visit a variable reference.
62: * @param owner The owner of the expression, to which the expression can
63: * be reset if rewriting takes place.
64: * @param var The variable reference object.
65: * @return true if the sub expressions should be traversed.
66: */
67: public boolean visitVariableRef(ExpressionOwner owner, Variable var) {
68: m_refs.addElement(var.getQName());
69: return true;
70: }
71:
72: }
|