KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > lang > jpath > expression > ListLiteral


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.standard.lang.jpath.expression;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collection JavaDoc;
21
22 import javax.servlet.jsp.PageContext JavaDoc;
23
24 import org.apache.taglibs.standard.lang.jpath.adapter.IterationContext;
25
26 /**
27  * The ListLiteral class
28  *
29  *
30  * @author <a HREF='mailto:scott.hasse@isthmusgroup.com'>Scott Hasse</a>
31  * @version
32  */

33 public class ListLiteral extends SimpleNode {
34
35     /**
36      * Used to create an instance of the ListLiteral class
37      *
38      *
39      * @param id
40      *
41      */

42     public ListLiteral(int id) {
43         super(id);
44     }
45
46     /**
47      * Used to create an instance of the ListLiteral class
48      *
49      *
50      * @param p
51      * @param id
52      *
53      */

54     public ListLiteral(Parser p, int id) {
55         super(p, id);
56     }
57
58     /**
59      * Provides a method to print a normalized version of the original
60      * expression. The normalized version has standardized spacing and
61      * parenthesis, and can be used to compare expressions formatted
62      * in different ways to see if they are actually the same expression.
63      *
64      *
65      * @return The normalized version of the original expression
66      *
67      */

68     public String JavaDoc toNormalizedString() {
69
70         boolean first = true;
71         String JavaDoc normalized;
72
73         normalized = "{";
74
75         if (children != null) {
76             for (int i = 0; i < children.length; ++i) {
77                 if (!first) {
78                     normalized = normalized + ",";
79                 }
80
81                 first = false;
82
83                 SimpleNode n = (SimpleNode) children[i];
84
85                 if (n != null) {
86                     normalized = normalized + n.toNormalizedString();
87                 }
88             }
89         }
90
91         normalized = normalized + "}";
92
93         return normalized;
94     }
95
96     /**
97      * This method evaluates this node of the expression and all child nodes.
98      * It returns the result of the
99      * evaluation as an <tt>Object</tt>. If any problems are encountered
100      * during the evaluation, an <tt>EvaluationException</tt> is thrown.
101      *
102      *
103      * @param pageContext the current JSP PageContext
104      *
105      * @param icontext the Iteration Context of the expression. If there is
106      * no interation context, this should be null.
107      *
108      * @return the result of the expression evaluation as an object
109      *
110      * @throws EvaluationException if a problem is encountered during the
111      * evaluation
112      */

113     public Object JavaDoc evaluate(PageContext JavaDoc pageContext, IterationContext icontext)
114             throws EvaluationException {
115
116         Collection JavaDoc c = new ArrayList JavaDoc();
117
118         for (int i = 0; i < jjtGetNumChildren(); i++) {
119             c.add(jjtGetChild(i).evaluate(pageContext, icontext));
120         }
121
122         return c;
123     }
124 }
125
Popular Tags