Example usage for org.springframework.beans.factory.config TypedStringValue hasTargetType

List of usage examples for org.springframework.beans.factory.config TypedStringValue hasTargetType

Introduction

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

Prototype

public boolean hasTargetType() 

Source Link

Document

Return whether this typed String value carries a target type .

Usage

From source file:de.acosix.alfresco.mtsupport.repo.subsystems.TenantAwareSubsystemPlaceholderConfigurer.java

/**
 * {@inheritDoc}/*from  ww  w.j ava  2 s  .co  m*/
 */
@Override
protected void doProcessProperties(final ConfigurableListableBeanFactory beanFactoryToProcess,
        final StringValueResolver valueResolver) {
    final BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver) {

        /**
         * {@inheritDoc}
         */
        @Override
        protected Object resolveValue(final Object value) {
            Object result = value;

            // TODO Report bug with Spring
            // TypedStringValue may be reused as result of cloneBeanDefinition and thus should not be mutated

            if (value instanceof TypedStringValue) {
                final TypedStringValue typedStringValue = (TypedStringValue) value;
                final String stringValue = typedStringValue.getValue();
                if (stringValue != null) {
                    final String visitedString = this.resolveStringValue(stringValue);
                    if (!stringValue.equals(visitedString)) {
                        result = typedStringValue.hasTargetType()
                                ? new TypedStringValue(visitedString, typedStringValue.getTargetType())
                                : new TypedStringValue(visitedString);
                    }
                }
            } else {
                result = super.resolveValue(value);
            }

            return result;
        }
    };

    final String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
    for (final String curName : beanNames) {
        // Check that we're not parsing our own bean definition,
        // to avoid failing on unresolvable placeholders in properties file locations.
        if (!(curName.equals(this.beanName) && beanFactoryToProcess.equals(this.beanFactory))) {
            final String tenantDomain;
            if (curName.contains(TenantBeanUtils.TENANT_BEAN_NAME_PATTERN)) {
                tenantDomain = curName.substring(curName.indexOf(TenantBeanUtils.TENANT_BEAN_NAME_PATTERN)
                        + TenantBeanUtils.TENANT_BEAN_NAME_PATTERN.length());
                LOGGER.debug("[{}] Processing bean {} for tenant domain {}", this.beanName, curName,
                        tenantDomain);
            } else {
                LOGGER.debug("[{}] Processing bean {} without tenant domain", this.beanName, curName);
                tenantDomain = null;
            }

            final BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(curName);
            TENANT_CONTEXT.set(tenantDomain);
            try {
                visitor.visitBeanDefinition(bd);
            } catch (final Exception ex) {
                throw new BeanDefinitionStoreException(bd.getResourceDescription(), curName, ex.getMessage());
            } finally {
                TENANT_CONTEXT.remove();
            }
        }
    }
    LOGGER.debug("[{}] Completed processing all beans", this.beanName);

    // New in Spring 2.5: resolve placeholders in alias target names and aliases as well.
    beanFactoryToProcess.resolveAliases(valueResolver);

    // New in Spring 3.0: resolve placeholders in embedded values such as annotation attributes.
    beanFactoryToProcess.addEmbeddedValueResolver(valueResolver);

}