| 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 net.sf.morph.reflect.BeanReflector; |
| 20 | |
import net.sf.morph.reflect.MutableIndexedContainerReflector; |
| 21 | |
import net.sf.morph.reflect.SizableReflector; |
| 22 | |
|
| 23 | |
import org.apache.commons.flatfile.Entity; |
| 24 | |
import org.apache.commons.flatfile.EntityArray; |
| 25 | |
import org.apache.commons.flatfile.IndexedEntityCollection; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | 36 | public class IndexedEntityCollectionReflector extends |
| 32 | |
BaseEntityCollectionReflector implements |
| 33 | |
MutableIndexedContainerReflector, SizableReflector, BeanReflector { |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
public static final String IMPLICIT_PROPERTY_PROTOTYPE = "prototype"; |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
@Override |
| 43 | |
protected Entity getEntity(Object container, int index) throws Exception { |
| 44 | 36 | return ((IndexedEntityCollection) container).getChild(index); |
| 45 | |
} |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
@Override |
| 51 | |
protected Class<?>[] getReflectableClassesImpl() throws Exception { |
| 52 | 30 | return new Class[] { IndexedEntityCollection.class }; |
| 53 | |
} |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
@Override |
| 59 | |
protected boolean isEntity(Object bean, String propertyName) |
| 60 | |
throws Exception { |
| 61 | 1014 | if (bean instanceof EntityArray |
| 62 | 338 | && IMPLICIT_PROPERTY_PROTOTYPE.equals(propertyName)) { |
| 63 | 198 | return true; |
| 64 | |
} |
| 65 | |
try { |
| 66 | 816 | return Integer.parseInt(propertyName) < getSize(bean); |
| 67 | 816 | } catch (Exception e) { |
| 68 | 816 | return false; |
| 69 | |
} |
| 70 | |
} |
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
@Override |
| 76 | |
protected Object getImpl(Object bean, String propertyName) throws Exception { |
| 77 | 186 | return super.getImpl(bean, propertyName); |
| 78 | |
} |
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
@Override |
| 84 | |
protected Entity getEntity(Object bean, String propertyName) |
| 85 | |
throws Exception { |
| 86 | 72 | if (bean instanceof EntityArray |
| 87 | 24 | && IMPLICIT_PROPERTY_PROTOTYPE.equals(propertyName)) { |
| 88 | 72 | return ((EntityArray) bean).getPrototype(); |
| 89 | |
} |
| 90 | 0 | return super.getEntity(bean, propertyName); |
| 91 | |
} |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
@Override |
| 97 | |
protected int getSizeImpl(Object o) throws Exception { |
| 98 | 630 | int size = ((IndexedEntityCollection) o).size(); |
| 99 | 630 | return size < 0 ? 0 : size; |
| 100 | |
} |
| 101 | |
} |