KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > lang > jstl > test > StaticFunctionTests


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.jstl.test;
18
19 import java.util.HashMap JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.apache.taglibs.standard.lang.jstl.Evaluator;
23
24 /**
25  *
26  * <p>This class contains some test functions.</p>
27  *
28  * @author Shawn Bayern
29  */

30
31 public class StaticFunctionTests {
32
33   public static void main(String JavaDoc args[]) throws Exception JavaDoc {
34     Map JavaDoc m = getSampleMethodMap();
35     Evaluator e = new Evaluator();
36     Object JavaDoc o;
37     o = e.evaluate("", "4", Integer JavaDoc.class, null, null, m, "foo");
38     System.out.println(o);
39     o = e.evaluate("", "${4}", Integer JavaDoc.class, null, null, m, "foo");
40     System.out.println(o);
41     o = e.evaluate("", "${2+2}", Integer JavaDoc.class, null, null, m, "foo");
42     System.out.println(o);
43     o = e.evaluate("", "${foo:add(2, 3)}", Integer JavaDoc.class, null, null, m, "foo");
44     System.out.println(o);
45     o = e.evaluate("", "${foo:multiply(2, 3)}", Integer JavaDoc.class, null, null, m, "foo");
46     System.out.println(o);
47     o = e.evaluate("", "${add(2, 3)}", Integer JavaDoc.class, null, null, m, "foo");
48     System.out.println(o);
49     o = e.evaluate("", "${multiply(2, 3)}", Integer JavaDoc.class, null, null, m, "foo");
50     System.out.println(o);
51     o = e.evaluate("", "${add(2, 3) + 5}", Integer JavaDoc.class, null, null, m, "foo");
52     System.out.println(o);
53
54     System.out.println("---");
55     o = e.evaluate("", "${getInt(getInteger(getInt(5)))}", Integer JavaDoc.class, null, null, m, "foo");
56     System.out.println(o);
57     o = e.evaluate("", "${getInteger(getInt(getInteger(5)))}", Integer JavaDoc.class, null, null, m, "foo");
58     System.out.println(o);
59     o = e.evaluate("", "${getInt(getInt(getInt(5)))}", Integer JavaDoc.class, null, null, m, "foo");
60     System.out.println(o);
61     o = e.evaluate("", "${getInteger(getInteger(getInteger(5)))}", Integer JavaDoc.class, null, null, m, "foo");
62     System.out.println(o);
63
64   }
65
66   public static int add(int a, int b) {
67     return a + b;
68   }
69
70   public static int multiply(int a, int b) {
71     return a * b;
72   }
73
74   public static int getInt(Integer JavaDoc i) {
75     return i.intValue();
76   }
77
78   public static Integer JavaDoc getInteger(int i) {
79     return new Integer JavaDoc(i);
80   }
81
82   public static Map JavaDoc getSampleMethodMap() throws Exception JavaDoc {
83     Map JavaDoc m = new HashMap JavaDoc();
84     Class JavaDoc c = StaticFunctionTests.class;
85     m.put("foo:add",
86      c.getMethod("add", new Class JavaDoc[] { Integer.TYPE, Integer.TYPE }));
87     m.put("foo:multiply",
88      c.getMethod("multiply", new Class JavaDoc[] { Integer.TYPE, Integer.TYPE }));
89     m.put("foo:getInt",
90      c.getMethod("getInt", new Class JavaDoc[] { Integer JavaDoc.class }));
91     m.put("foo:getInteger",
92      c.getMethod("getInteger", new Class JavaDoc[] { Integer.TYPE }));
93     return m;
94   }
95
96 }
97
Popular Tags