Coverage Report - org.apache.commons.flatfile.morph.ContainerToIndexedEntityCollectionCopier
 
Classes in this File Line Coverage Branch Coverage Complexity
ContainerToIndexedEntityCollectionCopier
79%
15/19
100%
4/4
0
ContainerToIndexedEntityCollectionCopier$1
N/A
N/A
0
ContainerToIndexedEntityCollectionCopier$SizeOneReflector
50%
1/2
N/A
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 java.util.Locale;
 20  
 
 21  
 import org.apache.commons.flatfile.IndexedEntityCollection;
 22  
 
 23  
 import net.sf.morph.reflect.Reflector;
 24  
 import net.sf.morph.reflect.SizableReflector;
 25  
 import net.sf.morph.reflect.reflectors.ArrayReflector;
 26  
 import net.sf.morph.reflect.reflectors.CollectionReflector;
 27  
 import net.sf.morph.reflect.reflectors.EnumerationReflector;
 28  
 import net.sf.morph.reflect.reflectors.IteratorReflector;
 29  
 import net.sf.morph.reflect.reflectors.ListReflector;
 30  
 import net.sf.morph.reflect.reflectors.ObjectReflector;
 31  
 import net.sf.morph.reflect.reflectors.SetReflector;
 32  
 import net.sf.morph.reflect.reflectors.SimpleDelegatingReflector;
 33  
 import net.sf.morph.reflect.reflectors.SortedSetReflector;
 34  
 import net.sf.morph.transform.copiers.ContainerCopier;
 35  
 import net.sf.morph.transform.TransformationException;
 36  
 
 37  
 /**
 38  
  * Copies containers to IndexedEntityCollections. Additionally recognizes <code>null</code> copy source as an empty
 39  
  * collection.
 40  
  * @version $Revision: 757266 $ $Date: 2009-03-22 17:12:27 -0500 (Sun, 22 Mar 2009) $
 41  
  */
 42  
 public class ContainerToIndexedEntityCollectionCopier extends ContainerCopier {
 43  1
     private static final Class<?>[] DEST_CLASSES = new Class[] { IndexedEntityCollection.class };
 44  
 
 45  4
     private static class SizeOneReflector extends ObjectReflector implements SizableReflector {
 46  
         /**
 47  
          * {@inheritDoc}
 48  
          */
 49  
         protected int getSizeImpl(Object container) throws Exception {
 50  0
             return 1;
 51  
         }
 52  
     }
 53  
 
 54  
     /**
 55  
      * Create a new ContainerToIndexedEntityCollectionCopier
 56  
      */
 57  2
     public ContainerToIndexedEntityCollectionCopier() {
 58  2
         setReflector(new SimpleDelegatingReflector(new Reflector[] {
 59  
                 new EntityCollectionReflector(), new ListReflector(), new SortedSetReflector(),
 60  
                 new SetReflector(), new EnumerationReflector(), new IteratorReflector(),
 61  
                 new ArrayReflector(), new CollectionReflector(), new SizeOneReflector() }));
 62  2
     }
 63  
 
 64  
     /**
 65  
      * {@inheritDoc}
 66  
      */
 67  
     @SuppressWarnings("unchecked")
 68  
     public synchronized void setSourceClasses(Class[] sourceClasses) {
 69  0
         super.setSourceClasses(sourceClasses);
 70  0
     }
 71  
 
 72  
     /**
 73  
      * {@inheritDoc}
 74  
      */
 75  
     protected Class<?>[] getSourceClassesImpl() throws Exception {
 76  2
         Class<?>[] c = getBeanReflector().getReflectableClasses();
 77  2
         Class<?>[] result = new Class[c.length + 1];
 78  2
         System.arraycopy(c, 0, result, 0, c.length);
 79  2
         return result;
 80  
     }
 81  
 
 82  
     /**
 83  
      * {@inheritDoc}
 84  
      */
 85  
     @SuppressWarnings("unchecked")
 86  
     public synchronized void setDestinationClasses(Class[] destinationClasses) {
 87  0
         super.setDestinationClasses(destinationClasses);
 88  0
     }
 89  
 
 90  
     /**
 91  
      * {@inheritDoc}
 92  
      */
 93  
     protected Class<?>[] getDestinationClassesImpl() throws Exception {
 94  2
         return DEST_CLASSES;
 95  
     }
 96  
 
 97  
     /**
 98  
      * {@inheritDoc}
 99  
      */
 100  
     protected void copyImpl(Object destination, Object source, Locale locale,
 101  
             Integer preferredTransformationType) throws TransformationException {
 102  3
         int size = source == null ? 0 : getBeanReflector().getSize(source);
 103  3
         ((IndexedEntityCollection) destination).setSize(size);
 104  3
         if (size > 0) {
 105  1
             super.copyImpl(destination, source, locale, preferredTransformationType);
 106  
         }
 107  3
     }
 108  
 
 109  
     /**
 110  
      * {@inheritDoc}
 111  
      */
 112  
     protected boolean isAutomaticallyHandlingNulls() {
 113  1
         return false;
 114  
     }
 115  
 }