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. package org.apache.commons.jexl.util;
  17. import org.apache.commons.logging.Log;
  18. /**
  19. * Handles discovery and valuation of a
  20. * boolean object property, of the
  21. * form public boolean is<property> when executed.
  22. *
  23. * We do this separately as to preserve the current
  24. * quasi-broken semantics of get<as is property>
  25. * get< flip 1st char> get("property") and now followed
  26. * by is<Property>
  27. *
  28. * @author <a href="geirm@apache.org">Geir Magnusson Jr.</a>
  29. * @version $Id: BooleanPropertyExecutor.java,v 1.4 2004/02/28 13:45:21 yoavs Exp $
  30. */
  31. public class BooleanPropertyExecutor extends PropertyExecutor
  32. {
  33. public BooleanPropertyExecutor(Log rlog, org.apache.commons.jexl.util.introspection.Introspector is, Class clazz, String property)
  34. {
  35. super(rlog, is, clazz, property);
  36. }
  37. protected void discover(Class clazz, String property)
  38. {
  39. try
  40. {
  41. char c;
  42. StringBuffer sb;
  43. Object[] params = { };
  44. /*
  45. * now look for a boolean isFoo
  46. */
  47. sb = new StringBuffer("is");
  48. sb.append(property);
  49. c = sb.charAt(2);
  50. if (Character.isLowerCase(c))
  51. {
  52. sb.setCharAt(2, Character.toUpperCase(c));
  53. }
  54. methodUsed = sb.toString();
  55. method = introspector.getMethod(clazz, methodUsed, params);
  56. if (method != null)
  57. {
  58. /*
  59. * now, this has to return a boolean
  60. */
  61. if (method.getReturnType() == Boolean.TYPE)
  62. return;
  63. method = null;
  64. }
  65. }
  66. catch(Exception e)
  67. {
  68. rlog.error("PROGRAMMER ERROR : BooleanPropertyExector() : " + e);
  69. }
  70. }
  71. }