Search in sources :

Example 1 with ClassDefine

use of com.blade.ioc.bean.ClassDefine in project blade by biezhi.

the class IocKit method initInjection.

public static void initInjection(Ioc ioc, BeanDefine beanDefine) {
    ClassDefine classDefine = ClassDefine.create(beanDefine.getType());
    List<FieldInjector> fieldInjectors = getInjectFields(ioc, classDefine);
    Object bean = beanDefine.getBean();
    AtomicBoolean hasPrototypeField = new AtomicBoolean(false);
    fieldInjectors.forEach(fieldInjector -> {
        if (fieldInjector.isSingleton()) {
            fieldInjector.injection(bean);
        } else {
            hasPrototypeField.set(true);
        }
    });
    beanDefine.setFieldHasPrototype(hasPrototypeField.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClassDefine(com.blade.ioc.bean.ClassDefine) FieldInjector(com.blade.ioc.bean.FieldInjector)

Example 2 with ClassDefine

use of com.blade.ioc.bean.ClassDefine in project blade by biezhi.

the class IocKit method injectionValue.

public static void injectionValue(Environment environment, BeanDefine beanDefine) {
    ClassDefine classDefine = ClassDefine.create(beanDefine.getType());
    List<ValueInjector> valueFields = getValueInjectFields(environment, classDefine);
    Object bean = beanDefine.getBean();
    valueFields.forEach(fieldInjector -> fieldInjector.injection(bean));
}
Also used : ClassDefine(com.blade.ioc.bean.ClassDefine) ValueInjector(com.blade.ioc.bean.ValueInjector)

Example 3 with ClassDefine

use of com.blade.ioc.bean.ClassDefine in project blade by biezhi.

the class ClassDefineTest method testClassDefine.

@Test
public void testClassDefine() {
    ClassDefine classDefine = ClassDefine.create(BladeClassDefineType.class);
    int modifires = classDefine.getModifiers();
    Field[] fields = classDefine.getDeclaredFields();
    Bean bean = classDefine.getAnnotation(Bean.class);
    Annotation[] annotations = classDefine.getAnnotations();
    List<ClassDefine> interfaces = classDefine.getInterfaces();
    String name = classDefine.getName();
    String simpleName = classDefine.getSimpleName();
    ClassDefine superKlass = classDefine.getSuperKlass();
    Class<?> type = classDefine.getType();
    assertEquals(Modifier.PUBLIC, modifires);
    assertEquals(2, fields.length);
    assertNotNull(bean);
    assertEquals(1, annotations.length);
    assertEquals(0, interfaces.size());
    assertEquals("com.blade.types.BladeClassDefineType", name);
    assertEquals("BladeClassDefineType", simpleName);
    assertEquals(Object.class, superKlass.getType());
    assertEquals(BladeClassDefineType.class, type);
    assertEquals(false, classDefine.isAbstract());
    assertEquals(false, classDefine.isInterface());
    assertEquals(false, classDefine.isStatic());
    assertEquals(true, classDefine.isPublic());
    assertEquals(false, classDefine.isPrivate());
    assertEquals(false, classDefine.isProtected());
    assertEquals(1, ClassDefine.create(BladeWebHookType.class).getInterfaces().size());
    assertEquals(1, ClassDefine.create(BladeWebHookType.class).getInterfaces().size());
}
Also used : Field(java.lang.reflect.Field) ClassDefine(com.blade.ioc.bean.ClassDefine) BladeWebHookType(com.blade.types.BladeWebHookType) Annotation(java.lang.annotation.Annotation) Bean(com.blade.ioc.annotation.Bean) Test(org.junit.Test)

Example 4 with ClassDefine

use of com.blade.ioc.bean.ClassDefine in project blade by biezhi.

the class IocKit method injection.

public static void injection(Ioc ioc, BeanDefine beanDefine) {
    ClassDefine classDefine = ClassDefine.create(beanDefine.getType());
    List<FieldInjector> fieldInjectors = getInjectFields(ioc, classDefine);
    Object bean = beanDefine.getBean();
    fieldInjectors.forEach(fieldInjector -> {
        Object fieldInstance = ReflectKit.newInstance(fieldInjector.getType());
        if (fieldInjector.hasInjectFields()) {
            injection(ioc, new BeanDefine(fieldInstance));
        }
        fieldInjector.injection(bean, fieldInstance);
    });
}
Also used : ClassDefine(com.blade.ioc.bean.ClassDefine) FieldInjector(com.blade.ioc.bean.FieldInjector) BeanDefine(com.blade.ioc.bean.BeanDefine)

Aggregations

ClassDefine (com.blade.ioc.bean.ClassDefine)4 FieldInjector (com.blade.ioc.bean.FieldInjector)2 Bean (com.blade.ioc.annotation.Bean)1 BeanDefine (com.blade.ioc.bean.BeanDefine)1 ValueInjector (com.blade.ioc.bean.ValueInjector)1 BladeWebHookType (com.blade.types.BladeWebHookType)1 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.Test)1