/** * Create a new {@link AbstractNamedValueArgumentResolver} instance. * @param factory a bean factory to use for resolving {@code ${...}} placeholder * and {@code #{...}} SpEL expressions in default values, or {@code null} if default * values are not expected to contain expressions * @param registry for checking reactive type wrappers */ public AbstractNamedValueArgumentResolver(@Nullable ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { super(registry); this.configurableBeanFactory = factory; this.expressionContext = (factory != null ? new BeanExpressionContext(factory, null) : null); }
@Override @Nullable public String resolveStringValue(String strVal) { String value = this.exprContext.getBeanFactory().resolveEmbeddedValue(strVal); if (this.exprResolver != null && value != null) { Object evaluated = this.exprResolver.evaluate(value, this.exprContext); value = (evaluated != null ? evaluated.toString() : null); } return value; }
@Override public boolean canRead(EvaluationContext context, @Nullable Object target, String name) throws AccessException { return (target instanceof BeanExpressionContext && ((BeanExpressionContext) target).containsObject(name)); }
BeanExpressionContext beanEvaluationContext = new BeanExpressionContext(beanFactory, null); sec.addPropertyAccessor(new BeanFactoryAccessor()); sec.addPropertyAccessor(new MapAccessor()); sec.setBeanResolver(new BeanFactoryResolver(beanEvaluationContext.getBeanFactory())); sec.setTypeLocator(new StandardTypeLocator(beanEvaluationContext.getBeanFactory().getBeanClassLoader())); ConversionService conversionService = beanEvaluationContext.getBeanFactory().getConversionService(); if (conversionService != null) { sec.setTypeConverter(new StandardTypeConverter(conversionService));
@Override public TypedValue read(EvaluationContext context, @Nullable Object target, String name) throws AccessException { Assert.state(target instanceof BeanExpressionContext, "Target must be of type BeanExpressionContext"); return new TypedValue(((BeanExpressionContext) target).getObject(name)); }
BeanExpressionContext beanEvaluationContext = new BeanExpressionContext(beanFactory, null); sec.addPropertyAccessor(new BeanFactoryAccessor()); sec.addPropertyAccessor(new MapAccessor()); sec.setBeanResolver(new BeanFactoryResolver(beanEvaluationContext.getBeanFactory())); sec.setTypeLocator(new StandardTypeLocator(beanEvaluationContext.getBeanFactory().getBeanClassLoader())); ConversionService conversionService = beanEvaluationContext.getBeanFactory().getConversionService(); if (conversionService != null) { sec.setTypeConverter(new StandardTypeConverter(conversionService));
@Override public TypedValue read(EvaluationContext context, @Nullable Object target, String name) throws AccessException { Assert.state(target instanceof BeanExpressionContext, "Target must be of type BeanExpressionContext"); return new TypedValue(((BeanExpressionContext) target).getObject(name)); }
public EmbeddedValueResolver(ConfigurableBeanFactory beanFactory) { this.exprContext = new BeanExpressionContext(beanFactory, null); this.exprResolver = beanFactory.getBeanExpressionResolver(); }
@Override @Nullable public String resolveStringValue(String strVal) { String value = this.exprContext.getBeanFactory().resolveEmbeddedValue(strVal); if (this.exprResolver != null && value != null) { Object evaluated = this.exprResolver.evaluate(value, this.exprContext); value = (evaluated != null ? evaluated.toString() : null); } return value; }
@Override public TypedValue read(EvaluationContext context, @Nullable Object target, String name) throws AccessException { Assert.state(target instanceof BeanExpressionContext, "Target must be of type BeanExpressionContext"); return new TypedValue(((BeanExpressionContext) target).getObject(name)); }
@Override public boolean canRead(EvaluationContext context, @Nullable Object target, String name) throws AccessException { return (target instanceof BeanExpressionContext && ((BeanExpressionContext) target).containsObject(name)); }
/** * Constructor with a {@link ConversionService} and a {@link BeanFactory}. * @param cs conversion service for converting values to match the * target method parameter type * @param beanFactory a bean factory to use for resolving {@code ${...}} placeholder * and {@code #{...}} SpEL expressions in default values, or {@code null} if default * values are not expected to contain expressions */ protected AbstractNamedValueMethodArgumentResolver(ConversionService cs, @Nullable ConfigurableBeanFactory beanFactory) { this.conversionService = (cs != null ? cs : DefaultConversionService.getSharedInstance()); this.configurableBeanFactory = beanFactory; this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, null) : null); }
sec.addPropertyAccessor(new MapAccessor()); sec.addPropertyAccessor(new EnvironmentAccessor()); sec.setBeanResolver(new BeanFactoryResolver(evalContext.getBeanFactory())); sec.setTypeLocator(new StandardTypeLocator(evalContext.getBeanFactory().getBeanClassLoader())); ConversionService conversionService = evalContext.getBeanFactory().getConversionService(); if (conversionService != null) { sec.setTypeConverter(new StandardTypeConverter(conversionService));
@Override public boolean canRead(EvaluationContext context, @Nullable Object target, String name) throws AccessException { return (target instanceof BeanExpressionContext && ((BeanExpressionContext) target).containsObject(name)); }
/** * Create a new {@link AbstractNamedValueMethodArgumentResolver} instance. * @param beanFactory a bean factory to use for resolving ${...} placeholder * and #{...} SpEL expressions in default values, or {@code null} if default * values are not expected to contain expressions */ public AbstractNamedValueMethodArgumentResolver(@Nullable ConfigurableBeanFactory beanFactory) { this.configurableBeanFactory = beanFactory; this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, new RequestScope()) : null); }
sec.addPropertyAccessor(new MapAccessor()); sec.addPropertyAccessor(new EnvironmentAccessor()); sec.setBeanResolver(new BeanFactoryResolver(evalContext.getBeanFactory())); sec.setTypeLocator(new StandardTypeLocator(evalContext.getBeanFactory().getBeanClassLoader())); ConversionService conversionService = evalContext.getBeanFactory().getConversionService(); if (conversionService != null) { sec.setTypeConverter(new StandardTypeConverter(conversionService));
public EmbeddedValueResolver(ConfigurableBeanFactory beanFactory) { this.exprContext = new BeanExpressionContext(beanFactory, null); this.exprResolver = beanFactory.getBeanExpressionResolver(); }
private String resolve(String value) { if (this.resolver != null) { String resolvedValue = this.beanExpressionContext.getBeanFactory().resolveEmbeddedValue(value); Object newValue = this.resolver.evaluate(resolvedValue, this.beanExpressionContext); Assert.isInstanceOf(String.class, newValue, "Invalid @SendTo expression"); return (String) newValue; } else { return value; } }
/** * Evaluate the given String as contained in a bean definition, * potentially resolving it as an expression. * @param value the value to check * @param beanDefinition the bean definition that the value comes from * @return the resolved value * @see #setBeanExpressionResolver */ @Nullable protected Object evaluateBeanDefinitionString(@Nullable String value, @Nullable BeanDefinition beanDefinition) { if (this.beanExpressionResolver == null) { return value; } Scope scope = null; if (beanDefinition != null) { String scopeName = beanDefinition.getScope(); if (scopeName != null) { scope = getRegisteredScope(scopeName); } } return this.beanExpressionResolver.evaluate(value, new BeanExpressionContext(this, scope)); }
private String resolve(String value) { if (this.resolver != null) { String resolvedValue = this.beanExpressionContext.getBeanFactory().resolveEmbeddedValue(value); Object newValue = this.resolver.evaluate(resolvedValue, this.beanExpressionContext); Assert.isInstanceOf(String.class, newValue, "Invalid @SendTo expression"); return (String) newValue; } else { return value; } }