org.springframework.beans.factory.support.ChildBeanDefinition Java Examples
The following examples show how to use
org.springframework.beans.factory.support.ChildBeanDefinition.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultListableBeanFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@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")); }
Example #2
Source File: DefaultListableBeanFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@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")); }
Example #3
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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")); }
Example #4
Source File: ConfigurationClassPostProcessorTests.java From spring-analysis-note with MIT License | 5 votes |
/** * 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); }
Example #5
Source File: DefaultListableBeanFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@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")); }
Example #6
Source File: DefaultListableBeanFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@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()); }
Example #7
Source File: ConfigurationClassPostProcessorTests.java From java-technology-stack with MIT License | 5 votes |
/** * 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); }
Example #8
Source File: DefaultListableBeanFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@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")); }
Example #9
Source File: DefaultListableBeanFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@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()); }
Example #10
Source File: ConfigurationClassPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * 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); }
Example #11
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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")); }
Example #12
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testScopeInheritanceForChildBeanDefinitions() throws Exception { 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()); }
Example #13
Source File: SimpleContentStoresBeanDefinitionEmitter.java From alfresco-simple-content-stores with Apache License 2.0 | 5 votes |
protected void emitCustomStoreBeanDefinition(final BeanDefinitionRegistry registry, final String storeName) { if (registry.containsBeanDefinition(storeName)) { throw new AlfrescoRuntimeException( storeName + " (custom content store) cannot be defined - a bean with same name already exists"); } final MessageFormat mf = new MessageFormat("{0}.{1}.", Locale.ENGLISH); final String prefix = mf.format(new Object[] { PROP_CUSTOM_STORE_PREFIX, storeName }); final String typeProperty = prefix + "type"; final String typeValue = this.propertiesSource.getProperty(typeProperty); if (typeValue != null && !typeValue.isEmpty()) { LOGGER.debug("Emitting bean definition for custom store {} based on template {}", storeName, typeValue); final BeanDefinition storeBeanDefinition = new ChildBeanDefinition(STORE_TEMPLATE_PREFIX + typeValue); storeBeanDefinition.setScope(BeanDefinition.SCOPE_SINGLETON); final Set<String> propertyNames = this.propertiesSource.stringPropertyNames(); for (final String propertyName : propertyNames) { if (propertyName.startsWith(prefix) && !typeProperty.equals(propertyName)) { this.handleBeanProperty(storeBeanDefinition, propertyName, this.propertiesSource.getProperty(propertyName)); } } registry.registerBeanDefinition(storeName, storeBeanDefinition); } else { LOGGER.warn("Custom store {} does not define a type", storeName); throw new AlfrescoRuntimeException(storeName + " (custom content store) has not been given a type"); } }
Example #14
Source File: DataDictionary.java From rice with Educational Community License v2.0 | 5 votes |
protected void generateMissingLookupDefinitions() { Collection<LookupView> lookupViewBeans = ddBeans.getBeansOfType(LookupView.class).values(); // Index all the inquiry views by the data object class so we can find them easily below Map<Class<?>,LookupView> defaultViewsByDataObjectClass = new HashMap<Class<?>, LookupView>(); for ( LookupView view : lookupViewBeans ) { if ( view.getViewName().equals(UifConstants.DEFAULT_VIEW_NAME) ) { defaultViewsByDataObjectClass.put(view.getDataObjectClass(), view); } } for (DataObjectEntry entry : ddBeans.getBeansOfType(DataObjectEntry.class).values()) { // if an inquiry already exists, just ignore - we only default if none exist if ( defaultViewsByDataObjectClass.containsKey(entry.getDataObjectClass())) { continue; } // We only generate the inquiry if the metadata says to if ( entry.getDataObjectMetadata() == null ) { continue; } if ( !entry.getDataObjectMetadata().shouldAutoCreateUifViewOfType(UifAutoCreateViewType.LOOKUP)) { continue; } // no inquiry exists and we want one to, create one if ( LOG.isInfoEnabled() ) { LOG.info( "Generating Lookup View for : " + entry.getDataObjectClass() ); } String lookupBeanName = entry.getDataObjectClass().getSimpleName()+"-LookupView-default"; LookupView lookupView = KRADServiceLocatorWeb.getUifDefaultingService().deriveLookupViewFromMetadata(entry); lookupView.setId(lookupBeanName); lookupView.setViewName(UifConstants.DEFAULT_VIEW_NAME); ChildBeanDefinition lookupBean = new ChildBeanDefinition(ComponentFactory.LOOKUP_VIEW); lookupBean.setScope(BeanDefinition.SCOPE_SINGLETON); lookupBean.setAttribute("dataObjectClassName", lookupView.getDataObjectClass()); lookupBean.getPropertyValues().add("dataObjectClassName", lookupView.getDataObjectClass().getName()); lookupBean.setResourceDescription("Autogenerated From Metadata"); ddBeans.registerBeanDefinition(lookupBeanName, lookupBean); ddBeans.registerSingleton(lookupBeanName, lookupView); } }
Example #15
Source File: DataDictionary.java From rice with Educational Community License v2.0 | 4 votes |
protected void generateMissingInquiryDefinitions() { Collection<InquiryView> inquiryViewBeans = ddBeans.getBeansOfType(InquiryView.class).values(); // Index all the inquiry views by the data object class so we can find them easily below Map<Class<?>,InquiryView> defaultViewsByDataObjectClass = new HashMap<Class<?>, InquiryView>(); for ( InquiryView view : inquiryViewBeans ) { if ( view.getViewName().equals(UifConstants.DEFAULT_VIEW_NAME) ) { defaultViewsByDataObjectClass.put(view.getDataObjectClassName(), view); } } for (DataObjectEntry entry : ddBeans.getBeansOfType(DataObjectEntry.class).values()) { // if an inquiry already exists, just ignore - we only default if none exist if ( defaultViewsByDataObjectClass.containsKey(entry.getDataObjectClass())) { continue; } // We only generate the inquiry if the metadata says to if ( entry.getDataObjectMetadata() == null ) { continue; } if ( !entry.getDataObjectMetadata().shouldAutoCreateUifViewOfType(UifAutoCreateViewType.INQUIRY)) { continue; } // no inquiry exists and we want one to, create one if ( LOG.isInfoEnabled() ) { LOG.info( "Generating Inquiry View for : " + entry.getDataObjectClass() ); } String inquiryBeanName = entry.getDataObjectClass().getSimpleName()+"-InquiryView-default"; InquiryView inquiryView = KRADServiceLocatorWeb.getUifDefaultingService().deriveInquiryViewFromMetadata(entry); inquiryView.setId(inquiryBeanName); inquiryView.setViewName(UifConstants.DEFAULT_VIEW_NAME); ChildBeanDefinition inquiryBean = new ChildBeanDefinition("Uif-InquiryView"); inquiryBean.setScope(BeanDefinition.SCOPE_SINGLETON); inquiryBean.setAttribute("dataObjectClassName", inquiryView.getDataObjectClassName()); inquiryBean.getPropertyValues().add("dataObjectClassName", inquiryView.getDataObjectClassName().getName()); inquiryBean.setResourceDescription("Autogenerated From Metadata"); ddBeans.registerBeanDefinition(inquiryBeanName, inquiryBean); ddBeans.registerSingleton(inquiryBeanName, inquiryView); } }