--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.compile.CollectNodesVisitor\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.sql.compile;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.sql.compile.Visitable; \r
+import org.apache.derby.iapi.sql.compile.Visitor;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import java.util.Vector;\r
+\r
+/**\r
+ * Collect all nodes of the designated type to be returned\r
+ * in a vector.\r
+ * <p>\r
+ * Can find any type of node -- the class or class name\r
+ * of the target node is passed in as a constructor\r
+ * parameter.\r
+ *\r
+ */\r
+public class CollectNodesVisitor implements Visitor\r
+{\r
+ private Vector nodeList;\r
+ private Class nodeClass;\r
+ private Class skipOverClass;\r
+ /**\r
+ * Construct a visitor\r
+ *\r
+ * @param nodeClass the class of the node that \r
+ * we are looking for.\r
+ */\r
+ public CollectNodesVisitor(Class nodeClass)\r
+ {\r
+ this.nodeClass = nodeClass;\r
+ nodeList = new Vector();\r
+ }\r
+\r
+ /**\r
+ * Construct a visitor\r
+ *\r
+ * @param nodeClass the class of the node that \r
+ * we are looking for.\r
+ * @param skipOverClass do not go below this\r
+ * node when searching for nodeClass.\r
+ */\r
+ public CollectNodesVisitor(Class nodeClass, Class skipOverClass)\r
+ {\r
+ this(nodeClass);\r
+ this.skipOverClass = skipOverClass;\r
+ }\r
+\r
+ public boolean stopTraversal()\r
+ {\r
+ return false;\r
+ }\r
+ ////////////////////////////////////////////////\r
+ //\r
+ // VISITOR INTERFACE\r
+ //\r
+ ////////////////////////////////////////////////\r
+\r
+ /**\r
+ * If we have found the target node, we are done.\r
+ *\r
+ * @param node the node to process\r
+ *\r
+ * @return me\r
+ */\r
+ public Visitable visit(Visitable node)\r
+ {\r
+ if (nodeClass.isInstance(node))\r
+ {\r
+ nodeList.addElement(node); \r
+ }\r
+ return node;\r
+ }\r
+\r
+ /**\r
+ * Don't visit childen under the skipOverClass\r
+ * node, if it isn't null.\r
+ *\r
+ * @return true/false\r
+ */\r
+ public boolean skipChildren(Visitable node)\r
+ {\r
+ return (skipOverClass == null) ?\r
+ false:\r
+ skipOverClass.isInstance(node);\r
+ }\r
+\r
+ ////////////////////////////////////////////////\r
+ //\r
+ // CLASS INTERFACE\r
+ //\r
+ ////////////////////////////////////////////////\r
+ /**\r
+ * Reset the status so it can be run again.\r
+ *\r
+ */\r
+ public Vector getList()\r
+ {\r
+ return nodeList;\r
+ }\r
+} \r