KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > facelets > tag > jstl > fn > JstlFnLibrary


1 /**
2  * Licensed under the Common Development and Distribution License,
3  * you may not use this file except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://www.sun.com/cddl/
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11  * implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */

14
15 package com.sun.facelets.tag.jstl.fn;
16
17 import java.lang.reflect.Method JavaDoc;
18 import java.lang.reflect.Modifier JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import javax.faces.FacesException;
23
24 import com.sun.facelets.tag.TagConfig;
25 import com.sun.facelets.tag.TagHandler;
26 import com.sun.facelets.tag.TagLibrary;
27
28 /**
29  * Library for JSTL Functions
30  *
31  * @author Jacob Hookom
32  * @version $Id: JstlFnLibrary.java,v 1.2 2005/08/24 04:38:59 jhook Exp $
33  */

34 public class JstlFnLibrary implements TagLibrary {
35
36     public final static String JavaDoc Namespace = "http://java.sun.com/jsp/jstl/functions";
37     
38     private final Map JavaDoc fns = new HashMap JavaDoc();
39     
40     public JstlFnLibrary() {
41         super();
42         try {
43             Method JavaDoc[] methods = JstlFunction.class.getMethods();
44             for (int i = 0; i < methods.length; i++) {
45                 if (Modifier.isStatic(methods[i].getModifiers())) {
46                     fns.put(methods[i].getName(), methods[i]);
47                 }
48             }
49         } catch (Exception JavaDoc e) {
50             throw new RuntimeException JavaDoc(e);
51         }
52     }
53
54     public boolean containsNamespace(String JavaDoc ns) {
55         return Namespace.equals(ns);
56     }
57
58     public boolean containsTagHandler(String JavaDoc ns, String JavaDoc localName) {
59         return false;
60     }
61
62     public TagHandler createTagHandler(String JavaDoc ns, String JavaDoc localName,
63             TagConfig tag) throws FacesException {
64         return null;
65     }
66
67     public boolean containsFunction(String JavaDoc ns, String JavaDoc name) {
68         if (Namespace.equals(ns)) {
69             return this.fns.containsKey(name);
70         }
71         return false;
72     }
73
74     public Method JavaDoc createFunction(String JavaDoc ns, String JavaDoc name) {
75         if (Namespace.equals(ns)) {
76             return (Method JavaDoc) this.fns.get(name);
77         }
78         return null;
79     }
80     
81     public static void main(String JavaDoc[] argv) {
82         JstlFnLibrary lib = new JstlFnLibrary();
83         System.out.println(lib.containsFunction(JstlFnLibrary.Namespace, "toUpperCase"));
84     }
85
86 }
87
Popular Tags