KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.jsp.PageContext JavaDoc;
20
21 import org.apache.taglibs.standard.lang.jpath.adapter.IterationContext;
22
23 /**
24  * The LastFunction class
25  *
26  *
27  * @author <a HREF='mailto:scott.hasse@isthmusgroup.com'>Scott Hasse</a>
28  * @version
29  */

30 public class LastFunction extends SimpleNode {
31
32     /**
33      * Used to create an instance of the LastFunction class
34      *
35      *
36      * @param id
37      *
38      */

39     public LastFunction(int id) {
40         super(id);
41     }
42
43     /**
44      * Used to create an instance of the LastFunction class
45      *
46      *
47      * @param p
48      * @param id
49      *
50      */

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

65     public String JavaDoc toNormalizedString() {
66
67         String JavaDoc normalized = "";
68
69         normalized = "last()";
70
71         return normalized;
72     }
73
74     /**
75      * This method evaluates this node of the expression and all child nodes.
76      * It returns the result of the
77      * evaluation as an <tt>Object</tt>. If any problems are encountered
78      * during the evaluation, an <tt>EvaluationException</tt> is thrown.
79      *
80      *
81      * @param pageContext the current JSP PageContext
82      *
83      * @param icontext the Iteration Context of the expression. If there is
84      * no interation context, this should be null.
85      *
86      * @return the result of the expression evaluation as an object
87      *
88      * @throws EvaluationException if a problem is encountered during the
89      * evaluation
90      */

91     public Object JavaDoc evaluate(PageContext JavaDoc pageContext, IterationContext icontext)
92             throws EvaluationException {
93
94         if (icontext == null) {
95             throw new EvaluationException(this,
96                     "The last() function can "
97                     + "only be used in the context of a predicate");
98         }
99
100         return new Double JavaDoc(icontext.getLast());
101     }
102 }
103
Popular Tags