Coverage Report - org.apache.commons.clazz.reflect.standard.StandardReflectedListPropertyIntrospector
 
Classes in this File Line Coverage Branch Coverage Complexity
StandardReflectedListPropertyIntrospector
0%
0/37
0%
0/20
4.5
 
 1  
 /*
 2  
  * Copyright 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.clazz.reflect.standard;
 17  
 
 18  
 import java.lang.reflect.Method;
 19  
 import java.util.HashMap;
 20  
 import java.util.Iterator;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.apache.commons.clazz.reflect.ReflectedClazz;
 24  
 import org.apache.commons.clazz.reflect.common.*;
 25  
 
 26  
 /**
 27  
  * A ReflectedPropertyIntrospector that discovers list (aka indexed) properties.
 28  
  * 
 29  
  * @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
 30  
  * @version $Id: StandardReflectedListPropertyIntrospector.java 155436 2005-02-26 13:17:48Z dirkv $
 31  
  */
 32  0
 public class StandardReflectedListPropertyIntrospector
 33  
     extends ReflectedListPropertyIntrospectorSupport 
 34  
 {
 35  
     public void introspectProperties(
 36  
             ReflectedClazz clazz,
 37  
             Class javaClass,
 38  
             Map parseResultMap)
 39  
     {
 40  0
         HashMap parseResultMapSingular = new HashMap();
 41  0
         Method methods[] = javaClass.getMethods();
 42  
         ReflectedListPropertyParseResults parseResults;
 43  
         AccessorMethodParseResults results;
 44  0
         for (int i = 0; i < methods.length; i++) {
 45  0
             Method method = methods[i];
 46  
             
 47  0
             results = getReadAccessMethodParser().parse(method);
 48  0
             if (results != null) {
 49  0
                 parseResults =
 50  
                     getParseResults(
 51  
                         clazz,
 52  
                         parseResultMap,
 53  
                         results.getPropertyName());
 54  0
                 parseResults.setReadMethodParseResults(results);
 55  0
                 continue;
 56  
             }
 57  
 
 58  0
             results = getWriteAccessMethodParser().parse(method);
 59  0
             if (results != null) {
 60  0
                 parseResults =
 61  
                     getParseResults(
 62  
                         clazz,
 63  
                         parseResultMap,
 64  
                         results.getPropertyName());
 65  0
                 parseResults.setWriteMethodParseResults(results);
 66  0
                 continue;
 67  
             }
 68  
 
 69  0
             results = getGetAccessMethodParser().parse(method);
 70  0
             if (results != null) {
 71  0
                 parseResults =
 72  
                     getParseResults(
 73  
                         clazz,
 74  
                         parseResultMapSingular,
 75  
                         results.getPropertyName());
 76  0
                 parseResults.setGetMethodParseResults(results);
 77  0
                 continue;
 78  
             }
 79  
             
 80  0
             results = getSetAccessMethodParser().parse(method);
 81  0
             if (results != null) {
 82  0
                 parseResults =
 83  
                     getParseResults(
 84  
                         clazz,
 85  
                         parseResultMapSingular,
 86  
                         results.getPropertyName());
 87  0
                 parseResults.setSetMethodParseResults(results);
 88  0
                 continue;
 89  
             }            
 90  
         }
 91  
         
 92  0
         Iterator iter = parseResultMap.entrySet().iterator();
 93  0
         while (iter.hasNext()) {
 94  0
             Map.Entry entry = (Map.Entry) iter.next();
 95  0
             ReflectedListPropertyParseResults result = 
 96  
                 (ReflectedListPropertyParseResults) entry.getValue();
 97  
                 
 98  0
             Class propertyType = result.getPropertyType();
 99  0
             Class componentType = result.getContentType();
 100  
 
 101  0
             if (propertyType != null
 102  
                 && (!propertyType.isArray()
 103  
                     || (componentType != null
 104  
                         && propertyType.getComponentType() != componentType))) {
 105  0
                 iter.remove(); // @todo verify that this actually works
 106  
             }
 107  0
         }
 108  
         
 109  0
         mergeSingularMethods(parseResultMap, parseResultMapSingular);
 110  0
     }
 111  
 
 112  
     /**
 113  
      * With the standard JavaBean indexed properties the plural form is the same
 114  
      * as the singular form.
 115  
      */
 116  
     protected boolean isCorrectPluralForm(String singular, String plural) {
 117  0
         return singular.equals(plural);
 118  
     }    
 119  
 }