KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > CollectNodesVisitor


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.CollectNodesVisitor
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.compile;
23
24 import org.apache.derby.iapi.services.sanity.SanityManager;
25 import org.apache.derby.iapi.sql.compile.Visitable;
26 import org.apache.derby.iapi.sql.compile.Visitor;
27
28 import org.apache.derby.iapi.error.StandardException;
29
30 import java.util.Vector JavaDoc;
31
32 /**
33  * Collect all nodes of the designated type to be returned
34  * in a vector.
35  * <p>
36  * Can find any type of node -- the class or class name
37  * of the target node is passed in as a constructor
38  * parameter.
39  *
40  * @author jamie
41  */

42 public class CollectNodesVisitor implements Visitor
43 {
44     private Vector JavaDoc nodeList;
45     private Class JavaDoc nodeClass;
46     private Class JavaDoc skipOverClass;
47     /**
48      * Construct a visitor
49      *
50      * @param nodeClass the class of the node that
51      * we are looking for.
52      */

53     public CollectNodesVisitor(Class JavaDoc nodeClass)
54     {
55         this.nodeClass = nodeClass;
56         nodeList = new Vector JavaDoc();
57     }
58
59     /**
60      * Construct a visitor
61      *
62      * @param nodeClass the class of the node that
63      * we are looking for.
64      * @param skipOverClass do not go below this
65      * node when searching for nodeClass.
66      */

67     public CollectNodesVisitor(Class JavaDoc nodeClass, Class JavaDoc skipOverClass)
68     {
69         this(nodeClass);
70         this.skipOverClass = skipOverClass;
71     }
72
73     public boolean stopTraversal()
74     {
75         return false;
76     }
77     ////////////////////////////////////////////////
78
//
79
// VISITOR INTERFACE
80
//
81
////////////////////////////////////////////////
82

83     /**
84      * If we have found the target node, we are done.
85      *
86      * @param node the node to process
87      *
88      * @return me
89      */

90     public Visitable visit(Visitable node)
91     {
92         if (nodeClass.isInstance(node))
93         {
94             nodeList.addElement(node);
95         }
96         return node;
97     }
98
99     /**
100      * Don't visit childen under the skipOverClass
101      * node, if it isn't null.
102      *
103      * @return true/false
104      */

105     public boolean skipChildren(Visitable node)
106     {
107         return (skipOverClass == null) ?
108                 false:
109                 skipOverClass.isInstance(node);
110     }
111
112     ////////////////////////////////////////////////
113
//
114
// CLASS INTERFACE
115
//
116
////////////////////////////////////////////////
117
/**
118      * Reset the status so it can be run again.
119      *
120      */

121     public Vector JavaDoc getList()
122     {
123         return nodeList;
124     }
125 }
126
Popular Tags