KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdql > parser > SimpleNode


1 /*
2  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6
7 package com.hp.hpl.jena.rdql.parser;
8 import com.hp.hpl.jena.rdql.Query;
9 ;
10
11 public class SimpleNode implements Node
12 {
13   // These are manipulated by JJTree,JavaCC
14
protected Node parent;
15   protected Node[] children;
16
17   protected int id;
18   protected RDQLParser parser;
19
20   // Used when created outside the parse tree (i.e. by ValueImpl())
21
// dead - that use is coivered by WorkingVar
22
//public SimpleNode() { id = -1 ; }
23

24   public SimpleNode(int i) {
25     id = i;
26   }
27
28   public SimpleNode(RDQLParser p, int i) {
29     this(i);
30     parser = p;
31   }
32
33   public void jjtOpen() {
34   }
35
36   public void jjtClose()
37   {
38   }
39
40   public void jjtSetParent(Node n) { parent = n; }
41   public Node jjtGetParent() { return parent; }
42
43   public void jjtAddChild(Node n, int i) {
44     if (children == null) {
45       children = new Node[i + 1];
46     } else if (i >= children.length) {
47       Node c[] = new Node[i + 1];
48       System.arraycopy(children, 0, c, 0, children.length);
49       children = c;
50     }
51     children[i] = n;
52   }
53
54   public Node jjtGetChild(int i) {
55     return children[i];
56   }
57
58   public int jjtGetNumChildren() {
59     return (children == null) ? 0 : children.length;
60   }
61
62   /* You can override these two methods in subclasses of SimpleNode to
63      customize the way the node appears when the tree is dumped. If
64      your output uses more than one line you should override
65      toString(String), otherwise overriding toString() is probably all
66      you need to do. */

67
68   public String JavaDoc toString() { return RDQLParserTreeConstants.jjtNodeName[id]; }
69   public String JavaDoc toString(String JavaDoc prefix) { return prefix + toString(); }
70
71
72   // Per-parse query processing
73
// Operation to allow any node to do some alterations after the query has been parsed
74
public void postParse(Query query)
75   {
76       if (children != null)
77       {
78           for (int i = 0; i < children.length; ++i)
79           {
80               SimpleNode n = (SimpleNode)children[i];
81               n.postParse(query);
82           }
83       }
84   }
85
86   /* Override this method if you want to customize how the node dumps
87      out its children. */

88
89   public void dump(String JavaDoc prefix) {
90     System.out.println(toString(prefix));
91     if (children != null) {
92       for (int i = 0; i < children.length; ++i) {
93         SimpleNode n = (SimpleNode)children[i];
94         if (n != null) {
95           n.dump(prefix + " ");
96         }
97       }
98     }
99   }
100 }
101
102 /*
103  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
104  * All rights reserved.
105  *
106  * Redistribution and use in source and binary forms, with or without
107  * modification, are permitted provided that the following conditions
108  * are met:
109  * 1. Redistributions of source code must retain the above copyright
110  * notice, this list of conditions and the following disclaimer.
111  * 2. Redistributions in binary form must reproduce the above copyright
112  * notice, this list of conditions and the following disclaimer in the
113  * documentation and/or other materials provided with the distribution.
114  * 3. The name of the author may not be used to endorse or promote products
115  * derived from this software without specific prior written permission.
116  *
117  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
118  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
119  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
120  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
121  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
122  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
123  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
124  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
125  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
126  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
127  */

128
Popular Tags