Search in sources :

Example 1 with RuntimeBeanReference

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

the class DubboBeanDefinitionParser method parseNested.

private static void parseNested(Element element, ParserContext parserContext, Class<?> beanClass, boolean required, String tag, String property, String ref, BeanDefinition beanDefinition) {
    NodeList nodeList = element.getChildNodes();
    if (nodeList != null && nodeList.getLength() > 0) {
        boolean first = true;
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node instanceof Element) {
                if (tag.equals(node.getNodeName()) || tag.equals(node.getLocalName())) {
                    if (first) {
                        first = false;
                        String isDefault = element.getAttribute("default");
                        if (isDefault == null || isDefault.length() == 0) {
                            beanDefinition.getPropertyValues().addPropertyValue("default", "false");
                        }
                    }
                    BeanDefinition subDefinition = parse((Element) node, parserContext, beanClass, required);
                    if (subDefinition != null && ref != null && ref.length() > 0) {
                        subDefinition.getPropertyValues().addPropertyValue(property, new RuntimeBeanReference(ref));
                    }
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 2 with RuntimeBeanReference

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

the class DubboBeanDefinitionParser method parseMultiRef.

@SuppressWarnings("unchecked")
private static void parseMultiRef(String property, String value, RootBeanDefinition beanDefinition, ParserContext parserContext) {
    String[] values = value.split("\\s*[,]+\\s*");
    ManagedList 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();
            }
            list.add(new RuntimeBeanReference(v));
        }
    }
    beanDefinition.getPropertyValues().addPropertyValue(property, list);
}
Also used : ManagedList(org.springframework.beans.factory.support.ManagedList) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 3 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)

Example 4 with RuntimeBeanReference

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

the class BeanBuilder method methodMissing.

/**
	 * This method is invoked by Groovy when a method that's not defined in Java is invoked.
     * We use that as a syntax for bean definition. 
	 */
public Object methodMissing(String name, Object arg) {
    Object[] args = (Object[]) arg;
    if (args.length == 0)
        throw new MissingMethodException(name, getClass(), args);
    if (args[0] instanceof Closure) {
        // abstract bean definition
        return invokeBeanDefiningMethod(name, args);
    } else if (args[0] instanceof Class || args[0] instanceof RuntimeBeanReference || args[0] instanceof Map) {
        return invokeBeanDefiningMethod(name, args);
    } else if (args.length > 1 && args[args.length - 1] instanceof Closure) {
        return invokeBeanDefiningMethod(name, args);
    }
    WebApplicationContext ctx = springConfig.getUnrefreshedApplicationContext();
    MetaClass mc = DefaultGroovyMethods.getMetaClass(ctx);
    if (!mc.respondsTo(ctx, name, args).isEmpty()) {
        return mc.invokeMethod(ctx, name, args);
    }
    return this;
}
Also used : MissingMethodException(groovy.lang.MissingMethodException) Closure(groovy.lang.Closure) MetaClass(groovy.lang.MetaClass) GroovyObject(groovy.lang.GroovyObject) MetaClass(groovy.lang.MetaClass) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) HashMap(java.util.HashMap) Map(java.util.Map) ManagedMap(org.springframework.beans.factory.support.ManagedMap) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 5 with RuntimeBeanReference

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

the class DelayedQueueDecorator method decorate.

@Override
public void decorate(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, RedissonNamespaceParserSupport helper) {
    Assert.state(element.hasAttribute(DESTINATION_QUEUE_REF), "Illegal state. property \"" + DESTINATION_QUEUE_REF + "\" is required in the \"" + helper.getName(element) + "\" element.");
    helper.addConstructorArgs(new RuntimeBeanReference(helper.getAttribute(element, DESTINATION_QUEUE_REF)), RQueue.class, builder);
}
Also used : RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Aggregations

RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)147 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)83 Element (org.w3c.dom.Element)46 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)38 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)32 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)28 ManagedList (org.springframework.beans.factory.support.ManagedList)25 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)23 Test (org.junit.Test)20 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 Map (java.util.Map)10 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)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