Coverage Report - org.apache.commons.flatfile.morph.IndexedEntityCollectionInstantiatingReflector
 
Classes in this File Line Coverage Branch Coverage Complexity
IndexedEntityCollectionInstantiatingReflector
0%
0/12
0%
0/4
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.InstantiatingReflector;
 20  
 import net.sf.morph.reflect.Reflector;
 21  
 import net.sf.morph.reflect.reflectors.BaseReflector;
 22  
 import net.sf.morph.reflect.reflectors.SimpleDelegatingReflector;
 23  
 
 24  
 import org.apache.commons.flatfile.Entity;
 25  
 import org.apache.commons.flatfile.EntityArray;
 26  
 import org.apache.commons.flatfile.IndexedEntityCollection;
 27  
 
 28  
 /**
 29  
  * IndexedEntityCollection InstantiatingReflector.
 30  
  * @version $Revision: 757266 $ $Date: 2009-03-22 17:12:27 -0500 (Sun, 22 Mar 2009) $
 31  
  */
 32  0
 public class IndexedEntityCollectionInstantiatingReflector extends
 33  
         BaseReflector implements InstantiatingReflector {
 34  
 
 35  
     // use a SimpleDelegatingReflector prepended with an
 36  
     // EntityCollectionReflector to get the
 37  
     // size and contained type of source objects when implementing
 38  
     // InstantiatingReflector
 39  0
     private static final SimpleDelegatingReflector CONTAINER_REFLECTOR = new SimpleDelegatingReflector(
 40  
             new Reflector[] { new EntityCollectionReflector() }, true);
 41  
 
 42  
     private InstantiatingReflector componentReflector;
 43  
 
 44  
     /**
 45  
      * {@inheritDoc}
 46  
      */
 47  
     protected Class<?>[] getReflectableClassesImpl() throws Exception {
 48  0
         return new Class[] { IndexedEntityCollection.class };
 49  
     }
 50  
 
 51  
     /**
 52  
      * Get the componentReflector.
 53  
      * @return InstantiatingReflector.
 54  
      */
 55  
     public synchronized InstantiatingReflector getComponentReflector() {
 56  0
         return componentReflector;
 57  
     }
 58  
 
 59  
     /**
 60  
      * Set the componentReflector.  Essential for use of this class as an InstantiatingReflector.
 61  
      * @param componentReflector The InstantiatingReflector componentReflector to set.
 62  
      */
 63  
     public synchronized void setComponentReflector(
 64  
             InstantiatingReflector componentReflector) {
 65  0
         this.componentReflector = componentReflector;
 66  0
     }
 67  
 
 68  
     /**
 69  
      * {@inheritDoc}
 70  
      */
 71  
     @SuppressWarnings("unchecked")
 72  
     protected Object newInstanceImpl(Class destType, Object source)
 73  
             throws Exception {
 74  0
         int size = CONTAINER_REFLECTOR.getSize(source);
 75  0
         if (size == 0) {
 76  0
             return new EntityArray(0);
 77  
         }
 78  0
         Class containedType = source == null ? null : CONTAINER_REFLECTOR
 79  
                 .getContainedType(source.getClass());
 80  0
         Entity prototype = (Entity) getComponentReflector().newInstance(
 81  
                 destType, containedType);
 82  0
         return new EntityArray(prototype, size);
 83  
     }
 84  
 
 85  
 }