Coverage Report - org.apache.commons.flatfile.morph.IndexedEntityCollectionReflector
 
Classes in this File Line Coverage Branch Coverage Complexity
IndexedEntityCollectionReflector
93%
15/16
56%
9/16
2.5
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.flatfile.morph;
 18  
 
 19  
 import net.sf.morph.reflect.BeanReflector;
 20  
 import net.sf.morph.reflect.MutableIndexedContainerReflector;
 21  
 import net.sf.morph.reflect.SizableReflector;
 22  
 
 23  
 import org.apache.commons.flatfile.Entity;
 24  
 import org.apache.commons.flatfile.EntityArray;
 25  
 import org.apache.commons.flatfile.IndexedEntityCollection;
 26  
 
 27  
 /**
 28  
  * IndexedEntityCollection Reflector.
 29  
  * @version $Revision: 1301237 $ $Date: 2012-03-15 17:08:23 -0500 (Thu, 15 Mar 2012) $
 30  
  */
 31  36
 public class IndexedEntityCollectionReflector extends
 32  
         BaseEntityCollectionReflector implements
 33  
         MutableIndexedContainerReflector, SizableReflector, BeanReflector {
 34  
     /**
 35  
      * Prototype property constant.
 36  
      */
 37  
     public static final String IMPLICIT_PROPERTY_PROTOTYPE = "prototype";
 38  
 
 39  
     /**
 40  
      * {@inheritDoc}
 41  
      */
 42  
     @Override
 43  
     protected Entity getEntity(Object container, int index) throws Exception {
 44  36
         return ((IndexedEntityCollection) container).getChild(index);
 45  
     }
 46  
 
 47  
     /**
 48  
      * {@inheritDoc}
 49  
      */
 50  
     @Override
 51  
     protected Class<?>[] getReflectableClassesImpl() throws Exception {
 52  30
         return new Class[] { IndexedEntityCollection.class };
 53  
     }
 54  
 
 55  
     /**
 56  
      * {@inheritDoc}
 57  
      */
 58  
     @Override
 59  
     protected boolean isEntity(Object bean, String propertyName)
 60  
             throws Exception {
 61  1014
         if (bean instanceof EntityArray
 62  338
                 && IMPLICIT_PROPERTY_PROTOTYPE.equals(propertyName)) {
 63  198
             return true;
 64  
         }
 65  
         try {
 66  816
             return Integer.parseInt(propertyName) < getSize(bean);
 67  816
         } catch (Exception e) {
 68  816
             return false;
 69  
         }
 70  
     }
 71  
 
 72  
     /**
 73  
      * {@inheritDoc}
 74  
      */
 75  
     @Override
 76  
     protected Object getImpl(Object bean, String propertyName) throws Exception {
 77  186
         return super.getImpl(bean, propertyName);
 78  
     }
 79  
 
 80  
     /**
 81  
      * {@inheritDoc}
 82  
      */
 83  
     @Override
 84  
     protected Entity getEntity(Object bean, String propertyName)
 85  
             throws Exception {
 86  72
         if (bean instanceof EntityArray
 87  24
                 && IMPLICIT_PROPERTY_PROTOTYPE.equals(propertyName)) {
 88  72
             return ((EntityArray) bean).getPrototype();
 89  
         }
 90  0
         return super.getEntity(bean, propertyName);
 91  
     }
 92  
 
 93  
     /**
 94  
      * {@inheritDoc}
 95  
      */
 96  
     @Override
 97  
     protected int getSizeImpl(Object o) throws Exception {
 98  630
         int size = ((IndexedEntityCollection) o).size();
 99  630
         return size < 0 ? 0 : size;
 100  
     }
 101  
 }