Coverage Report - org.apache.commons.flatfile.morph.EntityInstantiatingReflector
 
Classes in this File Line Coverage Branch Coverage Complexity
EntityInstantiatingReflector
69%
11/16
25%
1/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 org.apache.commons.flatfile.Entity;
 20  
 import org.apache.commons.flatfile.EntityFactory;
 21  
 import org.apache.commons.flatfile.IndexedEntityCollection;
 22  
 
 23  
 import net.sf.morph.reflect.InstantiatingReflector;
 24  
 import net.sf.morph.reflect.Reflector;
 25  
 import net.sf.morph.reflect.reflectors.BaseReflector;
 26  
 import net.sf.morph.reflect.reflectors.SimpleDelegatingReflector;
 27  
 
 28  
 /**
 29  
  * Instantiates basic entities by sending the source object as a cue object
 30  
  * to a configured EntityFactory.
 31  
  * @version $Revision: 758023 $ $Date: 2009-03-24 16:09:19 -0500 (Tue, 24 Mar 2009) $
 32  
  */
 33  
 public class EntityInstantiatingReflector extends BaseReflector implements
 34  
         InstantiatingReflector {
 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  1
     private static final SimpleDelegatingReflector CONTAINER_REFLECTOR = new SimpleDelegatingReflector(
 40  
             new Reflector[] { new EntityCollectionReflector() }, true);
 41  
 
 42  
     private EntityFactory entityFactory;
 43  
 
 44  
     /**
 45  
      * Create a new EntityInstantiatingReflector.
 46  
      */
 47  0
     public EntityInstantiatingReflector() {
 48  
         // default constructor
 49  0
     }
 50  
 
 51  
     /**
 52  
      * Create a new EntityInstantiatingReflector.
 53  
      * @param entityFactory to use
 54  
      */
 55  2
     public EntityInstantiatingReflector(EntityFactory entityFactory) {
 56  2
         setEntityFactory(entityFactory);
 57  2
     }
 58  
 
 59  
     /**
 60  
      * {@inheritDoc}
 61  
      */
 62  
     protected Class<?>[] getReflectableClassesImpl() throws Exception {
 63  2
         return new Class[] { Entity.class };
 64  
     }
 65  
 
 66  
     /**
 67  
      * Get the entityFactory.
 68  
      * @return EntityFactory.
 69  
      */
 70  
     public EntityFactory getEntityFactory() {
 71  6
         return entityFactory;
 72  
     }
 73  
 
 74  
     /**
 75  
      * Set the entityFactory.
 76  
      * @param entityFactory The EntityFactory entityFactory to set.
 77  
      */
 78  
     public void setEntityFactory(EntityFactory entityFactory) {
 79  2
         this.entityFactory = entityFactory;
 80  2
     }
 81  
 
 82  
     /**
 83  
      * {@inheritDoc}
 84  
      */
 85  
     @SuppressWarnings("unchecked")
 86  
     protected Object newInstanceImpl(Class destType, Object source)
 87  
             throws Exception {
 88  6
         Entity e = getEntityFactory().getEntity(source);
 89  6
         if (e instanceof IndexedEntityCollection) {
 90  0
             IndexedEntityCollection c = (IndexedEntityCollection) e;
 91  0
             if (c.isSizable()) {
 92  0
                 c.setSize(CONTAINER_REFLECTOR.getSize(source));
 93  
             }
 94  
         }
 95  6
         return e;
 96  
     }
 97  
 
 98  
 }