1 package org.apache.velocity.runtime.parser.node;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.velocity.exception.VelocityException;
23 import org.apache.velocity.runtime.RuntimeLogger;
24 import org.apache.velocity.runtime.log.Log;
25 import org.apache.velocity.runtime.log.RuntimeLoggerLog;
26 import org.apache.velocity.util.introspection.Introspector;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public class BooleanPropertyExecutor extends PropertyExecutor
42 {
43
44
45
46
47
48
49
50 public BooleanPropertyExecutor(final Log log, final Introspector introspector,
51 final Class clazz, final String property)
52 {
53 super(log, introspector, clazz, property);
54 }
55
56
57
58
59
60
61
62
63 public BooleanPropertyExecutor(final RuntimeLogger rlog, final Introspector introspector,
64 final Class clazz, final String property)
65 {
66 super(new RuntimeLoggerLog(rlog), introspector, clazz, property);
67 }
68
69 protected void discover(final Class clazz, final String property)
70 {
71 try
72 {
73 Object [] params = {};
74
75 StringBuffer sb = new StringBuffer("is");
76 sb.append(property);
77
78 setMethod(getIntrospector().getMethod(clazz, sb.toString(), params));
79
80 if (!isAlive())
81 {
82
83
84
85
86 char c = sb.charAt(2);
87
88 if (Character.isLowerCase(c))
89 {
90 sb.setCharAt(2, Character.toUpperCase(c));
91 }
92 else
93 {
94 sb.setCharAt(2, Character.toLowerCase(c));
95 }
96
97 setMethod(getIntrospector().getMethod(clazz, sb.toString(), params));
98 }
99
100 if (isAlive())
101 {
102 if( getMethod().getReturnType() != Boolean.TYPE &&
103 getMethod().getReturnType() != Boolean.class )
104 {
105 setMethod(null);
106 }
107 }
108 }
109
110
111
112 catch( RuntimeException e )
113 {
114 throw e;
115 }
116 catch(Exception e)
117 {
118 String msg = "Exception while looking for boolean property getter for '" + property;
119 log.error(msg, e);
120 throw new VelocityException(msg, e);
121 }
122 }
123 }