1 package org.apache.commons.ognl;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.ognl.enhance.UnsupportedCompilationException;
23
24
25
26
27
28
29 public abstract class BooleanExpression
30 extends ExpressionNode
31 implements NodeType
32 {
33
34 private static final long serialVersionUID = 8630306635724834872L;
35
36 protected Class<?> getterClass;
37
38 public BooleanExpression( int id )
39 {
40 super( id );
41 }
42
43 public BooleanExpression( OgnlParser p, int id )
44 {
45 super( p, id );
46 }
47
48
49
50
51 public Class<?> getGetterClass()
52 {
53 return getterClass;
54 }
55
56
57
58
59 public Class<?> getSetterClass()
60 {
61 return null;
62 }
63
64
65
66
67 @Override
68 public String toGetSourceString( OgnlContext context, Object target )
69 {
70 try
71 {
72
73 Object value = getValueBody( context, target );
74
75 if ( value != null && Boolean.class.isAssignableFrom( value.getClass() ) )
76 {
77 getterClass = Boolean.TYPE;
78 }
79 else if ( value != null )
80 {
81 getterClass = value.getClass();
82 }
83 else
84 {
85 getterClass = Boolean.TYPE;
86 }
87
88 String ret = super.toGetSourceString( context, target );
89
90 if ( "(false)".equals( ret ) )
91 {
92 return "false";
93 }
94 else if ( "(true)".equals( ret ) )
95 {
96 return "true";
97 }
98 return ret;
99
100 }
101 catch ( NullPointerException e )
102 {
103
104
105 e.printStackTrace();
106
107 throw new UnsupportedCompilationException( "evaluation resulted in null expression." );
108 }
109 catch ( Throwable t )
110 {
111 throw OgnlOps.castToRuntime( t );
112 }
113 }
114 }