1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jexl.parser;
18
19 import org.apache.commons.jexl.JexlContext;
20
21 import java.util.Collection;
22 import java.util.Map;
23
24 /***
25 * function to see if reference doesn't exist in context
26 *
27 * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
28 * @author <a href="mailto:tobrien@apache.org">Tim O'Brien</a>
29 * @version $Id: ASTEmptyFunction.java,v 1.6 2004/08/23 13:30:36 dion Exp $
30 */
31 public class ASTEmptyFunction extends SimpleNode
32 {
33 public ASTEmptyFunction(int id)
34 {
35 super(id);
36 }
37
38 public ASTEmptyFunction(Parser p, int id)
39 {
40 super(p, id);
41 }
42
43 /*** Accept the visitor. **/
44 public Object jjtAccept(ParserVisitor visitor, Object data)
45 {
46 return visitor.visit(this, data);
47 }
48
49 public Object value(JexlContext jc)
50 throws Exception
51 {
52 SimpleNode sn = (SimpleNode) jjtGetChild(0);
53
54
55
56
57
58 Object o = sn.value(jc);
59
60 if (o == null)
61 return Boolean.TRUE;
62
63 if (o instanceof String && "".equals((String) o))
64 return Boolean.TRUE;
65
66 if (o.getClass().isArray() && ((Object[])o).length == 0)
67 return Boolean.TRUE;
68
69 if (o instanceof Collection && ((Collection)o).isEmpty())
70 return Boolean.TRUE;
71
72
73
74
75 if (o instanceof Map && ((Map)o).isEmpty())
76 return Boolean.TRUE;
77
78 return Boolean.FALSE;
79 }
80 }