Java 类org.springframework.beans.factory.config.ListFactoryBean 实例源码

项目:spring4-understanding    文件:ConfigurationClassProcessingTests.java   
@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]);
}
项目:spring4-understanding    文件:XmlBeanCollectionTests.java   
@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);
}
项目:class-guard    文件:ConfigurationClassProcessingTests.java   
@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]);
}
项目:class-guard    文件:XmlBeanCollectionTests.java   
@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);
}
项目:jdal    文件:DefaultsBeanDefinitionParser.java   
/**
 * 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;
}
项目:jdal    文件:DefaultsBeanDefinitionParser.java   
/**
 * 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;
}
项目:kc-rice    文件:MessageBeanProcessor.java   
/**
 * 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);
        }
    }
}
项目:kc-rice    文件:MessageBeanProcessor.java   
/**
 * 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);
    }
}
项目:rice    文件:MessageBeanProcessor.java   
/**
 * 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);
        }
    }
}
项目:rice    文件:MessageBeanProcessor.java   
/**
 * 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);
    }
}
项目:kuali_rice    文件:MessageBeanProcessor.java   
/**
 * 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);
        }
    }
}
项目:kuali_rice    文件:MessageBeanProcessor.java   
/**
 * 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);
    }
}
项目:lams    文件:UtilNamespaceHandler.java   
@Override
protected Class<?> getBeanClass(Element element) {
    return ListFactoryBean.class;
}
项目:spring4-understanding    文件:ConfigurationClassProcessingTests.java   
public @Bean FactoryBean<?> factoryBean() {
    ListFactoryBean fb = new ListFactoryBean();
    fb.setSourceList(Arrays.asList("element1", "element2"));
    return fb;
}
项目:spring4-understanding    文件:UtilNamespaceHandler.java   
@Override
protected Class<?> getBeanClass(Element element) {
    return ListFactoryBean.class;
}
项目:spring    文件:UtilNamespaceHandler.java   
@Override
protected Class<?> getBeanClass(Element element) {
    return ListFactoryBean.class;
}
项目:gomall.la    文件:NamespaceHandler.java   
@Override
protected Class<ListFactoryBean> getBeanClass(final Element element) {
    return ListFactoryBean.class;
}
项目:class-guard    文件:ConfigurationClassProcessingTests.java   
public @Bean FactoryBean<?> factoryBean() {
    ListFactoryBean fb = new ListFactoryBean();
    fb.setSourceList(Arrays.asList("element1", "element2"));
    return fb;
}
项目:class-guard    文件:UtilNamespaceHandler.java   
@Override
protected Class getBeanClass(Element element) {
    return ListFactoryBean.class;
}
项目:jdal    文件:ColumnsBeanDefinitionParser.java   
/**
 * {@inheritDoc}
 */
@Override
protected Class<?> getBeanClass(Element element) {
    return ListFactoryBean.class;
}
项目:jdal    文件:ColumnsBeanDefinitionParser.java   
/**
 * {@inheritDoc}
 */
@Override
protected Class<?> getBeanClass(Element element) {
    return ListFactoryBean.class;
}
项目:jdal    文件:ListBeanDefinitionParser.java   
/**
 * {@inheritDoc}
 */
@Override
protected Class<?> getBeanClass(Element element) {
    return ListFactoryBean.class;
}