1 | package org.apache.velocity.runtime.parser.node; |
2 | /* |
3 | * Copyright 2000-2001,2004 The Apache Software Foundation. |
4 | * |
5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | * you may not use this file except in compliance with the License. |
7 | * You may obtain a copy of the License at |
8 | * |
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | * |
11 | * Unless required by applicable law or agreed to in writing, software |
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | * See the License for the specific language governing permissions and |
15 | * limitations under the License. |
16 | */ |
17 | |
18 | import org.apache.velocity.util.introspection.Introspector; |
19 | |
20 | import org.apache.velocity.runtime.RuntimeLogger; |
21 | |
22 | /** |
23 | * Handles discovery and valuation of a |
24 | * boolean object property, of the |
25 | * form public boolean is<property> when executed. |
26 | * |
27 | * We do this separately as to preserve the current |
28 | * quasi-broken semantics of get<as is property> |
29 | * get< flip 1st char> get("property") and now followed |
30 | * by is<Property> |
31 | * |
32 | * @author <a href="geirm@apache.org">Geir Magnusson Jr.</a> |
33 | * @version $Id: BooleanPropertyExecutor.java,v 1.3.4.1 2004/03/03 23:22:59 geirm Exp $ |
34 | */ |
35 | public class BooleanPropertyExecutor extends PropertyExecutor |
36 | { |
37 | public BooleanPropertyExecutor(RuntimeLogger rlog, Introspector is, Class clazz, String property) |
38 | { |
39 | super(rlog, is, clazz, property); |
40 | } |
41 | |
42 | protected void discover(Class clazz, String property) |
43 | { |
44 | try |
45 | { |
46 | char c; |
47 | StringBuffer sb; |
48 | |
49 | Object[] params = { }; |
50 | |
51 | /* |
52 | * now look for a boolean isFoo |
53 | */ |
54 | |
55 | sb = new StringBuffer("is"); |
56 | sb.append(property); |
57 | |
58 | c = sb.charAt(2); |
59 | |
60 | if (Character.isLowerCase(c)) |
61 | { |
62 | sb.setCharAt(2, Character.toUpperCase(c)); |
63 | } |
64 | |
65 | methodUsed = sb.toString(); |
66 | method = introspector.getMethod(clazz, methodUsed, params); |
67 | |
68 | if (method != null) |
69 | { |
70 | /* |
71 | * now, this has to return a boolean |
72 | */ |
73 | |
74 | if (method.getReturnType() == Boolean.TYPE) |
75 | return; |
76 | |
77 | method = null; |
78 | } |
79 | } |
80 | catch(Exception e) |
81 | { |
82 | rlog.error("PROGRAMMER ERROR : BooleanPropertyExector() : " + e); |
83 | } |
84 | } |
85 | } |