/** * Invokes single method injection point on given bean with given bean definition. */ protected void wireMethods() { for (final MethodInjectionPoint methodRef : definition().methods) { invokeMethodInjectionPoint(methodRef); } }
/** * Returns <code>true</code> if bean is destroyable. */ protected boolean isBeanDestroyable(final BeanData beanData) { DestroyMethodPoint[] dmp = beanData.definition().destroyMethodPoints(); return dmp != null && dmp.length != 0; }
/** * Wires beans. */ public void wireBean() { if (definition().wiringMode == WiringMode.NONE) { return; } wireProperties(); wireSets(); wireMethods(); }
protected void wireSets() { for (final SetInjectionPoint sip : definition().sets) { String[] beanNames = pc.resolveBeanNamesForType(sip.targetClass); Collection beans = sip.createSet(beanNames.length); for (String beanName : beanNames) { if (!beanName.equals(definition().name)) { Object value = pc.getBean(beanName); beans.add(value); } } //BeanUtil.setDeclaredProperty(bean, sip.field.getName(), beans); final Setter setter = sip.propertyDescriptor.getSetter(true); try { setter.invokeSetter(bean, beans); } catch (Exception ex) { throw new PetiteException("Wiring failed", ex); } } }
protected void wireProperties() { for (PropertyInjectionPoint pip : beanDefinition.properties) { final BeanReferences refNames = pip.references; final Object value = pc.lookupMixingScopedBean(this.definition(), refNames); if (value == null) { if ((beanDefinition.wiringMode == WiringMode.STRICT)) { throw new PetiteException("Wiring failed. Beans references: '" + refNames + "' not found for property: " + beanDefinition.type.getName() + '#' + pip.propertyDescriptor.getName()); } continue; } // BeanUtil.setDeclaredProperty(bean, pip.propertyDescriptor.getName(), value); final Setter setter = pip.propertyDescriptor.getSetter(true); try { setter.invokeSetter(bean, value); } catch (Exception ex) { throw new PetiteException("Wiring failed", ex); } } }
/** * Wires bean, injects parameters and invokes init methods. * Such a loooong name :) */ protected void registerBeanAndWireAndInjectParamsAndInvokeInitMethods(final BeanData beanData) { initBeanDefinition(beanData.definition()); beanData.scopeRegister(); beanData.invokeInitMethods(InitMethodInvocationStrategy.POST_CONSTRUCT); beanData.wireBean(); beanData.invokeInitMethods(InitMethodInvocationStrategy.POST_DEFINE); beanData.injectParams(paramManager, petiteConfig.isImplicitParamInjection()); beanData.invokeInitMethods(InitMethodInvocationStrategy.POST_INITIALIZE); beanData.invokeConsumerIfRegistered(); }
/** * Returns <code>true</code> if bean is destroyable. */ protected boolean isBeanDestroyable(final BeanData beanData) { DestroyMethodPoint[] dmp = beanData.definition().destroyMethodPoints(); return dmp != null && dmp.length != 0; }
/** * Invokes single method injection point on given bean with given bean definition. */ protected void wireMethods() { for (final MethodInjectionPoint methodRef : definition().methods) { invokeMethodInjectionPoint(methodRef); } }
/** * Wires beans. */ public void wireBean() { if (definition().wiringMode == WiringMode.NONE) { return; } wireProperties(); wireSets(); wireMethods(); }
protected void wireSets() { for (final SetInjectionPoint sip : definition().sets) { String[] beanNames = pc.resolveBeanNamesForType(sip.targetClass); Collection beans = sip.createSet(beanNames.length); for (String beanName : beanNames) { if (!beanName.equals(definition().name)) { Object value = pc.getBean(beanName); beans.add(value); } } //BeanUtil.setDeclaredProperty(bean, sip.field.getName(), beans); final Setter setter = sip.propertyDescriptor.getSetter(true); try { setter.invokeSetter(bean, beans); } catch (Exception ex) { throw new PetiteException("Wiring failed", ex); } } }
protected void wireProperties() { for (PropertyInjectionPoint pip : beanDefinition.properties) { final BeanReferences refNames = pip.references; final Object value = pc.lookupMixingScopedBean(this.definition(), refNames); if (value == null) { if ((beanDefinition.wiringMode == WiringMode.STRICT)) { throw new PetiteException("Wiring failed. Beans references: '" + refNames + "' not found for property: " + beanDefinition.type.getName() + '#' + pip.propertyDescriptor.getName()); } continue; } // BeanUtil.setDeclaredProperty(bean, pip.propertyDescriptor.getName(), value); final Setter setter = pip.propertyDescriptor.getSetter(true); try { setter.invokeSetter(bean, value); } catch (Exception ex) { throw new PetiteException("Wiring failed", ex); } } }
/** * Wires bean, injects parameters and invokes init methods. * Such a loooong name :) */ protected void registerBeanAndWireAndInjectParamsAndInvokeInitMethods(final BeanData beanData) { initBeanDefinition(beanData.definition()); beanData.scopeRegister(); beanData.invokeInitMethods(InitMethodInvocationStrategy.POST_CONSTRUCT); beanData.wireBean(); beanData.invokeInitMethods(InitMethodInvocationStrategy.POST_DEFINE); beanData.injectParams(paramManager, petiteConfig.isImplicitParamInjection()); beanData.invokeInitMethods(InitMethodInvocationStrategy.POST_INITIALIZE); beanData.invokeConsumerIfRegistered(); }