Java Code Examples for org.springframework.beans.factory.support.StaticListableBeanFactory

The following examples show how to use org.springframework.beans.factory.support.StaticListableBeanFactory. These examples are extracted from open source projects. 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 Project: localization_nifi   Source File: AbstractEmailProcessor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Builds and initializes the target message receiver if necessary (if it's
 * null). Upon execution of this operation the receiver is fully functional
 * and is ready to receive messages.
 */
private synchronized void initializeIfNecessary(ProcessContext context, ProcessSession processSession) {
    if (this.messageReceiver == null) {
        this.processSession = processSession;
        this.messageReceiver = this.buildMessageReceiver(context);

        this.shouldSetDeleteFlag = context.getProperty(SHOULD_DELETE_MESSAGES).asBoolean();
        int fetchSize = context.getProperty(FETCH_SIZE).evaluateAttributeExpressions().asInteger();

        this.messageReceiver.setMaxFetchSize(fetchSize);
        this.messageReceiver.setJavaMailProperties(this.buildJavaMailProperties(context));
        // need to avoid spring warning messages
        this.messageReceiver.setBeanFactory(new StaticListableBeanFactory());
        this.messageReceiver.afterPropertiesSet();

        this.messageQueue = new ArrayBlockingQueue<>(fetchSize);
    }
}
 
Example 2
@Before
public void initGRL() throws Exception {
    GlobalResourceLoader.stop();
    SimpleConfig config = new SimpleConfig();
    config.putProperty(CoreConstants.Config.APPLICATION_ID, "APPID");
    ConfigContext.init(config);

    StaticListableBeanFactory testBf = new StaticListableBeanFactory();
    when(kualiModuleService.getInstalledModuleServices()).thenReturn(installedModuleServices);

    testBf.addBean(KRADServiceLocator.PROVIDER_REGISTRY, mock(ProviderRegistry.class));
    testBf.addBean(KRADServiceLocatorWeb.KUALI_MODULE_SERVICE, kualiModuleService);

    ResourceLoader rl = new BeanFactoryResourceLoader(new QName("moduleservicebase-unittest"), testBf);
    GlobalResourceLoader.addResourceLoader(rl);
    GlobalResourceLoader.start();
}
 
Example 3
@Before
public void installRiceKualiModuleService() throws Exception {
    GlobalResourceLoader.stop();
    SimpleConfig config = new SimpleConfig();
    config.putProperty(CoreConstants.Config.APPLICATION_ID, "APPID");
    ConfigContext.init(config);

    StaticListableBeanFactory testBf = new StaticListableBeanFactory();

    KualiModuleService riceKualiModuleService = mock(KualiModuleService.class);
    when(riceKualiModuleService.getInstalledModuleServices()).thenReturn(riceModuleServices);

    testBf.addBean(KRADServiceLocatorWeb.KUALI_MODULE_SERVICE, riceKualiModuleService);

    ResourceLoader rl = new BeanFactoryResourceLoader(new QName("moduleservicebase-unittest"), testBf);
    GlobalResourceLoader.addResourceLoader(rl);
    GlobalResourceLoader.start();
}
 
Example 4
Source Project: nifi   Source File: AbstractEmailProcessor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Builds and initializes the target message receiver if necessary (if it's
 * null). Upon execution of this operation the receiver is fully functional
 * and is ready to receive messages.
 */
private synchronized void initializeIfNecessary(ProcessContext context, ProcessSession processSession) {
    if (this.messageReceiver == null) {
        this.processSession = processSession;
        this.messageReceiver = this.buildMessageReceiver(context);

        this.shouldSetDeleteFlag = context.getProperty(SHOULD_DELETE_MESSAGES).asBoolean();
        int fetchSize = context.getProperty(FETCH_SIZE).evaluateAttributeExpressions().asInteger();

        this.messageReceiver.setMaxFetchSize(fetchSize);
        this.messageReceiver.setJavaMailProperties(this.buildJavaMailProperties(context));
        // need to avoid spring warning messages
        this.messageReceiver.setBeanFactory(new StaticListableBeanFactory());
        this.messageReceiver.afterPropertiesSet();

        this.messageQueue = new ArrayBlockingQueue<>(fetchSize);
    }
}
 
Example 5
@Test
public void testBeanAutowiredWithAnnotationConfigEnabled() {
	GenericApplicationContext context = new GenericApplicationContext();
	context.registerBeanDefinition("myBf", new RootBeanDefinition(StaticListableBeanFactory.class));
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	scanner.setBeanNameGenerator(new TestBeanNameGenerator());
	int beanCount = scanner.scan(BASE_PACKAGE);
	assertEquals(12, beanCount);
	context.refresh();

	FooServiceImpl fooService = context.getBean("fooService", FooServiceImpl.class);
	StaticListableBeanFactory myBf = (StaticListableBeanFactory) context.getBean("myBf");
	MessageSource ms = (MessageSource) context.getBean("messageSource");
	assertTrue(fooService.isInitCalled());
	assertEquals("bar", fooService.foo(123));
	assertEquals("bar", fooService.lookupFoo(123));
	assertSame(context.getDefaultListableBeanFactory(), fooService.beanFactory);
	assertEquals(2, fooService.listableBeanFactory.size());
	assertSame(context.getDefaultListableBeanFactory(), fooService.listableBeanFactory.get(0));
	assertSame(myBf, fooService.listableBeanFactory.get(1));
	assertSame(context, fooService.resourceLoader);
	assertSame(context, fooService.resourcePatternResolver);
	assertSame(context, fooService.eventPublisher);
	assertSame(ms, fooService.messageSource);
	assertSame(context, fooService.context);
	assertEquals(1, fooService.configurableContext.length);
	assertSame(context, fooService.configurableContext[0]);
	assertSame(context, fooService.genericContext);
}
 
Example 6
Source Project: spring-analysis-note   Source File: JCacheInterceptorTests.java    License: MIT License 5 votes vote down vote up
protected JCacheOperationSource createOperationSource(CacheManager cacheManager,
		CacheResolver cacheResolver, CacheResolver exceptionCacheResolver, KeyGenerator keyGenerator) {

	DefaultJCacheOperationSource source = new DefaultJCacheOperationSource();
	source.setCacheManager(cacheManager);
	source.setCacheResolver(cacheResolver);
	source.setExceptionCacheResolver(exceptionCacheResolver);
	source.setKeyGenerator(keyGenerator);
	source.setBeanFactory(new StaticListableBeanFactory());
	source.afterSingletonsInstantiated();
	return source;
}
 
Example 7
Source Project: spring-analysis-note   Source File: BeanFactoryUtilsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testHierarchicalCountBeansWithNonHierarchicalFactory() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	lbf.addBean("t1", new TestBean());
	lbf.addBean("t2", new TestBean());
	assertTrue(BeanFactoryUtils.countBeansIncludingAncestors(lbf) == 2);
}
 
Example 8
Source Project: spring-analysis-note   Source File: BeanFactoryUtilsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testNoBeansOfType() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	lbf.addBean("foo", new Object());
	Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false);
	assertTrue(beans.isEmpty());
}
 
Example 9
Source Project: spring-analysis-note   Source File: BeanFactoryUtilsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testFindsBeansOfTypeWithStaticFactory() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	TestBean t1 = new TestBean();
	TestBean t2 = new TestBean();
	DummyFactory t3 = new DummyFactory();
	DummyFactory t4 = new DummyFactory();
	t4.setSingleton(false);
	lbf.addBean("t1", t1);
	lbf.addBean("t2", t2);
	lbf.addBean("t3", t3);
	lbf.addBean("t4", t4);

	Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, true);
	assertEquals(4, beans.size());
	assertEquals(t1, beans.get("t1"));
	assertEquals(t2, beans.get("t2"));
	assertEquals(t3.getObject(), beans.get("t3"));
	assertTrue(beans.get("t4") instanceof TestBean);

	beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DummyFactory.class, true, true);
	assertEquals(2, beans.size());
	assertEquals(t3, beans.get("&t3"));
	assertEquals(t4, beans.get("&t4"));

	beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, FactoryBean.class, true, true);
	assertEquals(2, beans.size());
	assertEquals(t3, beans.get("&t3"));
	assertEquals(t4, beans.get("&t4"));
}
 
Example 10
@Test
public void testBeanAutowiredWithAnnotationConfigEnabled() {
	GenericApplicationContext context = new GenericApplicationContext();
	context.registerBeanDefinition("myBf", new RootBeanDefinition(StaticListableBeanFactory.class));
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	scanner.setBeanNameGenerator(new TestBeanNameGenerator());
	int beanCount = scanner.scan(BASE_PACKAGE);
	assertEquals(12, beanCount);
	context.refresh();

	FooServiceImpl fooService = context.getBean("fooService", FooServiceImpl.class);
	StaticListableBeanFactory myBf = (StaticListableBeanFactory) context.getBean("myBf");
	MessageSource ms = (MessageSource) context.getBean("messageSource");
	assertTrue(fooService.isInitCalled());
	assertEquals("bar", fooService.foo(123));
	assertEquals("bar", fooService.lookupFoo(123));
	assertSame(context.getDefaultListableBeanFactory(), fooService.beanFactory);
	assertEquals(2, fooService.listableBeanFactory.size());
	assertSame(context.getDefaultListableBeanFactory(), fooService.listableBeanFactory.get(0));
	assertSame(myBf, fooService.listableBeanFactory.get(1));
	assertSame(context, fooService.resourceLoader);
	assertSame(context, fooService.resourcePatternResolver);
	assertSame(context, fooService.eventPublisher);
	assertSame(ms, fooService.messageSource);
	assertSame(context, fooService.context);
	assertEquals(1, fooService.configurableContext.length);
	assertSame(context, fooService.configurableContext[0]);
	assertSame(context, fooService.genericContext);
}
 
Example 11
Source Project: java-technology-stack   Source File: JCacheInterceptorTests.java    License: MIT License 5 votes vote down vote up
protected JCacheOperationSource createOperationSource(CacheManager cacheManager,
		CacheResolver cacheResolver, CacheResolver exceptionCacheResolver, KeyGenerator keyGenerator) {

	DefaultJCacheOperationSource source = new DefaultJCacheOperationSource();
	source.setCacheManager(cacheManager);
	source.setCacheResolver(cacheResolver);
	source.setExceptionCacheResolver(exceptionCacheResolver);
	source.setKeyGenerator(keyGenerator);
	source.setBeanFactory(new StaticListableBeanFactory());
	source.afterSingletonsInstantiated();
	return source;
}
 
Example 12
Source Project: java-technology-stack   Source File: BeanFactoryUtilsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testHierarchicalCountBeansWithNonHierarchicalFactory() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	lbf.addBean("t1", new TestBean());
	lbf.addBean("t2", new TestBean());
	assertTrue(BeanFactoryUtils.countBeansIncludingAncestors(lbf) == 2);
}
 
Example 13
Source Project: java-technology-stack   Source File: BeanFactoryUtilsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testNoBeansOfType() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	lbf.addBean("foo", new Object());
	Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false);
	assertTrue(beans.isEmpty());
}
 
Example 14
Source Project: java-technology-stack   Source File: BeanFactoryUtilsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testFindsBeansOfTypeWithStaticFactory() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	TestBean t1 = new TestBean();
	TestBean t2 = new TestBean();
	DummyFactory t3 = new DummyFactory();
	DummyFactory t4 = new DummyFactory();
	t4.setSingleton(false);
	lbf.addBean("t1", t1);
	lbf.addBean("t2", t2);
	lbf.addBean("t3", t3);
	lbf.addBean("t4", t4);

	Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, true);
	assertEquals(4, beans.size());
	assertEquals(t1, beans.get("t1"));
	assertEquals(t2, beans.get("t2"));
	assertEquals(t3.getObject(), beans.get("t3"));
	assertTrue(beans.get("t4") instanceof TestBean);

	beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DummyFactory.class, true, true);
	assertEquals(2, beans.size());
	assertEquals(t3, beans.get("&t3"));
	assertEquals(t4, beans.get("&t4"));

	beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, FactoryBean.class, true, true);
	assertEquals(2, beans.size());
	assertEquals(t3, beans.get("&t3"));
	assertEquals(t4, beans.get("&t4"));
}
 
Example 15
@Test
public void testBeanAutowiredWithAnnotationConfigEnabled() {
	GenericApplicationContext context = new GenericApplicationContext();
	context.registerBeanDefinition("myBf", new RootBeanDefinition(StaticListableBeanFactory.class));
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	scanner.setBeanNameGenerator(new TestBeanNameGenerator());
	int beanCount = scanner.scan(BASE_PACKAGE);
	assertEquals(12, beanCount);
	context.refresh();

	FooServiceImpl fooService = context.getBean("fooService", FooServiceImpl.class);
	StaticListableBeanFactory myBf = (StaticListableBeanFactory) context.getBean("myBf");
	MessageSource ms = (MessageSource) context.getBean("messageSource");
	assertTrue(fooService.isInitCalled());
	assertEquals("bar", fooService.foo(123));
	assertSame(context.getDefaultListableBeanFactory(), fooService.beanFactory);
	assertEquals(2, fooService.listableBeanFactory.size());
	assertSame(context.getDefaultListableBeanFactory(), fooService.listableBeanFactory.get(0));
	assertSame(myBf, fooService.listableBeanFactory.get(1));
	assertSame(context, fooService.resourceLoader);
	assertSame(context, fooService.resourcePatternResolver);
	assertSame(context, fooService.eventPublisher);
	assertSame(ms, fooService.messageSource);
	assertSame(context, fooService.context);
	assertEquals(1, fooService.configurableContext.length);
	assertSame(context, fooService.configurableContext[0]);
	assertSame(context, fooService.genericContext);
}
 
Example 16
protected JCacheOperationSource createOperationSource(CacheManager cacheManager,
		CacheResolver cacheResolver, CacheResolver exceptionCacheResolver, KeyGenerator keyGenerator) {

	DefaultJCacheOperationSource source = new DefaultJCacheOperationSource();
	source.setCacheManager(cacheManager);
	source.setCacheResolver(cacheResolver);
	source.setExceptionCacheResolver(exceptionCacheResolver);
	source.setKeyGenerator(keyGenerator);
	source.setBeanFactory(new StaticListableBeanFactory());
	source.afterPropertiesSet();
	source.afterSingletonsInstantiated();
	return source;
}
 
Example 17
@Test
public void testHierarchicalCountBeansWithNonHierarchicalFactory() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	lbf.addBean("t1", new TestBean());
	lbf.addBean("t2", new TestBean());
	assertTrue(BeanFactoryUtils.countBeansIncludingAncestors(lbf) == 2);
}
 
Example 18
@Test
public void testNoBeansOfType() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	lbf.addBean("foo", new Object());
	Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false);
	assertTrue(beans.isEmpty());
}
 
Example 19
@Test
public void testFindsBeansOfTypeWithStaticFactory() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	TestBean t1 = new TestBean();
	TestBean t2 = new TestBean();
	DummyFactory t3 = new DummyFactory();
	DummyFactory t4 = new DummyFactory();
	t4.setSingleton(false);
	lbf.addBean("t1", t1);
	lbf.addBean("t2", t2);
	lbf.addBean("t3", t3);
	lbf.addBean("t4", t4);

	Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, true);
	assertEquals(4, beans.size());
	assertEquals(t1, beans.get("t1"));
	assertEquals(t2, beans.get("t2"));
	assertEquals(t3.getObject(), beans.get("t3"));
	assertTrue(beans.get("t4") instanceof TestBean);

	beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DummyFactory.class, true, true);
	assertEquals(2, beans.size());
	assertEquals(t3, beans.get("&t3"));
	assertEquals(t4, beans.get("&t4"));

	beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, FactoryBean.class, true, true);
	assertEquals(2, beans.size());
	assertEquals(t3, beans.get("&t3"));
	assertEquals(t4, beans.get("&t4"));
}
 
Example 20
@Before
public void initGRL() throws Exception {
    GlobalResourceLoader.stop();
    SimpleConfig config = new SimpleConfig();
    config.putProperty(CoreConstants.Config.APPLICATION_ID, "APPID");
    ConfigContext.init(config);
    StaticListableBeanFactory testBf = new StaticListableBeanFactory();
    testBf.addBean(KRADServiceLocator.PROVIDER_REGISTRY, prMock);
    ResourceLoader rl = new BeanFactoryResourceLoader(new QName("moduleconfiguration-unittest"), testBf);
    GlobalResourceLoader.addResourceLoader(rl);
    GlobalResourceLoader.start();
}
 
Example 21
@Before
public void setup() throws Exception {
    GlobalResourceLoader.stop();

    SimpleConfig config = new SimpleConfig();
    config.putProperty(CoreConstants.Config.APPLICATION_ID, getClass().getName());
    ConfigContext.init(config);
    ConfigContext.getCurrentContextConfig().removeProperty(KRADConstants.Config.ENABLE_LEGACY_DATA_FRAMEWORK);
    ConfigContext.getCurrentContextConfig().removeProperty(KRADConstants.Config.KNS_ENABLED);

    StaticListableBeanFactory testBf = new StaticListableBeanFactory();
    testBf.addBean("metadataRepository", metadataRepository);
    testBf.addBean("dataDictionaryService", dataDictionaryService);
    testBf.addBean("knsLegacyDataAdapter", knsLegacyDataAdapter);
    testBf.addBean("kradLegacyDataAdapter", kradLegacyDataAdapter);

    ResourceLoader rl = new BeanFactoryResourceLoader(new QName(getClass().getName()), testBf);
    GlobalResourceLoader.addResourceLoader(rl);
    GlobalResourceLoader.start();

    MetadataManager mm = MetadataManager.getInstance();

    // register Legacy object
    ClassDescriptor legacyDescriptor = new ClassDescriptor(mm.getGlobalRepository());
    legacyDescriptor.setClassOfObject(Legacy.class);
    mm.getGlobalRepository().put(Legacy.class, legacyDescriptor);

    // register LegacyDocument object
    ClassDescriptor legacyDocumentDescriptor = new ClassDescriptor(mm.getGlobalRepository());
    legacyDocumentDescriptor.setClassOfObject(LegacyDocument.class);
    mm.getGlobalRepository().put(LegacyDocument.class, legacyDocumentDescriptor);
}
 
Example 22
@Before
public void createBadInstance() {
    StaticListableBeanFactory bf = new StaticListableBeanFactory();
    bf.addBean("bean", "This is a bean");
    bad = (BadInterface)
            Proxy.newProxyInstance(this.getClass().getClassLoader(),
                    new Class[]{BadInterface.class},
                    new BeanFactoryInvocationHandler(bf));
}
 
Example 23
private DefaultMessageHandlerMethodFactory createInstance() {
	DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
	factory.setBeanFactory(new StaticListableBeanFactory());
	return factory;
}
 
Example 24
private void initializeFactory(DefaultMessageHandlerMethodFactory factory) {
	factory.setBeanFactory(new StaticListableBeanFactory());
	factory.afterPropertiesSet();
}
 
Example 25
@Before
public void setup() {
	this.registrar.setEndpointRegistry(this.registry);
	this.registrar.setBeanFactory(new StaticListableBeanFactory());
}
 
Example 26
private void initializeFactory(DefaultMessageHandlerMethodFactory factory) {
	factory.setBeanFactory(new StaticListableBeanFactory());
	factory.afterPropertiesSet();
}
 
Example 27
private void initializeFactory(DefaultMessageHandlerMethodFactory factory) {
	factory.setBeanFactory(new StaticListableBeanFactory());
	factory.afterPropertiesSet();
}
 
Example 28
private DefaultMessageHandlerMethodFactory createInstance() {
	DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
	factory.setBeanFactory(new StaticListableBeanFactory());
	return factory;
}
 
Example 29
private void initializeFactory(DefaultMessageHandlerMethodFactory factory) {
	factory.setBeanFactory(new StaticListableBeanFactory());
	factory.afterPropertiesSet();
}
 
Example 30
@Before
public void setup() {
	this.registrar.setEndpointRegistry(this.registry);
	this.registrar.setBeanFactory(new StaticListableBeanFactory());
}