1. package org.apache.xalan.templates;
  2. import java.util.Vector;
  3. import org.apache.xml.utils.QName;
  4. import org.apache.xpath.ExpressionOwner;
  5. import org.apache.xpath.XPathVisitor;
  6. import org.apache.xpath.operations.Variable;
  7. /**
  8. * This class visits variable refs in an XPath and collects their QNames.
  9. */
  10. public class VarNameCollector extends XPathVisitor
  11. {
  12. Vector m_refs = new Vector();
  13. /**
  14. * Reset the list for a fresh visitation and collection.
  15. */
  16. public void reset()
  17. {
  18. m_refs.removeAllElements(); //.clear();
  19. }
  20. /**
  21. * Get the number of variable references that were collected.
  22. * @return the size of the list.
  23. */
  24. public int getVarCount()
  25. {
  26. return m_refs.size();
  27. }
  28. /**
  29. * Tell if the given qualified name occurs in
  30. * the list of qualified names collected.
  31. *
  32. * @param refName Must be a valid qualified name.
  33. * @return true if the list contains the qualified name.
  34. */
  35. boolean doesOccur(QName refName)
  36. {
  37. return m_refs.contains(refName);
  38. }
  39. /**
  40. * Visit a variable reference.
  41. * @param owner The owner of the expression, to which the expression can
  42. * be reset if rewriting takes place.
  43. * @param var The variable reference object.
  44. * @return true if the sub expressions should be traversed.
  45. */
  46. public boolean visitVariableRef(ExpressionOwner owner, Variable var)
  47. {
  48. m_refs.addElement(var.getQName());
  49. return true;
  50. }
  51. }