protected BeanDefinitionBase findTypedProxy(BeanDefinitionBase bd) { Set<BeanDefinitionBase> pds = bpds.beanTypeDefinitions.get(bd.getType()); if(null != pds) { for(BeanDefinitionBase pd : pds) { if(isTypedProxy(pd)) { return pd; } } } return null; }
protected BeanDefinitionBase removeAll(BeanDefinitionBase bd) { if(null != bd) { allBeanDefinitions.remove(bd); if(!Strings.isEmpty(bd.getId())) { identifiedBeanDefinitions.remove(bd.getId()); } if(bd.isPrimary()) { primaryBeanDefinitions.remove(bd.getType()); } if(!Strings.isEmpty(bd.getName())) { namedBeanDefinitions.remove(bd.getType(), bd.getName()); } Set<BeanDefinitionBase> set = beanTypeDefinitions.get(bd.getType()); if(null != set) { Set<BeanDefinitionBase> found = new HashSet<>(); Set<BeanDefinitionBase> notFound = new LinkedHashSet<>(); for (BeanDefinitionBase item : set) { if (item == bd) { found.add(item); } else { notFound.add(item); } } set.clear(); set.addAll(notFound); } } return bd; }
protected BeanDefinitionBase findProxy(BeanDefinitionBase bd) { BeanDefinitionBase pd; //find by id. if(!Strings.isEmpty(bd.getId())) { pd = bpds.identifiedBeanDefinitions.get(bd.getId()); if(null != pd) { return pd; } } //find by name. if(!Strings.isEmpty(bd.getName())) { pd = bpds.find(bd.getType(), bd.getName()); if(null != pd) { return pd; } } //find by primary. if(bd.isPrimary()) { pd = bpds.primaryBeanDefinitions.get(bd.getType()); if(null != pd) { return pd; } } //find typed proxy. return findTypedProxy(bd); }
protected Object doCreateBean(BeanDefinitionBase bd){ Object bean = doCreateBeanOnly(bd); BeanDefinitionBase pd = findProxy(bd); if(null != pd) { Object proxyBean = doCreateProxy(pd, bd.getType(), bean); if(!isTypedProxy(pd)) { pd = findTypedProxy(bd); if(null != pd) { Object typedProxyBean = doCreateProxy(pd, bd.getType(), proxyBean); proxyBean = typedProxyBean; } } if(bd.isSingleton()) { bd.setProxyInstance(proxyBean); } return proxyBean; } return bean; }
if(null == bd.getType()) { bd.setType(bd.getBeanClass());
if (null == ReflectClass.of(bean.getBeanClass()).getConstructor(bean.getType())) { throw new BeanDefinitionException("Bean proxy class'" + bean.getBeanClass() + "' must be sub-class of '" + ProxyBean.class + "' or has a constructor with the parameter type '" + bean.getType() + "' , source : " + reader.getSource());