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