Coverage report

  %line %branch
org.apache.commons.jexl.util.PropertyExecutor
90% 
87% 

 1  
 /*
 2  
  * Copyright 2000-2002,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  
 
 18  
 import java.lang.reflect.InvocationTargetException;
 19  
 
 20  
 import org.apache.commons.jexl.util.introspection.Introspector;
 21  
 import org.apache.commons.logging.Log;
 22  
 
 23  
 /**
 24  
  * Returned the value of object property when executed.
 25  
  */
 26  
 public class PropertyExecutor extends AbstractExecutor
 27  
 {
 28  198
     protected Introspector introspector = null;
 29  
 
 30  198
     protected String methodUsed = null;
 31  
 
 32  
     public PropertyExecutor(Log r, Introspector ispctr,
 33  
                             Class clazz, String property)
 34  198
     {
 35  198
         rlog = r;
 36  198
         introspector = ispctr;
 37  
 
 38  198
         discover(clazz, property);
 39  198
     }
 40  
 
 41  
     protected void discover(Class clazz, String property)
 42  
     {
 43  
         /*
 44  
          *  this is gross and linear, but it keeps it straightforward.
 45  
          */
 46  
 
 47  
         try
 48  
         {
 49  
             char c;
 50  
             StringBuffer sb;
 51  
 
 52  180
             Object[] params = {  };
 53  
 
 54  
             /*
 55  
              *  start with get<property>
 56  
              *  this leaves the property name 
 57  
              *  as is...
 58  
              */
 59  180
             sb = new StringBuffer("get");
 60  180
             sb.append(property);
 61  
 
 62  180
             methodUsed = sb.toString();
 63  
 
 64  180
             method = introspector.getMethod(clazz, methodUsed, params);
 65  
              
 66  180
             if (method != null)
 67  0
                 return;
 68  
         
 69  
             /*
 70  
              *  now the convenience, flip the 1st character
 71  
              */
 72  
          
 73  180
             sb = new StringBuffer("get");
 74  180
             sb.append(property);
 75  
 
 76  180
             c = sb.charAt(3);
 77  
 
 78  180
             if (Character.isLowerCase(c))
 79  
             {
 80  180
                 sb.setCharAt(3, Character.toUpperCase(c));
 81  
             }
 82  
             else
 83  
             {
 84  0
                 sb.setCharAt(3, Character.toLowerCase(c));
 85  
             }
 86  
 
 87  180
             methodUsed = sb.toString();
 88  180
             method = introspector.getMethod(clazz, methodUsed, params);
 89  
 
 90  180
             if (method != null)
 91  162
                 return; 
 92  
             
 93  16
         }
 94  
         catch(Exception e)
 95  
         {
 96  0
             rlog.error("PROGRAMMER ERROR : PropertyExector() : " + e );
 97  2
         }
 98  18
     }
 99  
 
 100  
 
 101  
     /**
 102  
      * Execute method against context.
 103  
      */
 104  
     public Object execute(Object o)
 105  
         throws IllegalAccessException,  InvocationTargetException
 106  
     {
 107  180
         if (method == null)
 108  0
             return null;
 109  
 
 110  180
         return method.invoke(o, null);
 111  
     }
 112  
 }
 113  
 
 114  
 

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.