KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > tag > el > core > ExpressionUtil


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.tag.el.core;
18
19 import javax.servlet.jsp.JspException JavaDoc;
20 import javax.servlet.jsp.PageContext JavaDoc;
21 import javax.servlet.jsp.tagext.Tag JavaDoc;
22
23 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
24 import org.apache.taglibs.standard.tag.common.core.NullAttributeException;
25
26 /**
27  * <p>Contains some static utilities to facilitate common forms of
28  * expression evaluation.</p>
29  *
30  * @author Shawn Bayern
31  */

32
33 public class ExpressionUtil {
34
35     /** Evaluates an expression if present, but does not allow the expression
36      * to evaluate to 'null', throwing a NullAttributeException if it
37      * does. The function <b>can</b> return null, however, if the
38      * expression itself is null.
39      */

40     public static Object JavaDoc evalNotNull(String JavaDoc tagName,
41                      String JavaDoc attributeName,
42                                  String JavaDoc expression,
43                      Class JavaDoc expectedType,
44                      Tag JavaDoc tag,
45                                  PageContext JavaDoc pageContext)
46             throws JspException JavaDoc {
47         if (expression != null) {
48             Object JavaDoc r = ExpressionEvaluatorManager.evaluate(
49                 attributeName, expression, expectedType, tag, pageContext);
50             if (r == null)
51                 throw new NullAttributeException(tagName, attributeName);
52         return r;
53         } else
54         return null;
55     }
56 }
57
Popular Tags