Search in sources :

Example 11 with StringValueResolver

use of org.springframework.util.StringValueResolver in project com.revolsys.open by revolsys.

the class BeanConfigurrer method processPlaceholderAttributes.

protected void processPlaceholderAttributes(final ConfigurableListableBeanFactory beanFactory, final String beanName, final Map<String, Object> attributes) throws BeansException {
    final StringValueResolver valueResolver = new PlaceholderResolvingStringValueResolver("${", "}", this.ignoreUnresolvablePlaceholders, null, attributes);
    final BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver);
    // locations.
    if (!(beanName.equals(this.beanName) && beanFactory.equals(this.applicationContext))) {
        final BeanDefinition bd = beanFactory.getBeanDefinition(beanName);
        try {
            visitor.visitBeanDefinition(bd);
        } catch (final BeanDefinitionStoreException ex) {
            throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanName, ex.getMessage());
        }
    }
    // NEW in Spring 2.5: resolve placeholders in alias target names and aliases
    // as well.
    beanFactory.resolveAliases(valueResolver);
}
Also used : StringValueResolver(org.springframework.util.StringValueResolver) PlaceholderResolvingStringValueResolver(com.revolsys.spring.util.PlaceholderResolvingStringValueResolver) PlaceholderResolvingStringValueResolver(com.revolsys.spring.util.PlaceholderResolvingStringValueResolver) BeanDefinitionVisitor(org.springframework.beans.factory.config.BeanDefinitionVisitor) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition)

Example 12 with StringValueResolver

use of org.springframework.util.StringValueResolver in project com.revolsys.open by revolsys.

the class BeanConfigurrer method processPlaceholderAttributes.

protected void processPlaceholderAttributes(final ConfigurableListableBeanFactory beanFactory, final Map<String, Object> attributes) throws BeansException {
    final Map<String, Object> attributeMap = new LinkedHashMap<>();
    for (final Entry<String, Object> entry : attributes.entrySet()) {
        final String key = entry.getKey();
        final Object value = entry.getValue();
        if (!(value instanceof BeanReference)) {
            attributeMap.put(key, value);
        }
    }
    final StringValueResolver valueResolver = new PlaceholderResolvingStringValueResolver("${", "}", this.ignoreUnresolvablePlaceholders, null, attributeMap);
    final BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver);
    final String[] beanNames = beanFactory.getBeanDefinitionNames();
    for (int i = 0; i < beanNames.length; i++) {
        // locations.
        if (!(beanNames[i].equals(this.beanName) && beanFactory.equals(this.applicationContext))) {
            final BeanDefinition bd = beanFactory.getBeanDefinition(beanNames[i]);
            try {
                visitor.visitBeanDefinition(bd);
            } catch (final BeanDefinitionStoreException ex) {
                throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanNames[i], ex.getMessage());
            }
        }
    }
    // NEW in Spring 2.5: resolve placeholders in alias target names and aliases
    // as well.
    beanFactory.resolveAliases(valueResolver);
}
Also used : PlaceholderResolvingStringValueResolver(com.revolsys.spring.util.PlaceholderResolvingStringValueResolver) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) LinkedHashMap(java.util.LinkedHashMap) StringValueResolver(org.springframework.util.StringValueResolver) PlaceholderResolvingStringValueResolver(com.revolsys.spring.util.PlaceholderResolvingStringValueResolver) BeanDefinitionVisitor(org.springframework.beans.factory.config.BeanDefinitionVisitor) BeanReference(com.revolsys.spring.BeanReference)

Example 13 with StringValueResolver

use of org.springframework.util.StringValueResolver in project commons by terran4j.

the class DSchedulingAspect method isValidTime.

boolean isValidTime(JobExeInfo lastInfo, Scheduled scheduled, DScheduling distributedScheduling, Logger log) {
    // 之前没有任务执行,视为有效的执行时间。
    if (lastInfo == null) {
        return true;
    }
    // 无效的任务信息,视为无效的执行时间。
    if (lastInfo.getBeginTime() == null || lastInfo.getEndTime() == null) {
        if (log.isInfoEnabled()) {
            log.info("Invalid lastInfo(beginTime OR endTime is null): {}", lastInfo);
        }
        return false;
    }
    long currentTime = System.currentTimeMillis();
    long lastBeginTime = lastInfo.getBeginTime();
    long lastEndTime = lastInfo.getEndTime();
    long tolerableTime = tolerableTimeDeviation();
    StringValueResolver resolver = getResolver();
    // 最早开始的时间点。
    Long point = null;
    String cornText = scheduled.cron();
    if (StringUtils.hasText(cornText)) {
        cornText = resolver.resolveStringValue(cornText);
        String zone = scheduled.zone();
        TimeZone timeZone;
        if (StringUtils.hasText(zone)) {
            zone = resolver.resolveStringValue(zone);
            timeZone = StringUtils.parseTimeZoneString(zone);
        } else {
            timeZone = TimeZone.getDefault();
        }
        CronSequenceGenerator corn = new CronSequenceGenerator(cornText, timeZone);
        Long currentPoint = corn.next(new Date(lastEndTime)).getTime();
        point = getMinPoint(point, currentPoint);
    }
    long fixedDelay = scheduled.fixedDelay();
    if (fixedDelay >= 0) {
        Long currentPoint = lastEndTime + fixedDelay;
        point = getMinPoint(point, currentPoint);
    }
    String fixedDelayString = scheduled.fixedDelayString();
    if (StringUtils.hasText(fixedDelayString)) {
        fixedDelayString = resolver.resolveStringValue(fixedDelayString);
        Long currentPoint = lastEndTime + Long.parseLong(fixedDelayString);
        point = getMinPoint(point, currentPoint);
    }
    long fixedRate = scheduled.fixedRate();
    if (fixedRate > 0) {
        Long currentPoint = lastBeginTime + fixedRate;
        point = getMinPoint(point, currentPoint);
    }
    String fixedRateString = scheduled.fixedRateString();
    if (StringUtils.hasText(fixedRateString)) {
        fixedRateString = resolver.resolveStringValue(fixedRateString);
        Long currentPoint = lastBeginTime + fixedRate;
        point = getMinPoint(point, currentPoint);
    }
    Assert.isTrue(point != null, "Invalid scheduled: " + scheduled);
    return point - tolerableTime <= currentTime;
}
Also used : StringValueResolver(org.springframework.util.StringValueResolver) TimeZone(java.util.TimeZone) CronSequenceGenerator(org.springframework.scheduling.support.CronSequenceGenerator) Date(java.util.Date)

Example 14 with StringValueResolver

use of org.springframework.util.StringValueResolver in project spring-framework by spring-projects.

the class PropertyPlaceholderConfigurer method processProperties.

/**
 * Visit each bean definition in the given bean factory and attempt to replace ${...} property
 * placeholders with values from the given properties.
 */
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
    StringValueResolver valueResolver = new PlaceholderResolvingStringValueResolver(props);
    doProcessProperties(beanFactoryToProcess, valueResolver);
}
Also used : StringValueResolver(org.springframework.util.StringValueResolver)

Aggregations

StringValueResolver (org.springframework.util.StringValueResolver)14 BeanDefinitionVisitor (org.springframework.beans.factory.config.BeanDefinitionVisitor)5 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)3 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)3 PlaceholderResolvingStringValueResolver (com.revolsys.spring.util.PlaceholderResolvingStringValueResolver)2 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 BeanReference (com.revolsys.spring.BeanReference)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 TimeZone (java.util.TimeZone)1 Predicate (java.util.function.Predicate)1 PojoSwaggerGeneratorContext (org.apache.servicecomb.swagger.generator.pojo.PojoSwaggerGeneratorContext)1 CasEmbeddedValueResolver (org.apereo.cas.CasEmbeddedValueResolver)1 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 ConversionService (org.springframework.core.convert.ConversionService)1