KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsps > parserapi > ELNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.jsps.parserapi;
21
22 import java.util.*;
23 import javax.servlet.jsp.tagext.FunctionInfo JavaDoc;
24 import javax.servlet.jsp.JspException JavaDoc;
25
26 /**
27  * This class defines internal representation for an EL Expression
28  *
29  * It currently only defines functions. It can be expanded to define
30  * all the components of an EL expression, if need to.
31  */

32
33 public abstract class ELNode {
34
35     public abstract void accept(Visitor v) throws JspException JavaDoc;
36
37     /**
38      * Child classes
39      */

40
41
42     /**
43      * Represents an EL expression: anything in ${ and }.
44      */

45     public static class Root extends ELNode {
46
47     private ELNode.Nodes expr;
48
49     public Root(ELNode.Nodes expr) {
50         this.expr = expr;
51     }
52
53     public void accept(Visitor v) throws JspException JavaDoc {
54         v.visit(this);
55     }
56
57     public ELNode.Nodes getExpression() {
58         return expr;
59     }
60     }
61
62     /**
63      * Represents text outside of EL expression.
64      */

65     public static class Text extends ELNode {
66
67     private String JavaDoc text;
68
69     public Text(String JavaDoc text) {
70         this.text = text;
71     }
72
73     public void accept(Visitor v) throws JspException JavaDoc {
74         v.visit(this);
75     }
76
77     public String JavaDoc getText() {
78         return text;
79     }
80     }
81
82     /**
83      * Represents anything else EL expression, including function arguments etc
84      */

85     public static class ELText extends ELNode {
86
87     private String JavaDoc text;
88
89     public ELText(String JavaDoc text) {
90         this.text = text;
91     }
92
93     public void accept(Visitor v) throws JspException JavaDoc {
94         v.visit(this);
95     }
96
97     public String JavaDoc getText() {
98         return text;
99     }
100     }
101
102     /**
103      * Represents a function
104      * Currently only the prefix and function name, but not its arguments.
105      */

106     public static class Function extends ELNode {
107
108     private String JavaDoc prefix;
109     private String JavaDoc name;
110     private String JavaDoc uri;
111     private FunctionInfo JavaDoc functionInfo;
112     private String JavaDoc methodName;
113     private String JavaDoc[] parameters;
114
115     Function(String JavaDoc prefix, String JavaDoc name) {
116         this.prefix = prefix;
117         this.name = name;
118     }
119
120     public void accept(Visitor v) throws JspException JavaDoc {
121         v.visit(this);
122     }
123
124     public String JavaDoc getPrefix() {
125         return prefix;
126     }
127
128     public String JavaDoc getName() {
129         return name;
130     }
131
132     public void setUri(String JavaDoc uri) {
133         this.uri = uri;
134     }
135
136     public String JavaDoc getUri() {
137         return uri;
138     }
139
140     public void setFunctionInfo(FunctionInfo JavaDoc f) {
141         this.functionInfo = f;
142     }
143
144     public FunctionInfo JavaDoc getFunctionInfo() {
145         return functionInfo;
146     }
147
148     public void setMethodName(String JavaDoc methodName) {
149         this.methodName = methodName;
150     }
151
152     public String JavaDoc getMethodName() {
153         return methodName;
154     }
155
156     public void setParameters(String JavaDoc[] parameters) {
157         this.parameters = parameters;
158     }
159
160     public String JavaDoc[] getParameters() {
161         return parameters;
162     }
163     }
164
165     /**
166      * An ordered list of ELNode.
167      */

168     public static class Nodes {
169
170     /* Name used for creating a map for the functions in this
171        EL expression, for communication to Generator.
172      */

173     String JavaDoc mapName = null;
174     private List<ELNode> list;
175
176     public Nodes() {
177         list = new ArrayList<ELNode>();
178     }
179
180     public void add(ELNode en) {
181         list.add(en);
182     }
183
184     /**
185      * Visit the nodes in the list with the supplied visitor
186      * @param v The visitor used
187      */

188     public void visit(Visitor v) throws JspException JavaDoc {
189             for (ELNode n: list) {
190         n.accept(v);
191         }
192     }
193
194     public Iterator<ELNode> iterator() {
195         return list.iterator();
196     }
197
198     public boolean isEmpty() {
199         return list.size() == 0;
200     }
201
202     /**
203      * @return true if the expression contains a ${...}
204      */

205     public boolean containsEL() {
206         Iterator<ELNode> iter = list.iterator();
207         while (iter.hasNext()) {
208         ELNode n = iter.next();
209         if (n instanceof Root) {
210             return true;
211         }
212         }
213         return false;
214     }
215
216     public void setMapName(String JavaDoc name) {
217         this.mapName = name;
218     }
219
220     public String JavaDoc getMapName() {
221         return mapName;
222     }
223     }
224
225     public static class Visitor {
226
227     public void visit(Root n) throws JspException JavaDoc {
228         n.getExpression().visit(this);
229     }
230
231     public void visit(Function n) throws JspException JavaDoc {
232     }
233
234     public void visit(Text n) throws JspException JavaDoc {
235     }
236
237     public void visit(ELText n) throws JspException JavaDoc {
238     }
239     }
240 }
241
242
Popular Tags