All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mule.runtime.config.internal.dsl.spring.ReferenceBeanDefinitionCreator Maven / Gradle / Ivy

/*
 * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 * The software in this package is published under the terms of the CPAL v1.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE.txt file.
 */
package org.mule.runtime.config.internal.dsl.spring;

import static org.mule.runtime.config.internal.model.ApplicationModel.TRANSFORMER_IDENTIFIER;

import org.mule.runtime.api.component.ComponentIdentifier;
import org.mule.runtime.config.internal.model.ComponentModel;
import org.mule.runtime.config.internal.dsl.model.SpringComponentModel;
import org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor;

import com.google.common.collect.ImmutableMap;

import java.util.function.Consumer;

import org.springframework.beans.factory.config.RuntimeBeanReference;

/**
 * Bean definition creator for elements that are just containers for a reference to another bean definition. i.e.:
 * 
 * 
 *     
 *         
 *     
 * 
*

* This construct is deprecated and will only be used for backward compatibility. No new constructs in the language must use this * mechanism. The preferred mechanism is to use an attribute to define the reference or define the object inline as a child * element. i.e.: * *

 *     
 * 
* * @since 4.0 */ class ReferenceBeanDefinitionCreator extends BeanDefinitionCreator { private static final String REF_ATTRIBUTE = "ref"; private ImmutableMap> referenceConsumers = new ImmutableMap.Builder() .put(TRANSFORMER_IDENTIFIER, getConsumer()) .build(); private Consumer getConsumer() { return (beanDefinitionRequest) -> { SpringComponentModel componentModel = beanDefinitionRequest.getComponentModel(); componentModel.setBeanReference(new RuntimeBeanReference(componentModel.getParameters().get(REF_ATTRIBUTE))); ObjectTypeVisitor objectTypeVisitor = new ObjectTypeVisitor(componentModel); beanDefinitionRequest.getComponentBuildingDefinition().getTypeDefinition().visit(objectTypeVisitor); componentModel.setType(objectTypeVisitor.getType()); }; } @Override boolean handleRequest(CreateBeanDefinitionRequest createBeanDefinitionRequest) { ComponentModel componentModel = createBeanDefinitionRequest.getComponentModel(); if (referenceConsumers.containsKey(componentModel.getIdentifier())) { referenceConsumers.get(componentModel.getIdentifier()).accept(createBeanDefinitionRequest); return true; } return false; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy