| 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 | 6 | 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 | |
protected Entity getEntity(Object container, int index) throws Exception { |
| 43 | 6 | return ((IndexedEntityCollection) container).getChild(index); |
| 44 | |
} |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
protected Class<?>[] getReflectableClassesImpl() throws Exception { |
| 50 | 5 | return new Class[] { IndexedEntityCollection.class }; |
| 51 | |
} |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
protected boolean isEntity(Object bean, String propertyName) |
| 57 | |
throws Exception { |
| 58 | 169 | if (bean instanceof EntityArray |
| 59 | |
&& IMPLICIT_PROPERTY_PROTOTYPE.equals(propertyName)) { |
| 60 | 33 | return true; |
| 61 | |
} |
| 62 | |
try { |
| 63 | 136 | return Integer.parseInt(propertyName) < getSize(bean); |
| 64 | 136 | } catch (Exception e) { |
| 65 | 136 | return false; |
| 66 | |
} |
| 67 | |
} |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
protected Object getImpl(Object bean, String propertyName) throws Exception { |
| 73 | 31 | return super.getImpl(bean, propertyName); |
| 74 | |
} |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
protected Entity getEntity(Object bean, String propertyName) |
| 81 | |
throws Exception { |
| 82 | 12 | if (bean instanceof EntityArray |
| 83 | |
&& IMPLICIT_PROPERTY_PROTOTYPE.equals(propertyName)) { |
| 84 | 12 | return ((EntityArray) bean).getPrototype(); |
| 85 | |
} |
| 86 | 0 | return super.getEntity(bean, propertyName); |
| 87 | |
} |
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
protected int getSizeImpl(Object o) throws Exception { |
| 94 | 105 | int size = ((IndexedEntityCollection) o).size(); |
| 95 | 105 | return size < 0 ? 0 : size; |
| 96 | |
} |
| 97 | |
} |