Search in sources :

Example 1 with RelationMode

use of siena.core.RelationMode in project siena by mandubian.

the class Model method init.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void init() {
    // initialize Query<T> types
    Class<?> clazz = getClass();
    // Takes into account superclass fields for inheritance!!!!
    ClassInfo info = ClassInfo.getClassInfo(clazz);
    for (Field field : info.queryFieldMap.keySet()) {
        try {
            Map<FieldMapKeys, Object> map = info.queryFieldMap.get(field);
            Util.setField(this, field, new ProxyQuery((Class<?>) map.get(FieldMapKeys.CLASS), (String) map.get(FieldMapKeys.FILTER), this));
        } catch (Exception e) {
            throw new SienaException(e);
        }
    }
    for (Field field : info.manyFieldMap.keySet()) {
        try {
            Map<FieldMapKeys, Object> map = info.manyFieldMap.get(field);
            RelationMode mode = (RelationMode) map.get(FieldMapKeys.MODE);
            switch(mode) {
                case AGGREGATION:
                    Util.setField(this, field, new ProxyMany((Class<?>) map.get(FieldMapKeys.CLASS), this, (RelationMode) map.get(FieldMapKeys.MODE), field));
                    break;
                case RELATION:
                    Util.setField(this, field, new ProxyMany((Class<?>) map.get(FieldMapKeys.CLASS), this, (RelationMode) map.get(FieldMapKeys.MODE), (Field) map.get(FieldMapKeys.FIELD)));
                    break;
            }
        } catch (Exception e) {
            throw new SienaException(e);
        }
    }
    for (Field field : info.oneFieldMap.keySet()) {
        try {
            Map<FieldMapKeys, Object> map = info.oneFieldMap.get(field);
            RelationMode mode = (RelationMode) map.get(FieldMapKeys.MODE);
            switch(mode) {
                case AGGREGATION:
                    Util.setField(this, field, new ProxyOne((Class<?>) map.get(FieldMapKeys.CLASS), this, (RelationMode) map.get(FieldMapKeys.MODE), field));
                    break;
                case RELATION:
                    Util.setField(this, field, new ProxyOne((Class<?>) map.get(FieldMapKeys.CLASS), this, (RelationMode) map.get(FieldMapKeys.MODE), (Field) map.get(FieldMapKeys.FIELD)));
                    break;
            }
        } catch (Exception e) {
            throw new SienaException(e);
        }
    }
}
Also used : RelationMode(siena.core.RelationMode) Field(java.lang.reflect.Field) FieldMapKeys(siena.ClassInfo.FieldMapKeys)

Aggregations

Field (java.lang.reflect.Field)1 FieldMapKeys (siena.ClassInfo.FieldMapKeys)1 RelationMode (siena.core.RelationMode)1