KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > expression > IsNullFunction


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 package org.apache.cocoon.forms.expression;
17
18 import org.outerj.expression.AbstractExpression;
19 import org.outerj.expression.Expression;
20 import org.outerj.expression.ExpressionContext;
21 import org.outerj.expression.ExpressionException;
22
23 /**
24  * Returns true if argument is null.
25  *
26  * @author <a HREF="mailto:vadim.gritsenko@dc.gov">Vadim Gritsenko</a>
27  * @version $Id: IsNullFunction.java 151179 2005-02-03 16:55:16Z tim $
28  */

29 public class IsNullFunction extends AbstractExpression {
30
31     public Object JavaDoc evaluate(ExpressionContext context) throws ExpressionException {
32         Object JavaDoc result = null;
33         try {
34             result = ((Expression)arguments.get(0)).evaluate(context);
35         } catch (ExpressionException e) {
36             // FIXME: Hack to handle null variables
37
if (!e.getMessage().startsWith("Unknown variable")) {
38                 throw e;
39             }
40         }
41         return result == null? Boolean.TRUE: Boolean.FALSE;
42     }
43
44     public void check() throws ExpressionException {
45         if (arguments.size() != 1) {
46             throw new ExpressionException(getDescription() + " requires one argument.", getLine(), getColumn());
47         }
48     }
49
50     public Class JavaDoc getResultType() {
51         return Boolean JavaDoc.class;
52     }
53
54     public String JavaDoc getDescription() {
55         return "IsNull function";
56     }
57 }
58
Popular Tags