Search in sources :

Example 61 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project redisson by redisson.

the class LocalCachedMapOptionsDecorator method decorate.

@Override
public void decorate(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, RedissonNamespaceParserSupport helper) {
    NodeList list = element.getElementsByTagNameNS(RedissonNamespaceParserSupport.REDISSON_NAMESPACE, RedissonNamespaceParserSupport.LOCAL_CACHED_MAP_OPTIONS_ELEMENT);
    Element options = null;
    String id;
    if (list.getLength() == 1) {
        options = (Element) list.item(0);
        id = invokeOptions(options, parserContext, helper);
        for (int i = 0; i < options.getAttributes().getLength(); i++) {
            Attr item = (Attr) options.getAttributes().item(i);
            if (helper.isEligibleAttribute(item) && !RedissonNamespaceParserSupport.TIME_TO_LIVE_UNIT_ATTRIBUTE.equals(item.getLocalName()) && !RedissonNamespaceParserSupport.MAX_IDLE_UNIT_ATTRIBUTE.equals(item.getLocalName())) {
                helper.invoker(id, helper.getName(item), new Object[] { item.getValue() }, parserContext);
            }
        }
        invokeTimeUnitOptions(options, id, parserContext, helper, RedissonNamespaceParserSupport.TIME_TO_LIVE_ATTRIBUTE, RedissonNamespaceParserSupport.TIME_TO_LIVE_UNIT_ATTRIBUTE);
        invokeTimeUnitOptions(options, id, parserContext, helper, RedissonNamespaceParserSupport.MAX_IDLE_ATTRIBUTE, RedissonNamespaceParserSupport.MAX_IDLE_UNIT_ATTRIBUTE);
    } else {
        id = invokeOptions(options, parserContext, helper);
    }
    helper.addConstructorArgs(new RuntimeBeanReference(id), LocalCachedMapOptions.class, builder);
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) Attr(org.w3c.dom.Attr)

Example 62 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project redisson by redisson.

the class RedissonLiveObjectDefinitionParser method parseNested.

@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
    Class<?> apiClass;
    try {
        apiClass = Class.forName(helper.getAttribute(element, RedissonNamespaceParserSupport.CLASS_ATTRIBUTE));
    } catch (ClassNotFoundException ex) {
        throw new IllegalArgumentException("The class [" + helper.getAttribute(element, RedissonNamespaceParserSupport.CLASS_ATTRIBUTE) + "] specified in \"api-class\" attribute has not " + "found. Please check the class path.", ex);
    }
    Assert.state(helper.hasAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_ATTRIBUTE) || helper.hasAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_REF_ATTRIBUTE), "One of \"" + RedissonNamespaceParserSupport.OBJECT_ID_ATTRIBUTE + "\" or \"" + RedissonNamespaceParserSupport.OBJECT_ID_REF_ATTRIBUTE + "\" attribute is required in the \"" + RedissonNamespaceParserSupport.LIVE_OBJECT_ELEMENT + "\" element.");
    builder.addPropertyValue("targetObject", new RuntimeBeanReference(helper.getAttribute(element, RedissonNamespaceParserSupport.LIVE_OBJECT_SERVICE_REF_ATTRIBUTE)));
    builder.addPropertyValue("targetMethod", "get");
    ManagedList args = new ManagedList();
    args.add(apiClass);
    if (helper.hasAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_ATTRIBUTE)) {
        args.add(helper.getAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_ATTRIBUTE));
    }
    if (helper.hasAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_REF_ATTRIBUTE)) {
        args.add(new RuntimeBeanReference(helper.getAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_REF_ATTRIBUTE)));
    }
    builder.addPropertyValue("arguments", args);
}
Also used : ManagedList(org.springframework.beans.factory.support.ManagedList) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 63 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project redisson by redisson.

the class RedissonMultiLockDefinitionParser method parseNested.

@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
    bd.setDependsOn(element.getAttribute(RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE));
    List<Element> childElements = DomUtils.getChildElements(element);
    for (Element elt : childElements) {
        String localName = elt.getLocalName();
        if (BeanDefinitionParserDelegate.QUALIFIER_ELEMENT.equals(localName)) {
            //parsed elsewhere
            continue;
        }
        String id;
        if (BeanDefinitionParserDelegate.REF_ELEMENT.equals(localName)) {
            id = elt.getAttribute(BeanDefinitionParserDelegate.BEAN_REF_ATTRIBUTE);
        } else {
            if (!elt.hasAttribute(RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE)) {
                helper.setAttribute(elt, RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE, element.getAttribute(RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE));
            }
            helper.populateIdAttribute(elt, builder, parserContext);
            parserContext.getDelegate().parseCustomElement(elt, bd);
            id = elt.getAttribute(RedissonNamespaceParserSupport.ID_ATTRIBUTE);
        }
        ConstructorArgumentValues args = builder.getRawBeanDefinition().getConstructorArgumentValues();
        if (args.getArgumentCount() > 0) {
            ConstructorArgumentValues.ValueHolder value = args.getIndexedArgumentValues().get(0);
            ManagedList list;
            if (value.getValue() instanceof ManagedList) {
                list = (ManagedList) value.getValue();
            } else {
                list = new ManagedList();
                list.add(value.getValue());
                value.setValue(list);
                value.setType(ManagedList.class.getName());
            }
            list.add(new RuntimeBeanReference(id));
        } else {
            builder.addConstructorArgReference(id);
        }
    }
}
Also used : Element(org.w3c.dom.Element) ManagedList(org.springframework.beans.factory.support.ManagedList) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 64 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project redisson by redisson.

the class RedissonRPCClientDefinitionParser method parseNested.

@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
    Class<?> apiClass;
    try {
        apiClass = Class.forName(helper.getAttribute(element, RedissonNamespaceParserSupport.API_CLASS_ATTRIBUTE));
    } catch (ClassNotFoundException ex) {
        throw new IllegalArgumentException("The class [" + helper.getAttribute(element, RedissonNamespaceParserSupport.API_CLASS_ATTRIBUTE) + "] specified in \"" + RedissonNamespaceParserSupport.API_CLASS_ATTRIBUTE + "\" attribute has not " + "found. Please check the class path.", ex);
    }
    builder.addPropertyValue("targetObject", new RuntimeBeanReference(helper.getAttribute(element, RedissonNamespaceParserSupport.REMOTE_SERVICE_REF_ATTRIBUTE)));
    builder.addPropertyValue("targetMethod", "get");
    builder.addPropertyValue("arguments", new Object[] { apiClass });
}
Also used : RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 65 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project hudson-2.x by hudson.

the class BeanBuilder method manageMapIfNecessary.

/**
	 * Checks whether there are any runtime refs inside a Map and converts
	 * it to a ManagedMap if necessary
	 *
	 * @param value The current map
	 * @return A ManagedMap or a normal map
	 */
private Object manageMapIfNecessary(Object value) {
    Map<Object, Object> map = (Map) value;
    boolean containsRuntimeRefs = false;
    for (Entry<Object, Object> e : map.entrySet()) {
        Object v = e.getValue();
        if (v instanceof RuntimeBeanReference) {
            containsRuntimeRefs = true;
        }
        if (v instanceof BeanConfiguration) {
            BeanConfiguration c = (BeanConfiguration) v;
            e.setValue(c.getBeanDefinition());
            containsRuntimeRefs = true;
        }
    }
    if (containsRuntimeRefs) {
        //			return new ManagedMap(map);
        ManagedMap m = new ManagedMap();
        m.putAll(map);
        return m;
    }
    return value;
}
Also used : GroovyObject(groovy.lang.GroovyObject) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) HashMap(java.util.HashMap) Map(java.util.Map) ManagedMap(org.springframework.beans.factory.support.ManagedMap) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Aggregations

RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)156 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)86 Element (org.w3c.dom.Element)47 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)39 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)33 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)32 ManagedList (org.springframework.beans.factory.support.ManagedList)27 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)24 Test (org.junit.Test)21 ManagedMap (org.springframework.beans.factory.support.ManagedMap)20 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)16 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)15 GroovyObject (groovy.lang.GroovyObject)12 TestBean (org.springframework.tests.sample.beans.TestBean)12 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)11 Map (java.util.Map)10 Node (org.w3c.dom.Node)10 HashMap (java.util.HashMap)9 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)9 ITestBean (org.springframework.tests.sample.beans.ITestBean)8