@Override public AbstractBeanDefinition cloneBeanDefinition() { return new ChildBeanDefinition(this); }
/** * Create a new {@code BeanDefinitionBuilder} used to construct a {@link ChildBeanDefinition}. * @param parentName the name of the parent bean */ public static BeanDefinitionBuilder childBeanDefinition(String parentName) { return new BeanDefinitionBuilder(new ChildBeanDefinition(parentName)); }
@Override public AbstractBeanDefinition cloneBeanDefinition() { return new ChildBeanDefinition(this); }
/** * Create a new {@code BeanDefinitionBuilder} used to construct a {@link ChildBeanDefinition}. * @param parentName the name of the parent bean */ public static BeanDefinitionBuilder childBeanDefinition(String parentName) { return new BeanDefinitionBuilder(new ChildBeanDefinition(parentName)); }
protected AbstractBeanDefinition createBeanDefinition() { AbstractBeanDefinition bd; if(constructorArgs.size() > 0) { ConstructorArgumentValues cav = new ConstructorArgumentValues(); for (Object constructorArg : constructorArgs) { cav.addGenericArgumentValue(constructorArg); } if(StringUtils.isBlank(parentName)) { bd = new RootBeanDefinition(clazz,cav,null); } else { bd = new ChildBeanDefinition(parentName,clazz,cav, null); } bd.setSingleton(singleton); } else { if(StringUtils.isBlank(parentName)) { bd = new RootBeanDefinition(clazz,singleton); } else { bd = new ChildBeanDefinition(parentName,clazz, null,null); bd.setSingleton(singleton); } } wrapper = new BeanWrapperImpl(bd); return bd; }
@Test public void childBeanDefinition() { ChildBeanDefinition master = new ChildBeanDefinition("foo"); ChildBeanDefinition equal = new ChildBeanDefinition("foo"); ChildBeanDefinition notEqual = new ChildBeanDefinition("bar"); ChildBeanDefinition subclass = new ChildBeanDefinition("foo") { }; setBaseProperties(master); setBaseProperties(equal); setBaseProperties(notEqual); setBaseProperties(subclass); assertEqualsAndHashCodeContracts(master, equal, notEqual, subclass); }
/** * Tests whether a bean definition without a specified bean class is handled * correctly. */ @Test public void postProcessorIntrospectsInheritedDefinitionsCorrectly() { beanFactory.registerBeanDefinition("config", new RootBeanDefinition(SingletonBeanConfig.class)); beanFactory.registerBeanDefinition("parent", new RootBeanDefinition(TestBean.class)); beanFactory.registerBeanDefinition("child", new ChildBeanDefinition("parent")); ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor(); pp.postProcessBeanFactory(beanFactory); Foo foo = beanFactory.getBean("foo", Foo.class); Bar bar = beanFactory.getBean("bar", Bar.class); assertSame(foo, bar.foo); }
@Test public void testGetTypeWorksAfterParentChildMerging() { RootBeanDefinition parentDefinition = new RootBeanDefinition(TestBean.class); ChildBeanDefinition childDefinition = new ChildBeanDefinition("parent", DerivedTestBean.class, null, null); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.registerBeanDefinition("parent", parentDefinition); factory.registerBeanDefinition("child", childDefinition); factory.freezeConfiguration(); assertEquals(TestBean.class, factory.getType("parent")); assertEquals(DerivedTestBean.class, factory.getType("child")); }
@Test public void testScopeInheritanceForChildBeanDefinitions() { RootBeanDefinition parent = new RootBeanDefinition(); parent.setScope("bonanza!"); AbstractBeanDefinition child = new ChildBeanDefinition("parent"); child.setBeanClass(TestBean.class); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.registerBeanDefinition("parent", parent); factory.registerBeanDefinition("child", child); BeanDefinition def = factory.getMergedBeanDefinition("child"); assertEquals("Child 'scope' not inherited", "bonanza!", def.getScope()); }
@Override public AbstractBeanDefinition cloneBeanDefinition() { return new ChildBeanDefinition(this); }
RootBeanDefinition parent = new RootBeanDefinition(TestBean.class); parent.setPropertyValues(pvs1); ChildBeanDefinition bd = new ChildBeanDefinition("${parent}", pvs2); factory.registerBeanDefinition("parent1", parent); factory.registerBeanDefinition("tb1", bd); someMap.put("key3", innerBd); MutablePropertyValues innerPvs2 = new MutablePropertyValues(innerPvs); someMap.put("${key4}", new BeanDefinitionHolder(new ChildBeanDefinition("tb1", innerPvs2), "child")); pvs.add("someMap", someMap);
@Test public void testCanReferenceParentBeanFromChildViaAlias() { final String EXPECTED_NAME = "Juergen"; final int EXPECTED_AGE = 41; RootBeanDefinition parentDefinition = new RootBeanDefinition(TestBean.class); parentDefinition.setAbstract(true); parentDefinition.getPropertyValues().add("name", EXPECTED_NAME); parentDefinition.getPropertyValues().add("age", EXPECTED_AGE); ChildBeanDefinition childDefinition = new ChildBeanDefinition("alias"); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.registerBeanDefinition("parent", parentDefinition); factory.registerBeanDefinition("child", childDefinition); factory.registerAlias("parent", "alias"); TestBean child = (TestBean) factory.getBean("child"); assertEquals(EXPECTED_NAME, child.getName()); assertEquals(EXPECTED_AGE, child.getAge()); assertEquals("Use cached merged bean definition", factory.getMergedBeanDefinition("child"), factory.getMergedBeanDefinition("child")); }
/** * Create a new <code>BeanDefinitionBuilder</code> used to construct a {@link ChildBeanDefinition}. * @param parentName the name of the parent bean */ public static BeanDefinitionBuilder childBeanDefinition(String parentName) { BeanDefinitionBuilder builder = new BeanDefinitionBuilder(); builder.beanDefinition = new ChildBeanDefinition(parentName); return builder; }
@Test public void testBeanNameWithParentBeanDefinition() throws Exception { GenericApplicationContext context = new GenericApplicationContext(); ConstructorArgumentValues args = new ConstructorArgumentValues(); args.addGenericArgumentValue("bar"); context.registerBeanDefinition("parent", new RootBeanDefinition( JobSupport.class, args, null)); context.registerBeanDefinition("bean", new ChildBeanDefinition("parent")); context.refresh(); JobSupport configuration = (JobSupport) context .getBean("bean"); assertNotNull(configuration.getName()); assertEquals("bar", configuration.getName()); configuration.setBeanName("foo"); assertEquals("bar", configuration.getName()); configuration.setName("foo"); assertEquals("foo", configuration.getName()); context.close(); } }
@Override public AbstractBeanDefinition cloneBeanDefinition() { return new ChildBeanDefinition(this); }
/** * Create a new {@code BeanDefinitionBuilder} used to construct a {@link ChildBeanDefinition}. * @param parentName the name of the parent bean */ public static BeanDefinitionBuilder childBeanDefinition(String parentName) { BeanDefinitionBuilder builder = new BeanDefinitionBuilder(); builder.beanDefinition = new ChildBeanDefinition(parentName); return builder; }
protected AbstractBeanDefinition createBeanDefinition() { AbstractBeanDefinition bd; if(constructorArgs.size() > 0) { ConstructorArgumentValues cav = new ConstructorArgumentValues(); for (Object constructorArg : constructorArgs) { cav.addGenericArgumentValue(constructorArg); } if(StringUtils.isBlank(parentName)) { bd = new RootBeanDefinition(clazz,cav,null); } else { bd = new ChildBeanDefinition(parentName,clazz,cav, null); } bd.setSingleton(singleton); } else { if(StringUtils.isBlank(parentName)) { bd = new RootBeanDefinition(clazz,singleton); } else { bd = new ChildBeanDefinition(parentName,clazz, null,null); bd.setSingleton(singleton); } } wrapper = new BeanWrapperImpl(bd); return bd; }
protected AbstractBeanDefinition createBeanDefinition() { AbstractBeanDefinition bd; if(constructorArgs.size() > 0) { ConstructorArgumentValues cav = new ConstructorArgumentValues(); for (Object constructorArg : constructorArgs) { cav.addGenericArgumentValue(constructorArg); } if(StringUtils.isBlank(parentName)) { bd = new RootBeanDefinition(clazz,cav,null); } else { bd = new ChildBeanDefinition(parentName,clazz,cav, null); } bd.setSingleton(singleton); } else { if(StringUtils.isBlank(parentName)) { bd = new RootBeanDefinition(clazz,singleton); } else { bd = new ChildBeanDefinition(parentName,clazz, null,null); bd.setSingleton(singleton); } } wrapper = new BeanWrapperImpl(bd); return bd; }
protected AbstractBeanDefinition createBeanDefinition() { AbstractBeanDefinition bd; if(constructorArgs.size() > 0) { ConstructorArgumentValues cav = new ConstructorArgumentValues(); for (Object constructorArg : constructorArgs) { cav.addGenericArgumentValue(constructorArg); } if(StringUtils.isBlank(parentName)) { bd = new RootBeanDefinition(clazz,cav,null); } else { bd = new ChildBeanDefinition(parentName,clazz,cav, null); } bd.setSingleton(singleton); } else { if(StringUtils.isBlank(parentName)) { bd = new RootBeanDefinition(clazz,singleton); } else { bd = new ChildBeanDefinition(parentName,clazz, null,null); bd.setSingleton(singleton); } } wrapper = new BeanWrapperImpl(bd); return bd; }
/** * @see org.apache.cocoon.core.container.spring.avalon.BridgeElementParser#createComponents(org.w3c.dom.Element, org.apache.cocoon.core.container.spring.avalon.ConfigurationInfo, org.springframework.beans.factory.support.BeanDefinitionRegistry, org.springframework.beans.factory.support.BeanDefinitionReader, org.springframework.core.io.ResourceLoader) */ public void createComponents(Element element, ConfigurationInfo info, BeanDefinitionRegistry registry, BeanDefinitionReader reader, ResourceLoader resourceLoader) throws Exception { super.createComponents(element, info, registry, reader, resourceLoader); // add string template parser for sitemap variable substitution final ChildBeanDefinition beanDef = new ChildBeanDefinition("org.apache.cocoon.template.expression.AbstractStringTemplateParser"); beanDef.setBeanClassName("org.apache.cocoon.components.treeprocessor.variables.LegacySitemapStringTemplateParser"); beanDef.setSingleton(true); beanDef.setLazyInit(false); beanDef.getPropertyValues().addPropertyValue("serviceManager", new RuntimeBeanReference("org.apache.avalon.framework.service.ServiceManager")); this.register(beanDef, "org.apache.cocoon.el.parsing.StringTemplateParser/legacySitemap", null, registry); final RootBeanDefinition resolverDef = new RootBeanDefinition(); resolverDef.setBeanClassName("org.apache.cocoon.components.treeprocessor.variables.StringTemplateParserVariableResolver"); resolverDef.setLazyInit(false); resolverDef.setScope("prototype"); resolverDef.getPropertyValues().addPropertyValue("stringTemplateParser", new RuntimeBeanReference("org.apache.cocoon.el.parsing.StringTemplateParser/legacySitemap")); resolverDef.getPropertyValues().addPropertyValue("objectModel", new RuntimeBeanReference("org.apache.cocoon.el.objectmodel.ObjectModel")); this.register(resolverDef, "org.apache.cocoon.components.treeprocessor.variables.VariableResolver", null, registry); }