Coverage Report - org.apache.commons.ognl.internal.entry.MethodCacheEntryFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
MethodCacheEntryFactory
100%
15/15
100%
10/10
3.5
 
 1  
 package org.apache.commons.ognl.internal.entry;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 /*
 23  
  * $Id: MethodCacheEntryFactory.java 1194957 2011-10-29 18:04:20Z mcucchiara $
 24  
  */
 25  
 
 26  
 
 27  
 import org.apache.commons.ognl.OgnlRuntime;
 28  
 import org.apache.commons.ognl.internal.CacheException;
 29  
 
 30  
 import java.lang.reflect.Method;
 31  
 import java.util.ArrayList;
 32  
 import java.util.HashMap;
 33  
 import java.util.List;
 34  
 import java.util.Map;
 35  
 
 36  362
 public abstract class MethodCacheEntryFactory<T extends MethodCacheEntry>
 37  
     implements CacheEntryFactory<T, Map<String, List<Method>>>
 38  
 {
 39  
     public Map<String, List<Method>> create( T key )
 40  
         throws CacheException
 41  
     {
 42  359
         Map<String, List<Method>> result = new HashMap<String, List<Method>>( 23 );
 43  
 
 44  359
         Class<?> c = key.targetClass;
 45  1144
         while ( c != null )
 46  
         {
 47  9152
             for ( Method method : c.getDeclaredMethods() )
 48  
             {
 49  
                 // skip over synthetic methods
 50  
 
 51  8367
                 if ( !OgnlRuntime.isMethodCallable( method ) )
 52  
                 {
 53  99
                     continue;
 54  
                 }
 55  
 
 56  8268
                 if ( shouldCache( key, method ) )
 57  
                 {
 58  6425
                     List<Method> ml = result.get( method.getName() );
 59  
 
 60  6425
                     if ( ml == null )
 61  
                     {
 62  5167
                         ml = new ArrayList<Method>();
 63  5167
                         result.put( method.getName(), ml );
 64  
                     }
 65  
 
 66  6425
                     ml.add( method );
 67  
                 }
 68  
             }
 69  785
             c = c.getSuperclass();
 70  
         }
 71  359
         return result;
 72  
     }
 73  
 
 74  
     protected abstract boolean shouldCache( T key, Method method );
 75  
 }