Example usage for org.springframework.beans.factory.support ManagedList ManagedList

List of usage examples for org.springframework.beans.factory.support ManagedList ManagedList

Introduction

In this page you can find the example usage for org.springframework.beans.factory.support ManagedList ManagedList.

Prototype

public ManagedList() 

Source Link

Usage

From source file:de.acosix.alfresco.utility.common.spring.PropertyAlteringBeanFactoryPostProcessor.java

protected Object handleListValues(final PropertyValue configuredValue) {
    final Object value;
    LOGGER.debug(//from  w  w w .j  av  a  2  s.c om
            "[{}] List of values / bean reference names has been configured - treating property {} of {} as <list>",
            this.beanName, this.propertyName, this.targetBeanName);

    final ManagedList<Object> list = new ManagedList<>();

    if (this.merge && configuredValue != null) {
        final Object configuredValueDefinition = configuredValue.getValue();
        if (configuredValueDefinition instanceof ManagedList<?>) {
            final ManagedList<?> oldList = (ManagedList<?>) configuredValueDefinition;
            list.setElementTypeName(oldList.getElementTypeName());
            list.setMergeEnabled(oldList.isMergeEnabled());
            list.setSource(oldList.getSource());

            list.addAll(oldList);

            LOGGER.debug("[{}] Merged existing value list values: {}", this.beanName, oldList);
        }
    }

    List<Object> valuesToAdd;
    if (this.valueList != null) {
        LOGGER.debug("[{}] List of configured values for {} of {}: ", this.beanName, this.propertyName,
                this.targetBeanName, this.valueList);
        valuesToAdd = this.valueList;
    } else {
        LOGGER.debug("[{}] List of configured bean reference names for {} of {}: ", this.beanName,
                this.propertyName, this.targetBeanName, this.beanReferenceNameList);
        valuesToAdd = new ArrayList<>();
        for (final String beanReferenceName : this.beanReferenceNameList) {
            valuesToAdd.add(new RuntimeBeanReference(beanReferenceName));
        }
    }

    if (this.addAsFirst) {
        LOGGER.debug("[{}] Adding new entries at start of list for {} of {}", this.beanName, this.propertyName,
                this.targetBeanName);
        list.addAll(0, valuesToAdd);
    } else if (this.addAtIndex >= 0 && this.addAtIndex < list.size()) {
        LOGGER.debug("[{}] Adding new entries at position {} of list for {} of {}", this.beanName,
                String.valueOf(this.addAtIndex), this.propertyName, this.targetBeanName);
        list.addAll(this.addAtIndex, valuesToAdd);
    } else {
        LOGGER.debug("[{}] Adding new entries at end of list for {} of {}", this.beanName, this.propertyName,
                this.targetBeanName);
        list.addAll(valuesToAdd);
    }

    if (!list.isMergeEnabled() && this.mergeParent) {
        LOGGER.debug("[{}] Enabling \"merge\" for <list> on {} of {}", this.beanName, this.propertyName,
                this.targetBeanName);
    }
    list.setMergeEnabled(list.isMergeEnabled() || this.mergeParent);
    value = list;
    return value;
}

From source file:com.cloudseal.spring.client.namespace.CloudSealBeanDefinitionParserInstance.java

private BeanDefinition createAndRegisterSAMLProcessor() {
    Collection<BeanDefinition> bindings = new ManagedList<BeanDefinition>();
    bindings.add(createRedirectBinding());
    bindings.add(createPostBinding());/* ww  w  .  j  a va  2  s  .  c o  m*/

    BeanDefinitionBuilder builder = createBean(SAMLProcessorImpl.class);
    builder.addConstructorArgValue(bindings);
    BeanDefinition bean = builder.getBeanDefinition();
    return registerBean(bean);
}

From source file:org.solmix.runtime.support.spring.AbstractBeanDefinitionParser.java

/***/
protected void parseMultiRef(String property, String value, BeanDefinitionBuilder bean,
        ParserContext parserContext) {/*from  w w  w.j a  v a2  s.  co  m*/
    String[] values = value.split("\\s*[,]+\\s*");
    ManagedList<Object> list = null;
    for (int i = 0; i < values.length; i++) {
        String v = values[i];
        if (v != null && v.length() > 0) {
            if (list == null) {
                list = new ManagedList<Object>();
            }
            list.add(new RuntimeBeanReference(v));
        }
    }
    bean.getBeanDefinition().getPropertyValues().addPropertyValue(property, list);
}

From source file:com.weibo.api.motan.config.springsupport.MotanBeanDefinitionParser.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private static void parseMethods(String id, NodeList nodeList, RootBeanDefinition beanDefinition,
        ParserContext parserContext) throws ClassNotFoundException {
    if (nodeList != null && nodeList.getLength() > 0) {
        ManagedList methods = null;//from  w w w . jav  a 2s. c  om
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node instanceof Element) {
                Element element = (Element) node;
                if ("method".equals(node.getNodeName()) || "method".equals(node.getLocalName())) {
                    String methodName = element.getAttribute("name");
                    if (methodName == null || methodName.length() == 0) {
                        throw new IllegalStateException("<motan:method> name attribute == null");
                    }
                    if (methods == null) {
                        methods = new ManagedList();
                    }
                    BeanDefinition methodBeanDefinition = parse((Element) node, parserContext,
                            MethodConfig.class, false);
                    String name = id + "." + methodName;
                    BeanDefinitionHolder methodBeanDefinitionHolder = new BeanDefinitionHolder(
                            methodBeanDefinition, name);
                    methods.add(methodBeanDefinitionHolder);
                }
            }
        }
        if (methods != null) {
            beanDefinition.getPropertyValues().addPropertyValue("methods", methods);
        }
    }
}

From source file:com.cloudseal.spring.client.namespace.CloudSealBeanDefinitionParserInstance.java

@SuppressWarnings("unchecked")
private BeanDefinition updateOrCreateAuthenticationManager(BeanDefinition authenticationProvider) {
    Element element = getChildElementByTagName(rootNode, AUTHENTICATION_PROVIDER_NODE);
    if (element != null) {
        String id = getRequiredAttribute(element, AUTHENTICATION_PROVIDER_ID_ATTRIBUTE);
        if (!id.trim().isEmpty()) {
            registerBean(authenticationProvider, id);
        }//from  ww w .ja va  2s  .  co  m
    }

    BeanDefinitionRegistry registry = parserContext.getRegistry();
    if (registry.containsBeanDefinition(SPRING_AUTH_MANAGER_ID)) {
        BeanDefinition bean = registry.getBeanDefinition(SPRING_AUTH_MANAGER_ID);
        MutablePropertyValues properties = bean.getPropertyValues();
        PropertyValue property = properties.getPropertyValue("providers");
        if (property == null) {
            List<BeanDefinition> list = new ManagedList<BeanDefinition>();
            list.add(authenticationProvider);
            properties.addPropertyValue("providers", list);
        } else {
            ((ManagedList<BeanDefinition>) property.getValue()).add(authenticationProvider);
        }
        return bean;
    }

    return createAuthenticationManager(authenticationProvider);
}

From source file:com.cloudseal.spring.client.namespace.CloudSealBeanDefinitionParserInstance.java

private BeanDefinition createAuthenticationManager(BeanDefinition authenticationProvider) {
    List<BeanDefinition> list = new ManagedList<BeanDefinition>();
    list.add(authenticationProvider);//  w w w  .  j av  a2s . c  o m
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(ProviderManager.class);
    builder.addPropertyValue("providers", list);
    return registerBean(builder, SPRING_AUTH_MANAGER_ID);
}

From source file:org.brekka.stillingar.spring.config.ConfigurationServiceBeanDefinitionParser.java

protected void prepareReloadMechanism(Element element, ParserContext parserContext) {
    String id = element.getAttribute("id");
    String reloadIntervalStr = element.getAttribute("reload-interval");
    if (StringUtils.hasLength(reloadIntervalStr)) {
        int reloadInterval = 0;
        try {/*  ww w .  ja v a2s  .co m*/
            reloadInterval = Integer.valueOf(reloadIntervalStr);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("The attribute reload-interval is invalid", e);
        }
        if (reloadInterval >= MINIMUM_RELOAD_INTERVAL) {
            // Update task
            BeanDefinitionBuilder updateTask = BeanDefinitionBuilder
                    .genericBeanDefinition(ConfigurationSnapshotRefresher.class);
            updateTask.addConstructorArgReference(id);

            // Scheduled executor
            BeanDefinitionBuilder scheduledExecutorTask = BeanDefinitionBuilder
                    .genericBeanDefinition(ScheduledExecutorTask.class);
            scheduledExecutorTask.addConstructorArgValue(updateTask.getBeanDefinition());
            if (watchableAvailable) {
                /*
                 * The WatchedResourceMonitor is blocking with a timeout of reloadInterval. Must set a period, choose
                 * an interval of 1s.
                 */
                scheduledExecutorTask.addPropertyValue("period", 1000);
                scheduledExecutorTask.addPropertyValue("delay", 1000);
            } else {
                scheduledExecutorTask.addPropertyValue("period", reloadInterval);
                scheduledExecutorTask.addPropertyValue("delay", reloadInterval);
            }

            ManagedList<Object> taskList = new ManagedList<Object>();
            taskList.add(scheduledExecutorTask.getBeanDefinition());

            // Scheduler factory bean
            BeanDefinitionBuilder scheduledExecutorFactoryBean = BeanDefinitionBuilder
                    .genericBeanDefinition(ScheduledExecutorFactoryBean.class);
            scheduledExecutorFactoryBean.addPropertyValue("scheduledExecutorTasks", taskList);
            scheduledExecutorFactoryBean.addPropertyValue("threadNamePrefix", id + "-reloader");
            scheduledExecutorFactoryBean.addPropertyValue("daemon", Boolean.TRUE);
            parserContext.registerBeanComponent(new BeanComponentDefinition(
                    scheduledExecutorFactoryBean.getBeanDefinition(), id + "-Scheduler"));
        }
    }
}

From source file:org.brekka.stillingar.spring.config.ConfigurationServiceBeanDefinitionParser.java

/**
 * @param element/*from   www. j  av  a 2s  . c o  m*/
 * @return
 */
protected ManagedList<Object> prepareBaseDirectoryList(Element element) {
    ManagedList<Object> list = new ManagedList<Object>();
    Element locationElement = selectSingleChildElement(element, "location", true);
    if (locationElement != null) {
        List<Element> selectChildElements = selectChildElements(locationElement, "*");
        for (Element location : selectChildElements) {
            String tag = location.getLocalName();
            if ("environment-variable".equals(tag)) {
                list.add(prepareLocation(location.getTextContent(), EnvironmentVariableDirectory.class));
            } else if ("system-property".equals(tag)) {
                list.add(prepareLocation(location.getTextContent(), SystemPropertyDirectory.class));
            } else if ("home".equals(tag)) {
                list.add(prepareHomeLocation(element, location.getAttribute("path")));
            } else if ("platform".equals(tag)) {
                list.add(preparePlatformLocation(location.getTextContent()));
            } else if ("webapp".equals(tag)) {
                list.add(prepareWebappLocation(element, location.getAttribute("path")));
            } else if ("resource".equals(tag)) {
                list.add(prepareResourceLocation(element, location.getAttribute("location")));
            } else {
                throw new IllegalArgumentException(String.format("Unknown location type '%s'", tag));
            }
        }
    } else {
        list.add(prepareHomeLocation(element, null));
        PlatformDirectory[] values = PlatformDirectory.values();
        for (PlatformDirectory platformDirectory : values) {
            list.add(platformDirectory);
        }
        // home, webapp (if available) and platforms
        if (ClassUtils.isPresent("org.springframework.web.context.WebApplicationContext",
                this.getClass().getClassLoader())) {
            list.add(prepareWebappLocation(element, null));
        }
    }
    return list;
}

From source file:com.cloudseal.spring.client.namespace.CloudSealBeanDefinitionParserInstance.java

@SuppressWarnings("unchecked")
private void addFilterChainMapValue(Map map, String path, BeanDefinition bean) {
    ManagedList<BeanDefinition> list = (ManagedList<BeanDefinition>) map.get(path);
    if (list == null) {
        list = new ManagedList<BeanDefinition>();
    }/*from   w  w  w. j av  a  2s  .co m*/
    list.add(bean);
    map.put(path, list);
}

From source file:hudson.util.spring.BeanBuilder.java

/**
 * Checks whether there are any runtime refs inside the list and
 * converts it to a ManagedList if necessary
 *
 * @param value The object that represents the list
 * @return Either a new list or a managed one
 */// w ww .  j  av a 2 s .  c o m
private Object manageListIfNecessary(Object value) {
    List list = (List) value;
    boolean containsRuntimeRefs = false;
    for (ListIterator i = list.listIterator(); i.hasNext();) {
        Object e = i.next();
        if (e instanceof RuntimeBeanReference) {
            containsRuntimeRefs = true;
        }
        if (e instanceof BeanConfiguration) {
            BeanConfiguration c = (BeanConfiguration) e;
            i.set(c.getBeanDefinition());
            containsRuntimeRefs = true;
        }
    }
    if (containsRuntimeRefs) {
        List tmp = new ManagedList();
        tmp.addAll((List) value);
        value = tmp;
    }
    return value;
}