use of com.blade.ioc.bean.BeanDefine in project blade by biezhi.
the class SimpleIoc method setBean.
/**
* Update BeanDefine
*/
@Override
public void setBean(Class<?> type, Object proxyBean) {
BeanDefine beanDefine = pool.get(type.getName());
if (beanDefine != null) {
beanDefine.setBean(proxyBean);
} else {
beanDefine = new BeanDefine(proxyBean, type);
}
pool.put(type.getName(), beanDefine);
}
use of com.blade.ioc.bean.BeanDefine in project blade by biezhi.
the class SimpleIoc method addBean.
/**
* Add user-defined objects
*/
@Override
public void addBean(String name, Object bean) {
BeanDefine beanDefine = new BeanDefine(bean);
put(name, beanDefine);
// add interfacećput to pool
Class<?>[] interfaces = beanDefine.getType().getInterfaces();
if (interfaces.length > 0) {
for (Class<?> interfaceClazz : interfaces) {
this.put(interfaceClazz.getName(), beanDefine);
}
}
}
use of com.blade.ioc.bean.BeanDefine in project blade by biezhi.
the class BeanDefineTest method testBeanDefine.
@Test
public void testBeanDefine() {
BeanDefine beanDefine = new BeanDefine(new BladeBeanDefineType());
Class<?> type = beanDefine.getType();
assertEquals(BladeBeanDefineType.class, type);
Object bean = beanDefine.getBean();
assertNotNull(bean);
assertEquals(true, beanDefine.isSingleton());
beanDefine.setSingleton(true);
beanDefine.setType(BladeBeanDefineType.class);
beanDefine.setBean(new BladeBeanDefineType());
assertEquals(BladeBeanDefineType.class, type);
assertNotNull(bean);
assertEquals(true, beanDefine.isSingleton());
}
Aggregations