Coverage Report - org.apache.tapestry.enhance.GenericsClassInspectorImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
GenericsClassInspectorImpl
0%
0/27
0%
0/16
5
 
 1  
 // Copyright 2004, 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 package org.apache.tapestry.enhance;
 15  
 
 16  
 import org.apache.hivemind.ApplicationRuntimeException;
 17  
 
 18  
 import java.beans.Introspector;
 19  
 import java.lang.reflect.Method;
 20  
 
 21  
 
 22  
 /**
 23  
  * Implementation of {@link ClassInspector} that can properly handle
 24  
  * jre 1.5 generic types.
 25  
  */
 26  0
 public class GenericsClassInspectorImpl implements ClassInspector
 27  
 {
 28  
 
 29  
     /**
 30  
      * {@inheritDoc}
 31  
      */
 32  
     public MethodSignature getMethodSignature(Class implementing, Method m)
 33  
     {
 34  0
         return new GenericsMethodSignatureImpl(implementing, m);
 35  
     }
 36  
     
 37  
     /**
 38  
      * {@inheritDoc}
 39  
      */
 40  
     public MethodSignature getPropertyAccessor(Class type, String propertyName)
 41  
     {
 42  
         try {
 43  0
             Method[] props = type.getMethods();
 44  0
             Method match = null;
 45  
             
 46  0
             for (int i=0; i < props.length; i++) {
 47  
 
 48  0
                 String propName = getPropertyName(props[i]);
 49  
 
 50  0
                 if (!propertyName.equals(propName)) {
 51  0
                     continue;
 52  
                 }
 53  
 
 54  
                 // store for later retrieval if necessary
 55  0
                 if (match == null)
 56  0
                     match = props[i];
 57  
                 
 58  
                 // try to find read methods before resorting to write
 59  0
                 if (props[i].getReturnType() == void.class) {
 60  0
                     continue;
 61  
                 }
 62  
 
 63  0
                 return new GenericsMethodSignatureImpl(type, props[i]);
 64  
             } 
 65  
 
 66  0
             if (match != null)
 67  0
                 return new GenericsMethodSignatureImpl(type, match);
 68  
 
 69  0
         } catch (Throwable t) {
 70  
             
 71  0
             throw new ApplicationRuntimeException("Error reading property " + propertyName + " from base class : " + type, t);
 72  0
         }
 73  
         
 74  0
         return null;
 75  
     }
 76  
 
 77  
     static String getPropertyName(Method m)
 78  
     {
 79  0
         String name = m.getName();
 80  
 
 81  0
         if (name.startsWith("get"))
 82  0
             name = name.substring(3);
 83  0
         else if (name.startsWith("set"))
 84  0
             name = name.substring(3);
 85  0
         else if (name.startsWith("is"))
 86  0
             name = name.substring(2);
 87  
 
 88  0
         return Introspector.decapitalize(name);
 89  
     }
 90  
 }