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

ConfigurationClassProcessingTests.java 文件源码 项目:spring4-understanding 阅读 30 收藏 0 点赞 0 评论 0
@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]);
}
XmlBeanCollectionTests.java 文件源码 项目:spring4-understanding 阅读 30 收藏 0 点赞 0 评论 0
@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);
}
ConfigurationClassProcessingTests.java 文件源码 项目:class-guard 阅读 29 收藏 0 点赞 0 评论 0
@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]);
}
XmlBeanCollectionTests.java 文件源码 项目:class-guard 阅读 26 收藏 0 点赞 0 评论 0
@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);
}
DefaultsBeanDefinitionParser.java 文件源码 项目:jdal 阅读 29 收藏 0 点赞 0 评论 0
/**
 * 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;
}
DefaultsBeanDefinitionParser.java 文件源码 项目:jdal 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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;
}
MessageBeanProcessor.java 文件源码 项目:kc-rice 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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);
        }
    }
}
MessageBeanProcessor.java 文件源码 项目:kc-rice 阅读 28 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
MessageBeanProcessor.java 文件源码 项目:rice 阅读 29 收藏 0 点赞 0 评论 0
/**
 * 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);
        }
    }
}
MessageBeanProcessor.java 文件源码 项目:rice 阅读 26 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
MessageBeanProcessor.java 文件源码 项目:kuali_rice 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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);
        }
    }
}
MessageBeanProcessor.java 文件源码 项目:kuali_rice 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
UtilNamespaceHandler.java 文件源码 项目:lams 阅读 27 收藏 0 点赞 0 评论 0
@Override
protected Class<?> getBeanClass(Element element) {
    return ListFactoryBean.class;
}
ConfigurationClassProcessingTests.java 文件源码 项目:spring4-understanding 阅读 32 收藏 0 点赞 0 评论 0
public @Bean FactoryBean<?> factoryBean() {
    ListFactoryBean fb = new ListFactoryBean();
    fb.setSourceList(Arrays.asList("element1", "element2"));
    return fb;
}
UtilNamespaceHandler.java 文件源码 项目:spring4-understanding 阅读 23 收藏 0 点赞 0 评论 0
@Override
protected Class<?> getBeanClass(Element element) {
    return ListFactoryBean.class;
}
UtilNamespaceHandler.java 文件源码 项目:spring 阅读 18 收藏 0 点赞 0 评论 0
@Override
protected Class<?> getBeanClass(Element element) {
    return ListFactoryBean.class;
}
NamespaceHandler.java 文件源码 项目:gomall.la 阅读 33 收藏 0 点赞 0 评论 0
@Override
protected Class<ListFactoryBean> getBeanClass(final Element element) {
    return ListFactoryBean.class;
}
ConfigurationClassProcessingTests.java 文件源码 项目:class-guard 阅读 28 收藏 0 点赞 0 评论 0
public @Bean FactoryBean<?> factoryBean() {
    ListFactoryBean fb = new ListFactoryBean();
    fb.setSourceList(Arrays.asList("element1", "element2"));
    return fb;
}
UtilNamespaceHandler.java 文件源码 项目:class-guard 阅读 22 收藏 0 点赞 0 评论 0
@Override
protected Class getBeanClass(Element element) {
    return ListFactoryBean.class;
}
ColumnsBeanDefinitionParser.java 文件源码 项目:jdal 阅读 18 收藏 0 点赞 0 评论 0
/**
 * {@inheritDoc}
 */
@Override
protected Class<?> getBeanClass(Element element) {
    return ListFactoryBean.class;
}
ColumnsBeanDefinitionParser.java 文件源码 项目:jdal 阅读 17 收藏 0 点赞 0 评论 0
/**
 * {@inheritDoc}
 */
@Override
protected Class<?> getBeanClass(Element element) {
    return ListFactoryBean.class;
}
ListBeanDefinitionParser.java 文件源码 项目:jdal 阅读 19 收藏 0 点赞 0 评论 0
/**
 * {@inheritDoc}
 */
@Override
protected Class<?> getBeanClass(Element element) {
    return ListFactoryBean.class;
}


问题


面经


文章

微信
公众号

扫码关注公众号