Example usage for org.springframework.beans.factory.config RuntimeBeanReference RuntimeBeanReference

List of usage examples for org.springframework.beans.factory.config RuntimeBeanReference RuntimeBeanReference

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config RuntimeBeanReference RuntimeBeanReference.

Prototype

public RuntimeBeanReference(Class<?> beanType) 

Source Link

Document

Create a new RuntimeBeanReference to a bean of the given type.

Usage

From source file:org.springframework.data.gemfire.config.ParsingUtils.java

static Object getBeanReference(ParserContext parserContext, Element element, String refAttributeName) {
    String refAttributeValue = element.getAttribute(refAttributeName);
    Object returnValue = null;// w  w w .  j  av  a  2  s . c o  m

    if (StringUtils.hasText(refAttributeValue)) {
        if (!DomUtils.getChildElements(element).isEmpty()) {
            parserContext.getReaderContext().error(String.format(
                    "Use either the '%1$s' attribute or a nested bean declaration for '%2$s' element, but not both.",
                    refAttributeName, element.getLocalName()), element);
        }

        returnValue = new RuntimeBeanReference(refAttributeValue);
    }

    return returnValue;
}

From source file:org.springframework.data.jdbc.config.oracle.AqJmsConnectionFactoryBeanDefinitionParser.java

protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    //attributes/*from  w  w  w  .  j  ava 2s.  c  o m*/
    String dataSourceRef = element.getAttribute(DATA_SOURCE_ATTRIBUTE);

    if (logger.isDebugEnabled()) {
        logger.debug("Using provided " + NATIVE_JDBC_EXTRACTOR_ATTRIBUTE + ": " + dataSourceRef);
    }

    String useLocalDataSourceTx = element.getAttribute(USE_LOCAL_DATA_SOURCE_TX_ATTRIBUTE);

    String connectionFactoryTypeRef = element.getAttribute(CONNECTION_FACTORY_TYPE_ATTRIBUTE);

    String nativeJdbcExtractorRef = element.getAttribute(NATIVE_JDBC_EXTRACTOR_ATTRIBUTE);

    builder.getRawBeanDefinition().setBeanClassName(FACTORY_BEAN_CLASS);
    RuntimeBeanReference ds = new RuntimeBeanReference(dataSourceRef);
    builder.addPropertyValue("dataSource", ds);

    if (StringUtils.hasText(useLocalDataSourceTx)) {
        if ("true".equals(useLocalDataSourceTx.toLowerCase())
                || "false".equals(useLocalDataSourceTx.toLowerCase())) {
            builder.addPropertyValue("coordinateWithDataSourceTransactions", useLocalDataSourceTx);
        } else {
            parserContext.getReaderContext().error(
                    "The 'use-local-data-source-transaction' attribute should be \"true\" or \"false\"; \""
                            + useLocalDataSourceTx + "\" is an invalid value",
                    element);
        }
    }

    if (StringUtils.hasText(connectionFactoryTypeRef)) {
        builder.addPropertyValue("connectionFactoryType", connectionFactoryTypeRef);
    }

    if (StringUtils.hasText(nativeJdbcExtractorRef)) {
        RuntimeBeanReference nje = new RuntimeBeanReference(nativeJdbcExtractorRef);
        builder.addPropertyValue("nativeJdbcExtractor", nje);
    }

    builder.setRole(BeanDefinition.ROLE_SUPPORT);

}

From source file:org.springframework.flex.config.FlexConfigurationManagerTests.java

@Test
public void customConfiguration() {
    this.context.registerSingleton("configParser", flex.messaging.config.XPathServerConfigurationParser.class);
    RuntimeBeanReference parserReference = new RuntimeBeanReference("configParser");
    GenericBeanDefinition configManagerDef = new GenericBeanDefinition();
    configManagerDef.setBeanClass(FlexConfigurationManager.class);
    configManagerDef.getPropertyValues().addPropertyValue("configurationParser", parserReference);
    configManagerDef.getPropertyValues().addPropertyValue("configurationPath",
            "classpath:org/springframework/flex/core/services-config.xml");
    this.context.getDefaultListableBeanFactory().registerBeanDefinition("configurationManager",
            configManagerDef);//from w ww.ja  va 2s  .  c  o  m
    this.context.refresh();

    this.configManager = (ConfigurationManager) this.context.getBean("configurationManager");

    MessagingConfiguration messagingConfiguration = this.configManager.getMessagingConfiguration(this.config);

    assertNotNull(messagingConfiguration);
    assertNotNull(messagingConfiguration.getServiceSettings("message-service"));
    assertNotNull(messagingConfiguration.getServiceSettings("proxy-service"));
    assertNotNull(messagingConfiguration.getServiceSettings("remoting-service"));
}

From source file:org.springframework.flex.config.HibernateSerializationConfigPostProcessor.java

@SuppressWarnings("unchecked")
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    if (isHibernateDetected(beanFactory.getBeanClassLoader())) {

        //Make sure there is a MessageBrokerFactoryBean present
        BeanDefinition messageBrokerBeanDef = findMessageBrokerFactoryBeanDefinition(beanFactory);
        Assert.notNull(/*from  w w w . j a v  a2 s.  c  o m*/
                "Could not find an appropriate bean definition for MessageBrokerBeanDefinitionFactoryBean.");

        MutablePropertyValues brokerProps = messageBrokerBeanDef.getPropertyValues();
        ManagedSet<RuntimeBeanReference> configProcessors;
        if (brokerProps.getPropertyValue(CONFIG_PROCESSORS_PROPERTY) != null) {
            configProcessors = (ManagedSet<RuntimeBeanReference>) brokerProps
                    .getPropertyValue(CONFIG_PROCESSORS_PROPERTY).getValue();
        } else {
            configProcessors = new ManagedSet<RuntimeBeanReference>();
        }

        //Abort if HibernateConfigProcessor is already present
        if (isAmfConversionServiceProcessorConfigured(beanFactory, configProcessors)) {
            return;
        }

        if (!ClassUtils.isAssignableValue(BeanDefinitionRegistry.class, beanFactory)) {
            if (log.isWarnEnabled()) {
                log.warn(
                        "Hibernate AMF serialization support could not be auto-configured because the current BeanFactory does not implement "
                                + "BeanDefinitionRegistry.  In order for this support to be enabled, you must manually configure an instance of "
                                + HIBERNATE_CONFIG_PROCESSOR_CLASS);
            }
        }

        BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;

        //Add the appropriate HibernateConfigProcessor bean definition
        BeanDefinitionBuilder processorBuilder;
        if (isJpaDetected(beanFactory.getBeanClassLoader())) {
            processorBuilder = BeanDefinitionBuilder.rootBeanDefinition(JPA_HIBERNATE_CONFIG_PROCESSOR_CLASS);
        } else {
            processorBuilder = BeanDefinitionBuilder.rootBeanDefinition(HIBERNATE_CONFIG_PROCESSOR_CLASS);
        }

        String processorId = BeanDefinitionReaderUtils
                .registerWithGeneratedName(processorBuilder.getBeanDefinition(), registry);

        configProcessors.add(new RuntimeBeanReference(processorId));
    }
}

From source file:org.springframework.integration.config.IntegrationRegistrar.java

/**
 * Register {@code jsonPath} and {@code xpath} SpEL-function beans, if necessary.
 * @param registry The {@link BeanDefinitionRegistry} to register additional {@link BeanDefinition}s.
 *///from   w  w w .j a  va 2  s  .  co m
private void registerBuiltInBeans(BeanDefinitionRegistry registry) {
    int registryId = System.identityHashCode(registry);

    String jsonPathBeanName = "jsonPath";
    boolean alreadyRegistered = false;
    if (registry instanceof ListableBeanFactory) {
        alreadyRegistered = ((ListableBeanFactory) registry).containsBean(jsonPathBeanName);
    } else {
        alreadyRegistered = registry.isBeanNameInUse(jsonPathBeanName);
    }
    if (!alreadyRegistered && !registriesProcessed.contains(registryId)) {
        Class<?> jsonPathClass = null;
        try {
            jsonPathClass = ClassUtils.forName("com.jayway.jsonpath.JsonPath", this.classLoader);
        } catch (ClassNotFoundException e) {
            logger.debug("The '#jsonPath' SpEL function cannot be registered: "
                    + "there is no jayway json-path.jar on the classpath.");
        }

        if (jsonPathClass != null) {
            try {
                ClassUtils.forName("com.jayway.jsonpath.Predicate", this.classLoader);
            } catch (ClassNotFoundException e) {
                jsonPathClass = null;
                logger.warn("The '#jsonPath' SpEL function cannot be registered. "
                        + "An old json-path.jar version is detected in the classpath."
                        + "At least 1.2.0 is required; see version information at: "
                        + "https://github.com/jayway/JsonPath/releases", e);

            }
        }

        if (jsonPathClass != null) {
            IntegrationConfigUtils.registerSpelFunctionBean(registry, jsonPathBeanName,
                    IntegrationConfigUtils.BASE_PACKAGE + ".json.JsonPathUtils", "evaluate");
        }
    }

    alreadyRegistered = false;
    String xpathBeanName = "xpath";
    if (registry instanceof ListableBeanFactory) {
        alreadyRegistered = ((ListableBeanFactory) registry).containsBean(xpathBeanName);
    } else {
        alreadyRegistered = registry.isBeanNameInUse(xpathBeanName);
    }
    if (!alreadyRegistered && !registriesProcessed.contains(registryId)) {
        Class<?> xpathClass = null;
        try {
            xpathClass = ClassUtils.forName(IntegrationConfigUtils.BASE_PACKAGE + ".xml.xpath.XPathUtils",
                    this.classLoader);
        } catch (ClassNotFoundException e) {
            logger.debug("SpEL function '#xpath' isn't registered: "
                    + "there is no spring-integration-xml.jar on the classpath.");
        }

        if (xpathClass != null) {
            IntegrationConfigUtils.registerSpelFunctionBean(registry, xpathBeanName,
                    IntegrationConfigUtils.BASE_PACKAGE + ".xml.xpath.XPathUtils", "evaluate");
        }
    }

    alreadyRegistered = false;
    if (registry instanceof ListableBeanFactory) {
        alreadyRegistered = ((ListableBeanFactory) registry).containsBean(
                IntegrationContextUtils.TO_STRING_FRIENDLY_JSON_NODE_TO_STRING_CONVERTER_BEAN_NAME);
    } else {
        alreadyRegistered = registry.isBeanNameInUse(
                IntegrationContextUtils.TO_STRING_FRIENDLY_JSON_NODE_TO_STRING_CONVERTER_BEAN_NAME);
    }

    if (!alreadyRegistered && !registriesProcessed.contains(registryId) && this.jackson2Present) {
        registry.registerBeanDefinition(
                IntegrationContextUtils.TO_STRING_FRIENDLY_JSON_NODE_TO_STRING_CONVERTER_BEAN_NAME,
                BeanDefinitionBuilder.genericBeanDefinition(
                        IntegrationConfigUtils.BASE_PACKAGE + ".json.ToStringFriendlyJsonNodeToStringConverter")
                        .getBeanDefinition());
        INTEGRATION_CONVERTER_INITIALIZER.registerConverter(registry, new RuntimeBeanReference(
                IntegrationContextUtils.TO_STRING_FRIENDLY_JSON_NODE_TO_STRING_CONVERTER_BEAN_NAME));
    }

    registriesProcessed.add(registryId);
}

From source file:org.springframework.integration.config.xml.ChainParser.java

private BeanMetadataElement parseChild(String chainHandlerId, Element element, int order,
        ParserContext parserContext, BeanDefinition parentDefinition) {

    BeanDefinitionHolder holder = null;/*from w  w  w.jav a2  s  .com*/

    String id = element.getAttribute(ID_ATTRIBUTE);
    boolean hasId = StringUtils.hasText(id);
    String handlerComponentName = chainHandlerId + "$child" + (hasId ? "." + id : "#" + order);

    if ("bean".equals(element.getLocalName())) {
        holder = parserContext.getDelegate().parseBeanDefinitionElement(element, parentDefinition);
    } else {

        this.validateChild(element, parserContext);

        BeanDefinition beanDefinition = parserContext.getDelegate().parseCustomElement(element,
                parentDefinition);
        if (beanDefinition == null) {
            parserContext.getReaderContext().error("child BeanDefinition must not be null", element);
            return null;
        } else {
            holder = new BeanDefinitionHolder(beanDefinition,
                    handlerComponentName + IntegrationNamespaceUtils.HANDLER_ALIAS_SUFFIX);
        }
    }

    holder.getBeanDefinition().getPropertyValues().add("componentName", handlerComponentName);

    if (hasId) {
        BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());
        return new RuntimeBeanReference(holder.getBeanName());
    }

    return holder;
}

From source file:org.springframework.security.config.authentication.PasswordEncoderParser.java

private void parse(Element element, ParserContext parserContext) {
    if (element == null) {
        if (parserContext.getRegistry().containsBeanDefinition("passwordEncoder")) {
            this.passwordEncoder = parserContext.getRegistry().getBeanDefinition("passwordEncoder");
        }/* w  w  w  .  jav  a2  s .  c  o  m*/
        return;
    }
    String hash = element.getAttribute(ATT_HASH);
    boolean useBase64 = false;

    if (StringUtils.hasText(element.getAttribute(ATT_BASE_64))) {
        useBase64 = Boolean.valueOf(element.getAttribute(ATT_BASE_64)).booleanValue();
    }

    String ref = element.getAttribute(ATT_REF);

    if (StringUtils.hasText(ref)) {
        passwordEncoder = new RuntimeBeanReference(ref);
    } else {
        passwordEncoder = createPasswordEncoderBeanDefinition(hash, useBase64);
        ((RootBeanDefinition) passwordEncoder).setSource(parserContext.extractSource(element));
    }
}

From source file:org.springframework.security.config.http.AuthenticationConfigBuilder.java

private void createRememberMeProvider(String key) {
    RootBeanDefinition provider = new RootBeanDefinition(RememberMeAuthenticationProvider.class);
    provider.setSource(rememberMeFilter.getSource());

    provider.getConstructorArgumentValues().addGenericArgumentValue(key);

    String id = pc.getReaderContext().generateBeanName(provider);
    pc.registerBeanComponent(new BeanComponentDefinition(provider, id));

    rememberMeProviderRef = new RuntimeBeanReference(id);
}

From source file:org.springframework.security.config.http.AuthenticationConfigBuilder.java

private void createOpenIDProvider() {
    Element openIDLoginElt = DomUtils.getChildElementByTagName(httpElt, Elements.OPENID_LOGIN);
    BeanDefinitionBuilder openIDProviderBuilder = BeanDefinitionBuilder
            .rootBeanDefinition(OPEN_ID_AUTHENTICATION_PROVIDER_CLASS);

    RootBeanDefinition uds = new RootBeanDefinition();
    uds.setFactoryBeanName(BeanIds.USER_DETAILS_SERVICE_FACTORY);
    uds.setFactoryMethodName("authenticationUserDetailsService");
    uds.getConstructorArgumentValues()//w  w w . j a  v a  2 s  .com
            .addGenericArgumentValue(openIDLoginElt.getAttribute(ATT_USER_SERVICE_REF));

    openIDProviderBuilder.addPropertyValue("authenticationUserDetailsService", uds);

    BeanDefinition openIDProvider = openIDProviderBuilder.getBeanDefinition();
    openIDProviderRef = new RuntimeBeanReference(
            pc.getReaderContext().registerWithGeneratedName(openIDProvider));
}

From source file:org.springframework.security.config.http.AuthenticationConfigBuilder.java

private void injectRememberMeServicesRef(RootBeanDefinition bean, String rememberMeServicesId) {
    if (rememberMeServicesId != null) {
        bean.getPropertyValues().addPropertyValue("rememberMeServices",
                new RuntimeBeanReference(rememberMeServicesId));
    }/*w w  w. j a va 2  s.c  om*/
}