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 398190 2006-04-29 16:04:10Z dion $
30   */
31  public class ASTEmptyFunction extends SimpleNode {
32      /***
33       * Create the node given an id.
34       * 
35       * @param id node id.
36       */
37      public ASTEmptyFunction(int id) {
38          super(id);
39      }
40  
41      /***
42       * Create a node with the given parser and id.
43       * 
44       * @param p a parser.
45       * @param id node id.
46       */
47      public ASTEmptyFunction(Parser p, int id) {
48          super(p, id);
49      }
50  
51      /*** {@inheritDoc} */
52      public Object jjtAccept(ParserVisitor visitor, Object data) {
53          return visitor.visit(this, data);
54      }
55  
56      /*** {@inheritDoc} */
57      public Object value(JexlContext jc) throws Exception {
58          SimpleNode sn = (SimpleNode) jjtGetChild(0);
59  
60          
61  
62  
63  
64          Object o = sn.value(jc);
65  
66          if (o == null) {
67              return Boolean.TRUE;
68          }
69  
70          if (o instanceof String && "".equals(o)) {
71              return Boolean.TRUE;
72          }
73  
74          if (o.getClass().isArray() && ((Object[]) o).length == 0) {
75              return Boolean.TRUE;
76          }
77  
78          if (o instanceof Collection && ((Collection) o).isEmpty()) {
79              return Boolean.TRUE;
80          }
81  
82          
83  
84  
85          if (o instanceof Map && ((Map) o).isEmpty()) {
86              return Boolean.TRUE;
87          }
88  
89          return Boolean.FALSE;
90      }
91  }