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);
}
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);
}
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;
}
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);
}
Aggregations