Coverage Report - org.apache.commons.flatfile.morph.IndexedEntityCollectionReflector
 
Classes in this File Line Coverage Branch Coverage Complexity
IndexedEntityCollectionReflector
93%
13/14
50%
6/12
0
 
 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: 760707 $ $Date: 2009-03-31 17:53:22 -0500 (Tue, 31 Mar 2009) $
 30  
  */
 31  6
 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  
     protected Entity getEntity(Object container, int index) throws Exception {
 43  6
         return ((IndexedEntityCollection) container).getChild(index);
 44  
     }
 45  
 
 46  
     /**
 47  
      * {@inheritDoc}
 48  
      */
 49  
     protected Class<?>[] getReflectableClassesImpl() throws Exception {
 50  5
         return new Class[] { IndexedEntityCollection.class };
 51  
     }
 52  
 
 53  
     /**
 54  
      * {@inheritDoc}
 55  
      */
 56  
     protected boolean isEntity(Object bean, String propertyName)
 57  
             throws Exception {
 58  169
         if (bean instanceof EntityArray
 59  
                 && IMPLICIT_PROPERTY_PROTOTYPE.equals(propertyName)) {
 60  33
             return true;
 61  
         }
 62  
         try {
 63  136
             return Integer.parseInt(propertyName) < getSize(bean);
 64  136
         } catch (Exception e) {
 65  136
             return false;
 66  
         }
 67  
     }
 68  
 
 69  
     /**
 70  
      * {@inheritDoc}
 71  
      */
 72  
     protected Object getImpl(Object bean, String propertyName) throws Exception {
 73  31
         return super.getImpl(bean, propertyName);
 74  
     }
 75  
 
 76  
     /**
 77  
      * {@inheritDoc}
 78  
      * @see com.pgac.flatfile.morph.BaseEntityCollectionReflector#getEntity(java.lang.Object, java.lang.String)
 79  
      */
 80  
     protected Entity getEntity(Object bean, String propertyName)
 81  
             throws Exception {
 82  12
         if (bean instanceof EntityArray
 83  
                 && IMPLICIT_PROPERTY_PROTOTYPE.equals(propertyName)) {
 84  12
             return ((EntityArray) bean).getPrototype();
 85  
         }
 86  0
         return super.getEntity(bean, propertyName);
 87  
     }
 88  
 
 89  
     /**
 90  
      * {@inheritDoc}
 91  
      * @see com.pgac.flatfile.morph.BaseEntityCollectionReflector#getSizeImpl(java.lang.Object)
 92  
      */
 93  
     protected int getSizeImpl(Object o) throws Exception {
 94  105
         int size = ((IndexedEntityCollection) o).size();
 95  105
         return size < 0 ? 0 : size;
 96  
     }
 97  
 }