Java Code Examples for org.springframework.beans.factory.config.BeanExpressionResolver#evaluate()

The following examples show how to use org.springframework.beans.factory.config.BeanExpressionResolver#evaluate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SendToHandlerMethodReturnValueHandler.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
private String resolveName(String name) {
	if (!(this.beanFactory instanceof ConfigurableBeanFactory)) {
		return name;
	}

	ConfigurableBeanFactory configurableBeanFactory = (ConfigurableBeanFactory) this.beanFactory;

	String placeholdersResolved = configurableBeanFactory.resolveEmbeddedValue(name);
	BeanExpressionResolver exprResolver = configurableBeanFactory
			.getBeanExpressionResolver();
	if (exprResolver == null) {
		return name;
	}
	Object result = exprResolver.evaluate(placeholdersResolved,
			new BeanExpressionContext(configurableBeanFactory, null));
	return result != null ? result.toString() : name;
}
 
Example 2
Source File: ServerEndpointExporter.java    From netty-websocket-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
private <T> T resolveAnnotationValue(Object value, Class<T> requiredType, String paramName) {
    if (value == null) {
        return null;
    }
    TypeConverter typeConverter = beanFactory.getTypeConverter();

    if (value instanceof String) {
        String strVal = beanFactory.resolveEmbeddedValue((String) value);
        BeanExpressionResolver beanExpressionResolver = beanFactory.getBeanExpressionResolver();
        if (beanExpressionResolver != null) {
            value = beanExpressionResolver.evaluate(strVal, new BeanExpressionContext(beanFactory, null));
        } else {
            value = strVal;
        }
    }
    try {
        return typeConverter.convertIfNecessary(value, requiredType);
    } catch (TypeMismatchException e) {
        throw new IllegalArgumentException("Failed to convert value of parameter '" + paramName + "' to required type '" + requiredType.getName() + "'");
    }
}
 
Example 3
Source File: ValueResolver.java    From rqueue with Apache License 2.0 6 votes vote down vote up
@NonNull
private static Object resolveExpression(ApplicationContext applicationContext, String name) {
  if (applicationContext instanceof ConfigurableApplicationContext) {
    ConfigurableBeanFactory configurableBeanFactory =
        ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
    String placeholdersResolved = configurableBeanFactory.resolveEmbeddedValue(name);
    BeanExpressionResolver exprResolver = configurableBeanFactory.getBeanExpressionResolver();
    if (exprResolver == null) {
      return name;
    }
    Object result =
        exprResolver.evaluate(
            placeholdersResolved, new BeanExpressionContext(configurableBeanFactory, null));
    if (result != null) {
      return result;
    }
  }
  return name;
}
 
Example 4
Source File: AnnotationMethodHandlerAdapter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Object resolveDefaultValue(String value) {
	if (beanFactory == null) {
		return value;
	}
	String placeholdersResolved = beanFactory.resolveEmbeddedValue(value);
	BeanExpressionResolver exprResolver = beanFactory.getBeanExpressionResolver();
	if (exprResolver == null) {
		return value;
	}
	return exprResolver.evaluate(placeholdersResolved, expressionContext);
}
 
Example 5
Source File: QueueMessageHandler.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
private String[] resolveName(String name) {
	if (!(getApplicationContext() instanceof ConfigurableApplicationContext)) {
		return wrapInStringArray(name);
	}

	ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) getApplicationContext();
	ConfigurableBeanFactory configurableBeanFactory = applicationContext
			.getBeanFactory();

	String placeholdersResolved = configurableBeanFactory.resolveEmbeddedValue(name);
	BeanExpressionResolver exprResolver = configurableBeanFactory
			.getBeanExpressionResolver();
	if (exprResolver == null) {
		return wrapInStringArray(name);
	}
	Object result = exprResolver.evaluate(placeholdersResolved,
			new BeanExpressionContext(configurableBeanFactory, null));
	if (result instanceof String[]) {
		return (String[]) result;
	}
	else if (result != null) {
		return wrapInStringArray(result);
	}
	else {
		return wrapInStringArray(name);
	}
}
 
Example 6
Source File: ApplicationMetricsProperties.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
private Map<String, Object> buildExportProperties() {
	Map<String, Object> props = new HashMap<>();
	if (!ObjectUtils.isEmpty(this.properties)) {
		Map<String, String> target = bindProperties();

		BeanExpressionResolver beanExpressionResolver = ((ConfigurableApplicationContext) this.applicationContext)
				.getBeanFactory().getBeanExpressionResolver();
		BeanExpressionContext expressionContext = new BeanExpressionContext(
				((ConfigurableApplicationContext) this.applicationContext)
						.getBeanFactory(),
				null);
		for (Entry<String, String> entry : target.entrySet()) {
			if (isMatch(entry.getKey(), this.properties, null)) {
				String stringValue = ObjectUtils.nullSafeToString(entry.getValue());
				Object exportedValue = null;
				if (stringValue != null) {
					exportedValue = stringValue.startsWith("#{")
							? beanExpressionResolver.evaluate(
									this.environment.resolvePlaceholders(stringValue),
									expressionContext)
							: this.environment.resolvePlaceholders(stringValue);
				}

				props.put(entry.getKey(), exportedValue);
			}
		}
	}
	return props;
}
 
Example 7
Source File: AbstractNamedValueMethodArgumentResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves the given default value into an argument value.
 */
private Object resolveDefaultValue(String defaultValue) {
	if (this.configurableBeanFactory == null) {
		return defaultValue;
	}
	String placeholdersResolved = this.configurableBeanFactory.resolveEmbeddedValue(defaultValue);
	BeanExpressionResolver exprResolver = this.configurableBeanFactory.getBeanExpressionResolver();
	if (exprResolver == null) {
		return defaultValue;
	}
	return exprResolver.evaluate(placeholdersResolved, this.expressionContext);
}
 
Example 8
Source File: AnnotationMethodHandlerAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected Object resolveDefaultValue(String value) {
	if (beanFactory == null) {
		return value;
	}
	String placeholdersResolved = beanFactory.resolveEmbeddedValue(value);
	BeanExpressionResolver exprResolver = beanFactory.getBeanExpressionResolver();
	if (exprResolver == null) {
		return value;
	}
	return exprResolver.evaluate(placeholdersResolved, expressionContext);
}
 
Example 9
Source File: AnnotationMethodHandlerAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected Object resolveDefaultValue(String value) {
	if (beanFactory == null) {
		return value;
	}
	String placeholdersResolved = beanFactory.resolveEmbeddedValue(value);
	BeanExpressionResolver exprResolver = beanFactory.getBeanExpressionResolver();
	if (exprResolver == null) {
		return value;
	}
	return exprResolver.evaluate(placeholdersResolved, expressionContext);
}
 
Example 10
Source File: AbstractNamedValueMethodArgumentResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves the given default value into an argument value.
 */
private Object resolveDefaultValue(String defaultValue) {
	if (this.configurableBeanFactory == null) {
		return defaultValue;
	}
	String placeholdersResolved = this.configurableBeanFactory.resolveEmbeddedValue(defaultValue);
	BeanExpressionResolver exprResolver = this.configurableBeanFactory.getBeanExpressionResolver();
	if (exprResolver == null) {
		return defaultValue;
	}
	return exprResolver.evaluate(placeholdersResolved, this.expressionContext);
}
 
Example 11
Source File: AbstractNamedValueMethodArgumentResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Resolve the given annotation-specified value,
 * potentially containing placeholders and expressions.
 */
private Object resolveStringValue(String value) {
	if (this.configurableBeanFactory == null) {
		return value;
	}
	String placeholdersResolved = this.configurableBeanFactory.resolveEmbeddedValue(value);
	BeanExpressionResolver exprResolver = this.configurableBeanFactory.getBeanExpressionResolver();
	if (exprResolver == null) {
		return value;
	}
	return exprResolver.evaluate(placeholdersResolved, this.expressionContext);
}
 
Example 12
Source File: AbstractNamedValueMethodArgumentResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Resolve the given annotation-specified value,
 * potentially containing placeholders and expressions.
 */
@Nullable
private Object resolveStringValue(String value) {
	if (this.configurableBeanFactory == null) {
		return value;
	}
	String placeholdersResolved = this.configurableBeanFactory.resolveEmbeddedValue(value);
	BeanExpressionResolver exprResolver = this.configurableBeanFactory.getBeanExpressionResolver();
	if (exprResolver == null || this.expressionContext == null) {
		return value;
	}
	return exprResolver.evaluate(placeholdersResolved, this.expressionContext);
}
 
Example 13
Source File: AbstractNamedValueArgumentResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Resolve the given annotation-specified value,
 * potentially containing placeholders and expressions.
 */
@Nullable
private Object resolveStringValue(String value) {
	if (this.configurableBeanFactory == null || this.expressionContext == null) {
		return value;
	}
	String placeholdersResolved = this.configurableBeanFactory.resolveEmbeddedValue(value);
	BeanExpressionResolver exprResolver = this.configurableBeanFactory.getBeanExpressionResolver();
	if (exprResolver == null) {
		return value;
	}
	return exprResolver.evaluate(placeholdersResolved, this.expressionContext);
}
 
Example 14
Source File: AbstractNamedValueMethodArgumentResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Resolve the given annotation-specified value,
 * potentially containing placeholders and expressions.
 */
private Object resolveStringValue(String value) {
	if (this.configurableBeanFactory == null) {
		return value;
	}
	String placeholdersResolved = this.configurableBeanFactory.resolveEmbeddedValue(value);
	BeanExpressionResolver exprResolver = this.configurableBeanFactory.getBeanExpressionResolver();
	if (exprResolver == null) {
		return value;
	}
	return exprResolver.evaluate(placeholdersResolved, this.expressionContext);
}
 
Example 15
Source File: AbstractNamedValueMethodArgumentResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Resolve the given annotation-specified value,
 * potentially containing placeholders and expressions.
 */
@Nullable
private Object resolveStringValue(String value) {
	if (this.configurableBeanFactory == null) {
		return value;
	}
	String placeholdersResolved = this.configurableBeanFactory.resolveEmbeddedValue(value);
	BeanExpressionResolver exprResolver = this.configurableBeanFactory.getBeanExpressionResolver();
	if (exprResolver == null || this.expressionContext == null) {
		return value;
	}
	return exprResolver.evaluate(placeholdersResolved, this.expressionContext);
}
 
Example 16
Source File: AbstractNamedValueArgumentResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Resolve the given annotation-specified value,
 * potentially containing placeholders and expressions.
 */
@Nullable
private Object resolveStringValue(String value) {
	if (this.configurableBeanFactory == null || this.expressionContext == null) {
		return value;
	}
	String placeholdersResolved = this.configurableBeanFactory.resolveEmbeddedValue(value);
	BeanExpressionResolver exprResolver = this.configurableBeanFactory.getBeanExpressionResolver();
	if (exprResolver == null) {
		return value;
	}
	return exprResolver.evaluate(placeholdersResolved, this.expressionContext);
}
 
Example 17
Source File: AbstractNamedValueMethodArgumentResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Resolve the given annotation-specified value,
 * potentially containing placeholders and expressions.
 */
@Nullable
private Object resolveEmbeddedValuesAndExpressions(String value) {
	if (this.configurableBeanFactory == null || this.expressionContext == null) {
		return value;
	}
	String placeholdersResolved = this.configurableBeanFactory.resolveEmbeddedValue(value);
	BeanExpressionResolver exprResolver = this.configurableBeanFactory.getBeanExpressionResolver();
	if (exprResolver == null) {
		return value;
	}
	return exprResolver.evaluate(placeholdersResolved, this.expressionContext);
}
 
Example 18
Source File: AbstractNamedValueMethodArgumentResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Resolve the given annotation-specified value,
 * potentially containing placeholders and expressions.
 */
@Nullable
private Object resolveEmbeddedValuesAndExpressions(String value) {
	if (this.configurableBeanFactory == null || this.expressionContext == null) {
		return value;
	}
	String placeholdersResolved = this.configurableBeanFactory.resolveEmbeddedValue(value);
	BeanExpressionResolver exprResolver = this.configurableBeanFactory.getBeanExpressionResolver();
	if (exprResolver == null) {
		return value;
	}
	return exprResolver.evaluate(placeholdersResolved, this.expressionContext);
}