com.jfinal.aop.Inject Java Examples

The following examples show how to use com.jfinal.aop.Inject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JbootAopFactory.java    From jboot with Apache License 2.0 5 votes vote down vote up
private void doInjectByName(Object targetObject, Field field, Inject inject, String name) throws ReflectiveOperationException {
    Object fieldInjectedObject = getBean(name);
    if (fieldInjectedObject != null) {
        setFieldValue(field, targetObject, fieldInjectedObject);
    } else {
        LOG.warn("can not inject by name [" + name + "] in " + targetObject.getClass() + "." + field.getName() + ", use default.");
        doInjectJFinalOrginal(targetObject, field, inject);
    }
}
 
Example #2
Source File: JbootAopFactory.java    From jboot with Apache License 2.0 5 votes vote down vote up
/**
 * JFinal 原生 service 注入
 *
 * @param targetObject
 * @param field
 * @param inject
 * @throws ReflectiveOperationException
 */
private void doInjectJFinalOrginal(Object targetObject, Field field, Inject inject) throws ReflectiveOperationException {
    Class<?> fieldInjectedClass = inject.value();
    if (fieldInjectedClass == Void.class) {
        fieldInjectedClass = field.getType();
    }

    Object fieldInjectedObject = doGet(fieldInjectedClass);

    setFieldValue(field, targetObject, fieldInjectedObject);
}
 
Example #3
Source File: JbootAopFactory.java    From jboot with Apache License 2.0 4 votes vote down vote up
@Override
protected void doInject(Class<?> targetClass, Object targetObject) throws ReflectiveOperationException {
    targetClass = getUsefulClass(targetClass);
    Field[] fields = targetClass.getDeclaredFields();

    if (fields.length != 0) {

        for (Field field : fields) {

            Inject inject = field.getAnnotation(Inject.class);
            if (inject != null) {
                Bean bean = field.getAnnotation(Bean.class);
                String beanName = bean != null ? AnnotationUtil.get(bean.name()) : null;
                if (StrUtil.isNotBlank(beanName)) {
                    doInjectByName(targetObject, field, inject, beanName);
                } else {
                    doInjectJFinalOrginal(targetObject, field, inject);
                }
                continue;
            }

            ConfigValue configValue = field.getAnnotation(ConfigValue.class);
            if (configValue != null) {
                doInjectConfigValue(targetObject, field, configValue);
                continue;
            }

            RPCInject rpcInject = field.getAnnotation(RPCInject.class);
            if (rpcInject != null) {
                doInjectRPC(targetObject, field, rpcInject);
                continue;
            }
        }
    }


    // 是否对超类进行注入
    if (injectSuperClass) {
        Class<?> c = targetClass.getSuperclass();
        if (c != JbootController.class
                && c != Controller.class
                && c != JbootServiceBase.class
                && c != Object.class
                && c != JbootModel.class
                && c != Model.class
                && c != null
        ) {
            doInject(c, targetObject);
        }
    }
}