org.springframework.beans.factory.config.ListFactoryBean Java Examples

The following examples show how to use org.springframework.beans.factory.config.ListFactoryBean. 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: ConfigurationClassProcessingTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void configWithFactoryBeanReturnType() {
	ListableBeanFactory factory = initBeanFactory(ConfigWithNonSpecificReturnTypes.class);
	assertEquals(List.class, factory.getType("factoryBean"));
	assertTrue(factory.isTypeMatch("factoryBean", List.class));
	assertEquals(FactoryBean.class, factory.getType("&factoryBean"));
	assertTrue(factory.isTypeMatch("&factoryBean", FactoryBean.class));
	assertFalse(factory.isTypeMatch("&factoryBean", BeanClassLoaderAware.class));
	assertFalse(factory.isTypeMatch("&factoryBean", ListFactoryBean.class));
	assertTrue(factory.getBean("factoryBean") instanceof List);

	String[] beanNames = factory.getBeanNamesForType(FactoryBean.class);
	assertEquals(1, beanNames.length);
	assertEquals("&factoryBean", beanNames[0]);

	beanNames = factory.getBeanNamesForType(BeanClassLoaderAware.class);
	assertEquals(1, beanNames.length);
	assertEquals("&factoryBean", beanNames[0]);

	beanNames = factory.getBeanNamesForType(ListFactoryBean.class);
	assertEquals(1, beanNames.length);
	assertEquals("&factoryBean", beanNames[0]);

	beanNames = factory.getBeanNamesForType(List.class);
	assertEquals("factoryBean", beanNames[0]);
}
 
Example #2
Source File: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * Register default TablePanel Actions
 * @param element current element
 * @param parserContext parserContext
 * @return a new ComponentDefinition with default table action list.
 */
private ComponentDefinition registerDefaultTableActions(Element element, ParserContext parserContext) {
	ManagedList<Object> actions = new ManagedList<Object>(7);
	actions.add(createBeanDefinition(AddAction.class, parserContext));
	actions.add(createBeanDefinition(SelectAllAction.class, parserContext));
	actions.add(createBeanDefinition(DeselectAllAction.class, parserContext));
	actions.add(createBeanDefinition(RemoveAllAction.class, parserContext));
	actions.add(createBeanDefinition(HideShowFilterAction.class, parserContext));
	actions.add(createBeanDefinition(ApplyFilterAction.class, parserContext));
	actions.add(createBeanDefinition(ClearFilterAction.class, parserContext));
	
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(ListFactoryBean.class);
	bdb.getRawBeanDefinition().setSource(parserContext.extractSource(element));
	bdb.addPropertyValue("sourceList", actions);
	bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
	BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), 
			DEFAULT_TABLE_ACTIONS);
	registerBeanComponentDefinition(element, parserContext, bcd);
	return bcd;
}
 
Example #3
Source File: XmlBeanCollectionTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testCollectionFactoryDefaults() throws Exception {
	ListFactoryBean listFactory = new ListFactoryBean();
	listFactory.setSourceList(new LinkedList());
	listFactory.afterPropertiesSet();
	assertTrue(listFactory.getObject() instanceof ArrayList);

	SetFactoryBean setFactory = new SetFactoryBean();
	setFactory.setSourceSet(new TreeSet());
	setFactory.afterPropertiesSet();
	assertTrue(setFactory.getObject() instanceof LinkedHashSet);

	MapFactoryBean mapFactory = new MapFactoryBean();
	mapFactory.setSourceMap(new TreeMap());
	mapFactory.afterPropertiesSet();
	assertTrue(mapFactory.getObject() instanceof LinkedHashMap);
}
 
Example #4
Source File: ConfigurationClassProcessingTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void configWithFactoryBeanReturnType() {
	ListableBeanFactory factory = initBeanFactory(ConfigWithNonSpecificReturnTypes.class);
	assertEquals(List.class, factory.getType("factoryBean"));
	assertTrue(factory.isTypeMatch("factoryBean", List.class));
	assertEquals(FactoryBean.class, factory.getType("&factoryBean"));
	assertTrue(factory.isTypeMatch("&factoryBean", FactoryBean.class));
	assertFalse(factory.isTypeMatch("&factoryBean", BeanClassLoaderAware.class));
	assertFalse(factory.isTypeMatch("&factoryBean", ListFactoryBean.class));
	assertTrue(factory.getBean("factoryBean") instanceof List);

	String[] beanNames = factory.getBeanNamesForType(FactoryBean.class);
	assertEquals(1, beanNames.length);
	assertEquals("&factoryBean", beanNames[0]);

	beanNames = factory.getBeanNamesForType(BeanClassLoaderAware.class);
	assertEquals(1, beanNames.length);
	assertEquals("&factoryBean", beanNames[0]);

	beanNames = factory.getBeanNamesForType(ListFactoryBean.class);
	assertEquals(1, beanNames.length);
	assertEquals("&factoryBean", beanNames[0]);

	beanNames = factory.getBeanNamesForType(List.class);
	assertEquals("factoryBean", beanNames[0]);
}
 
Example #5
Source File: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * Register default TablePanel Actions
 * @param element current element
 * @param parserContext parserContext
 * @return a new ComponentDefinition with default table action list.
 */
private ComponentDefinition registerDefaultTableActions(Element element, ParserContext parserContext) {
	ManagedList<Object> actions = new ManagedList<Object>(7);
	actions.add(createBeanDefinition(AddAction.class, parserContext));
	actions.add(createBeanDefinition(RefreshAction.class, parserContext));
	actions.add(createBeanDefinition(RemoveAction.class, parserContext));
	actions.add(createBeanDefinition(FindAction.class, parserContext));
	actions.add(createBeanDefinition(ClearFilterAction.class, parserContext));
	
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(ListFactoryBean.class);
	bdb.getRawBeanDefinition().setSource(parserContext.extractSource(element));
	bdb.addPropertyValue("sourceList", actions);
	bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
	BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), 
			DEFAULT_TABLE_ACTIONS);
	registerBeanComponentDefinition(element, parserContext, bcd);
	return bcd;
}
 
Example #6
Source File: XmlBeanCollectionTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testCollectionFactoryDefaults() throws Exception {
	ListFactoryBean listFactory = new ListFactoryBean();
	listFactory.setSourceList(new LinkedList());
	listFactory.afterPropertiesSet();
	assertTrue(listFactory.getObject() instanceof ArrayList);

	SetFactoryBean setFactory = new SetFactoryBean();
	setFactory.setSourceSet(new TreeSet());
	setFactory.afterPropertiesSet();
	assertTrue(setFactory.getObject() instanceof LinkedHashSet);

	MapFactoryBean mapFactory = new MapFactoryBean();
	mapFactory.setSourceMap(new TreeMap());
	mapFactory.afterPropertiesSet();
	assertTrue(mapFactory.getObject() instanceof LinkedHashMap);
}
 
Example #7
Source File: ConfigurationClassProcessingTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void configWithFactoryBeanReturnType() {
	ListableBeanFactory factory = initBeanFactory(ConfigWithNonSpecificReturnTypes.class);
	assertEquals(List.class, factory.getType("factoryBean"));
	assertTrue(factory.isTypeMatch("factoryBean", List.class));
	assertEquals(FactoryBean.class, factory.getType("&factoryBean"));
	assertTrue(factory.isTypeMatch("&factoryBean", FactoryBean.class));
	assertFalse(factory.isTypeMatch("&factoryBean", BeanClassLoaderAware.class));
	assertFalse(factory.isTypeMatch("&factoryBean", ListFactoryBean.class));
	assertTrue(factory.getBean("factoryBean") instanceof List);

	String[] beanNames = factory.getBeanNamesForType(FactoryBean.class);
	assertEquals(1, beanNames.length);
	assertEquals("&factoryBean", beanNames[0]);

	beanNames = factory.getBeanNamesForType(BeanClassLoaderAware.class);
	assertEquals(1, beanNames.length);
	assertEquals("&factoryBean", beanNames[0]);

	beanNames = factory.getBeanNamesForType(ListFactoryBean.class);
	assertEquals(1, beanNames.length);
	assertEquals("&factoryBean", beanNames[0]);

	beanNames = factory.getBeanNamesForType(List.class);
	assertEquals("factoryBean", beanNames[0]);
}
 
Example #8
Source File: XmlBeanCollectionTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testCollectionFactoryDefaults() throws Exception {
	ListFactoryBean listFactory = new ListFactoryBean();
	listFactory.setSourceList(new LinkedList());
	listFactory.afterPropertiesSet();
	assertTrue(listFactory.getObject() instanceof ArrayList);

	SetFactoryBean setFactory = new SetFactoryBean();
	setFactory.setSourceSet(new TreeSet());
	setFactory.afterPropertiesSet();
	assertTrue(setFactory.getObject() instanceof LinkedHashSet);

	MapFactoryBean mapFactory = new MapFactoryBean();
	mapFactory.setSourceMap(new TreeMap());
	mapFactory.afterPropertiesSet();
	assertTrue(mapFactory.getObject() instanceof LinkedHashMap);
}
 
Example #9
Source File: MessageBeanProcessor.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Applies the text for a given message to the associated bean definition property
 *
 * @param message message instance to apply
 * @param beanDefinition bean definition the message should be applied to
 * @param beanClass class for the bean definition
 */
protected void applyMessageToBean(Message message, BeanDefinition beanDefinition, Class<?> beanClass) {
    String key = message.getKey().trim();

    // if message doesn't start with path indicator, it will be an explicit key that is matched when
    // iterating over the property values, so we will just return in that case
    if (!key.startsWith(KRADConstants.MESSAGE_KEY_PATH_INDICATOR)) {
        return;
    }

    // if here dealing with a path key, strip off indicator and then process as a property path
    key = StringUtils.stripStart(key, KRADConstants.MESSAGE_KEY_PATH_INDICATOR);

    // list factory beans just have the one list property (with no name)
    if (ListFactoryBean.class.isAssignableFrom(beanClass)) {
        MutablePropertyValues pvs = beanDefinition.getPropertyValues();

        PropertyValue propertyValue = pvs.getPropertyValueList().get(0);
        List<?> listValue = (List<?>) propertyValue.getValue();

        applyMessageToNestedListBean(message, listValue, key);
    } else if (StringUtils.contains(key, ".")) {
        applyMessageToNestedBean(message, beanDefinition, key);
    } else {
        applyMessageTextToPropertyValue(key, message.getText(), beanDefinition);
    }
}
 
Example #10
Source File: MessageBeanProcessor.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Retrieves external messages whose namespace and component matches the bean definition and applies
 * the message text to the bean property values
 *
 * @param beanName name of the bean to process
 * @param beanDefinition bean definition to process
 * @param nestedBeanStack stack of beans that contain the given bean, used for finding a namespace
 */
protected void processBeanMessages(String beanName, BeanDefinition beanDefinition,
        Stack<BeanDefinitionHolder> nestedBeanStack) {
    Class<?> beanClass = getBeanClass(beanDefinition, beanFactory);
    if ((beanClass == null) || !(DictionaryBean.class.isAssignableFrom(beanClass) || ListFactoryBean.class
            .isAssignableFrom(beanClass))) {
        return;
    }

    String namespace = getNamespaceForBean(beanName, beanDefinition);
    if (StringUtils.isBlank(namespace)) {
        namespace = getNamespaceForBeanInStack(nestedBeanStack);
    }

    String componentCode = getComponentForBean(beanName, beanDefinition);
    if (StringUtils.equals(componentCode, beanName)) {
        // check if there is a parent bean in the factory using the standard suffix, if so we will skip this
        // bean as messages will be picked up by that parent bean definition. Note this is not for all parents,
        // just where the convention has been setup for extension (ex. 'bean' and 'bean-parentName')
        String extensionParentBeanName = beanName + KRADConstants.DICTIONARY_BEAN_PARENT_SUFFIX;
        if (beanFactory.containsBean(extensionParentBeanName)) {
            return;
        }
    }

    // if a namespace and component was found retrieve all messages associated with them
    if (StringUtils.isNotBlank(namespace) && StringUtils.isNotBlank(componentCode)) {
        Collection<Message> beanMessages = getMessageService().getAllMessagesForComponent(namespace, componentCode);
        for (Message beanMessage : beanMessages) {
            applyMessageToBean(beanMessage, beanDefinition, beanClass);
        }
    }
}
 
Example #11
Source File: ListBeanDefinitionParser.java    From jdal with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Class<?> getBeanClass(Element element) {
	return ListFactoryBean.class;
}
 
Example #12
Source File: ColumnsBeanDefinitionParser.java    From jdal with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Class<?> getBeanClass(Element element) {
	return ListFactoryBean.class;
}
 
Example #13
Source File: ColumnsBeanDefinitionParser.java    From jdal with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Class<?> getBeanClass(Element element) {
	return ListFactoryBean.class;
}
 
Example #14
Source File: UtilNamespaceHandler.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected Class<?> getBeanClass(Element element) {
	return ListFactoryBean.class;
}
 
Example #15
Source File: ConfigurationClassProcessingTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public @Bean FactoryBean<?> factoryBean() {
	ListFactoryBean fb = new ListFactoryBean();
	fb.setSourceList(Arrays.asList("element1", "element2"));
	return fb;
}
 
Example #16
Source File: UtilNamespaceHandler.java    From blog_demos with Apache License 2.0 4 votes vote down vote up
@Override
protected Class<?> getBeanClass(Element element) {
	return ListFactoryBean.class;
}
 
Example #17
Source File: UtilNamespaceHandler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Class<?> getBeanClass(Element element) {
	return ListFactoryBean.class;
}
 
Example #18
Source File: UtilNamespaceHandler.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
protected Class<?> getBeanClass(Element element) {
	return ListFactoryBean.class;
}
 
Example #19
Source File: ConfigurationClassProcessingTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
public @Bean FactoryBean<?> factoryBean() {
	ListFactoryBean fb = new ListFactoryBean();
	fb.setSourceList(Arrays.asList("element1", "element2"));
	return fb;
}
 
Example #20
Source File: UtilNamespaceHandler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected Class<?> getBeanClass(Element element) {
	return ListFactoryBean.class;
}
 
Example #21
Source File: ConfigurationClassProcessingTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public @Bean FactoryBean<?> factoryBean() {
	ListFactoryBean fb = new ListFactoryBean();
	fb.setSourceList(Arrays.asList("element1", "element2"));
	return fb;
}