Example usage for org.springframework.integration.config IntegrationConfigUtils registerSpelFunctionBean

List of usage examples for org.springframework.integration.config IntegrationConfigUtils registerSpelFunctionBean

Introduction

In this page you can find the example usage for org.springframework.integration.config IntegrationConfigUtils registerSpelFunctionBean.

Prototype

public static void registerSpelFunctionBean(BeanDefinitionRegistry registry, String functionId,
            String className, String methodSignature) 

Source Link

Usage

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 ww w .  j  a va2s  . c o 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);
}