| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 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 | |
|
| 39 | |
|
| 40 | |
|
| 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 | |
|
| 48 | |
|
| 49 | |
protected int getSizeImpl(Object container) throws Exception { |
| 50 | 0 | return 1; |
| 51 | |
} |
| 52 | |
} |
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 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 | |
|
| 66 | |
|
| 67 | |
@SuppressWarnings("unchecked") |
| 68 | |
public synchronized void setSourceClasses(Class[] sourceClasses) { |
| 69 | 0 | super.setSourceClasses(sourceClasses); |
| 70 | 0 | } |
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 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 | |
|
| 84 | |
|
| 85 | |
@SuppressWarnings("unchecked") |
| 86 | |
public synchronized void setDestinationClasses(Class[] destinationClasses) { |
| 87 | 0 | super.setDestinationClasses(destinationClasses); |
| 88 | 0 | } |
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
protected Class<?>[] getDestinationClassesImpl() throws Exception { |
| 94 | 2 | return DEST_CLASSES; |
| 95 | |
} |
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 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 | |
|
| 111 | |
|
| 112 | |
protected boolean isAutomaticallyHandlingNulls() { |
| 113 | 1 | return false; |
| 114 | |
} |
| 115 | |
} |