Coverage Report - org.apache.commons.flatfile.morph.EntityInstantiatingReflector
 
Classes in this File Line Coverage Branch Coverage Complexity
EntityInstantiatingReflector
70%
12/17
25%
1/4
1.333
 
 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: 1301237 $ $Date: 2012-03-15 17:08:23 -0500 (Thu, 15 Mar 2012) $
 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  8
     private static final SimpleDelegatingReflector CONTAINER_REFLECTOR = new SimpleDelegatingReflector(
 40  4
             new Reflector[] { new EntityCollectionReflector() }, true);
 41  
 
 42  
     private EntityFactory entityFactory;
 43  
 
 44  
     /**
 45  
      * Create a new EntityInstantiatingReflector.
 46  
      */
 47  
     public EntityInstantiatingReflector() {
 48  0
         super();
 49  0
     }
 50  
 
 51  
     /**
 52  
      * Create a new EntityInstantiatingReflector.
 53  
      * @param entityFactory to use
 54  
      */
 55  12
     public EntityInstantiatingReflector(EntityFactory entityFactory) {
 56  12
         setEntityFactory(entityFactory);
 57  12
     }
 58  
 
 59  
     /**
 60  
      * {@inheritDoc}
 61  
      */
 62  
     @Override
 63  
     protected Class<?>[] getReflectableClassesImpl() throws Exception {
 64  12
         return new Class[] { Entity.class };
 65  
     }
 66  
 
 67  
     /**
 68  
      * Get the entityFactory.
 69  
      * @return EntityFactory.
 70  
      */
 71  
     public EntityFactory getEntityFactory() {
 72  36
         return entityFactory;
 73  
     }
 74  
 
 75  
     /**
 76  
      * Set the entityFactory.
 77  
      * @param entityFactory The EntityFactory entityFactory to set.
 78  
      */
 79  
     public void setEntityFactory(EntityFactory entityFactory) {
 80  12
         this.entityFactory = entityFactory;
 81  12
     }
 82  
 
 83  
     /**
 84  
      * {@inheritDoc}
 85  
      */
 86  
     @Override
 87  
     protected Object newInstanceImpl(@SuppressWarnings("rawtypes") Class destType, Object source)
 88  
             throws Exception {
 89  36
         Entity e = getEntityFactory().getEntity(source);
 90  36
         if (e instanceof IndexedEntityCollection) {
 91  0
             IndexedEntityCollection c = (IndexedEntityCollection) e;
 92  0
             if (c.isSizable()) {
 93  0
                 c.setSize(CONTAINER_REFLECTOR.getSize(source));
 94  
             }
 95  
         }
 96  36
         return e;
 97  
     }
 98  
 
 99  
 }