--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.compile.HasNodeVisitor\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
+/**\r
+ * Find out if we have a particular node anywhere in the\r
+ * tree. Stop traversal as soon as we find one.\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 HasNodeVisitor implements Visitor\r
+{\r
+ private boolean hasNode;\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 HasNodeVisitor(Class nodeClass)\r
+ {\r
+ this.nodeClass = nodeClass;\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 HasNodeVisitor(Class nodeClass, Class skipOverClass)\r
+ {\r
+ this.nodeClass = nodeClass;\r
+ this.skipOverClass = skipOverClass;\r
+ }\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
+ hasNode = true;\r
+ }\r
+ return node;\r
+ }\r
+\r
+ /**\r
+ * Stop traversal if we found the target node\r
+ *\r
+ * @return true/false\r
+ */\r
+ public boolean stopTraversal()\r
+ {\r
+ return hasNode;\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
+ * Indicate whether we found the node in\r
+ * question\r
+ *\r
+ * @return true/false\r
+ */\r
+ public boolean hasNode()\r
+ {\r
+ return hasNode;\r
+ }\r
+\r
+ /**\r
+ * Reset the status so it can be run again.\r
+ *\r
+ */\r
+ public void reset()\r
+ {\r
+ hasNode = false;\r
+ }\r
+} \r