Coverage report

| %line | %branch
--- | --- | ---
org.apache.commons.jexl.util.PropertyExecutor |
85% |
72% |

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 | 330 |
         protected Introspector introspector = null;
29 |  |
30 | 330 |
         protected String methodUsed = null;
31 |  |
32 | 22 |
         public PropertyExecutor(Log r, Introspector ispctr,
33 |  |
                                 Class clazz, String property)
34 | 308 |
         {
35 | 330 |
             rlog = r;
36 | 330 |
             introspector = ispctr;
37 |  |
38 | 330 |
             discover(clazz, property);
39 | 330 |
         }
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 | 300 |
                 Object[] params = {  };
53 |  |
54 |  |
                 /*
55 |  |
                  *  start with get<property>
56 |  |
                  *  this leaves the property name
57 |  |
                  *  as is...
58 |  |
                  */
59 | 300 |
                 sb = new StringBuffer("get");
60 | 300 |
                 sb.append(property);
61 |  |
62 | 300 |
                 methodUsed = sb.toString();
63 |  |
64 | 300 |
                 method = introspector.getMethod(clazz, methodUsed, params);
65 |  |
66 | 300 |
                 if (method != null)
67 | 0 |
                     return;
68 |  |
69 |  |
                 /*
70 |  |
                  *  now the convenience, flip the 1st character
71 |  |
                  */
72 |  |
73 | 300 |
                 sb = new StringBuffer("get");
74 | 300 |
                 sb.append(property);
75 |  |
76 | 300 |
                 c = sb.charAt(3);
77 |  |
78 | 300 |
                 if (Character.isLowerCase(c))
79 |  |
                 {
80 | 300 |
                     sb.setCharAt(3, Character.toUpperCase(c));
81 |  |
                 }
82 |  |
                 else
83 |  |
                 {
84 | 0 |
                     sb.setCharAt(3, Character.toLowerCase(c));
85 |  |
                 }
86 |  |
87 | 300 |
                 methodUsed = sb.toString();
88 | 300 |
                 method = introspector.getMethod(clazz, methodUsed, params);
89 |  |
90 | 300 |
                 if (method != null)
91 | 270 |
                     return;
92 |  |
93 | 20 |
             }
94 |  |
             catch(Exception e)
95 |  |
             {
96 | 0 |
                 rlog.error("PROGRAMMER ERROR : PropertyExector() : " + e );
97 | 8 |
             }
98 | 30 |
         }
99 |  |
100 |  |
101 |  |
         /**
102 |  |
          * Execute method against context.
103 |  |
          */
104 |  |
         public Object execute(Object o)
105 |  |
             throws IllegalAccessException,  InvocationTargetException
106 |  |
         {
107 | 300 |
             if (method == null)
108 | 0 |
                 return null;
109 |  |
110 | 300 |
             return method.invoke(o, null);
111 |  |
         }
112 |  |
     }
113 |  |
114 |  |

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