use of com.andframe.util.java.AfReflecter in project AndFrameWorks by scwang90.
the class Injecter method inject.
private static void inject(Field field, Object handler, Context context) {
if (field.isAnnotationPresent(Inject.class)) {
try {
Object value = null;
Class<?> clazz = field.getType();
if (clazz.equals(Resources.class)) {
value = context.getResources();
} else if (clazz.equals(Random.class)) {
value = new Random();
} else if (clazz.equals(AfDialogBuilder.class)) {
value = new AfDialogBuilder(context);
} else if (clazz.equals(AfDensity.class)) {
value = new AfDensity();
} else if (clazz.equals(AfReflecter.class)) {
value = new AfReflecter();
// } else if (clazz.equals(AfDesHelper.class)) {
// value = new AfDesHelper();
// } else if (clazz.equals(AfDeviceInfo.class)) {
// value = new AfDeviceInfo(context);
// } else if (clazz.equals(AfDistance.class)) {
// value = new AfDistance();
// } else if (clazz.equals(AfGifHelper.class)) {
// value = new AfGifHelper();
// } else if (clazz.equals(AfImageHelper.class)) {
// value = new AfImageHelper();
} else if (clazz.equals(AfSharedPreference.class)) {
value = new AfSharedPreference(context, field.getAnnotation(Inject.class).value());
} else if (clazz.equals(Cacher.class)) {
value = new AfDurableCacher(field.getAnnotation(Inject.class).value());
} else if (clazz.equals(AfDurableCacher.class)) {
value = new AfDurableCacher(field.getAnnotation(Inject.class).value());
} else if (clazz.equals(AfPrivateCacher.class)) {
value = new AfPrivateCacher(field.getAnnotation(Inject.class).value());
} else if (clazz.equals(AfJsonCache.class)) {
value = new AfJsonCache(context, field.getAnnotation(Inject.class).value());
// } else if (clazz.equals(AfImageCaches.class)) {
// value = AfImageCaches.getInstance();
} else if (AfApp.class.isAssignableFrom(clazz)) {
value = AfApp.get();
} else if (AfAppSettings.class.isAssignableFrom(clazz)) {
value = AfApp.get().newAppSetting();
// } else if (AfEntityDao.class.isAssignableFrom(clazz)) {
// value = clazz.getConstructor(Context.class).newInstance(context);
}
if (value != null) {
field.setAccessible(true);
field.set(handler, value);
}
} catch (Throwable e) {
AfExceptionHandler.handle(e, TAG(handler, "doInject.Inject") + field.getName());
}
}
}
Aggregations