01: /*
02: * Copyright 2000-2001,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
17: package org.apache.commons.jexl.util;
18:
19: import org.apache.commons.logging.Log;
20:
21: /**
22: * Handles discovery and valuation of a
23: * boolean object property, of the
24: * form public boolean is<Property> when executed.
25: *
26: * We do this separately as to preserve the current
27: * quasi-broken semantics of get <as is property>
28: * get<flip 1st char> get("property") and now followed
29: * by is<Property>.
30: *
31: * @since 1.0
32: * @author <a href="geirm@apache.org">Geir Magnusson Jr.</a>
33: * @version $Id: BooleanPropertyExecutor.java 398171 2006-04-29 14:57:29Z dion $
34: */
35: public class BooleanPropertyExecutor extends PropertyExecutor {
36:
37: /**
38: * Constructor.
39: *
40: * @param rlog The instance log.
41: * @param is The JEXL introspector.
42: * @param clazz The class being analyzed.
43: * @param property The boolean property.
44: */
45: public BooleanPropertyExecutor(Log rlog,
46: org.apache.commons.jexl.util.introspection.Introspector is,
47: Class clazz, String property) {
48: super (rlog, is, clazz, property);
49: }
50:
51: /**
52: * Locate the getter method for this boolean property.
53: *
54: * @param clazz The class being analyzed.
55: * @param property Name of boolean property.
56: */
57: protected void discover(Class clazz, String property) {
58: try {
59: char c;
60: StringBuffer sb;
61:
62: Object[] params = {};
63:
64: /*
65: * now look for a boolean isFoo
66: */
67:
68: sb = new StringBuffer("is");
69: sb.append(property);
70:
71: c = sb.charAt(2);
72:
73: if (Character.isLowerCase(c)) {
74: sb.setCharAt(2, Character.toUpperCase(c));
75: }
76:
77: methodUsed = sb.toString();
78: method = introspector.getMethod(clazz, methodUsed, params);
79:
80: if (method != null) {
81: /*
82: * now, this has to return a boolean
83: */
84:
85: if (method.getReturnType() == Boolean.TYPE) {
86: return;
87: }
88:
89: method = null;
90: }
91: } catch (Exception e) {
92: rlog.error("PROGRAMMER ERROR : BooleanPropertyExector() : "
93: + e);
94: }
95: }
96: }
|