@Override public Object resolve(EvaluationContext context, String beanName) throws AccessException { try { return this.beanFactory.getBean(beanName); } catch (BeansException ex) { throw new AccessException("Could not resolve bean reference against BeanFactory", ex); } }
/** * Decode the AccessException, throwing a lightweight evaluation exception or, * if the cause was a RuntimeException, throw the RuntimeException directly. */ private void throwSimpleExceptionIfPossible(Object value, AccessException ex) { if (ex.getCause() instanceof InvocationTargetException) { Throwable rootCause = ex.getCause().getCause(); if (rootCause instanceof RuntimeException) { throw (RuntimeException) rootCause; } throw new ExpressionInvocationTargetException(getStartPosition(), "A problem occurred when trying to execute method '" + this.name + "' on object of type [" + value.getClass().getName() + "]", rootCause); } }
@Override public void setValue(@Nullable Object newValue) { Class<?> contextObjectClass = getObjectClass(this.targetObject); try { if (Indexer.this.cachedWriteName != null && Indexer.this.cachedWriteName.equals(this.name) && Indexer.this.cachedWriteTargetType != null && Indexer.this.cachedWriteTargetType.equals(contextObjectClass)) { // It is OK to use the cached accessor PropertyAccessor accessor = Indexer.this.cachedWriteAccessor; Assert.state(accessor != null, "No cached write accessor"); accessor.write(this.evaluationContext, this.targetObject, this.name, newValue); return; } List<PropertyAccessor> accessorsToTry = AstUtils.getPropertyAccessorsToTry( contextObjectClass, this.evaluationContext.getPropertyAccessors()); for (PropertyAccessor accessor : accessorsToTry) { if (accessor.canWrite(this.evaluationContext, this.targetObject, this.name)) { Indexer.this.cachedWriteName = this.name; Indexer.this.cachedWriteTargetType = contextObjectClass; Indexer.this.cachedWriteAccessor = accessor; accessor.write(this.evaluationContext, this.targetObject, this.name, newValue); return; } } } catch (AccessException ex) { throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_PROPERTY_WRITE, this.name, ex.getMessage()); } }
@Override public void write(EvaluationContext context, @Nullable Object target, String name, @Nullable Object newValue) throws AccessException { throw new AccessException("Beans in a BeanFactory are read-only"); }
throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_METHOD_INVOCATION, this.name, value.getClass().getName(), ex.getMessage());
/** * Decode the AccessException, throwing a lightweight evaluation exception or, * if the cause was a RuntimeException, throw the RuntimeException directly. */ private void throwSimpleExceptionIfPossible(Object value, AccessException ex) { if (ex.getCause() instanceof InvocationTargetException) { Throwable rootCause = ex.getCause().getCause(); if (rootCause instanceof RuntimeException) { throw (RuntimeException) rootCause; } throw new ExpressionInvocationTargetException(getStartPosition(), "A problem occurred when trying to execute method '" + this.name + "' on object of type [" + value.getClass().getName() + "]", rootCause); } }
@Override public void write(EvaluationContext context, @Nullable Object target, String name, @Nullable Object newValue) throws AccessException { throw new AccessException("Beans in a BeanFactory are read-only"); }
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { BeanResolver beanResolver = state.getEvaluationContext().getBeanResolver(); if (beanResolver == null) { throw new SpelEvaluationException( getStartPosition(), SpelMessage.NO_BEAN_RESOLVER_REGISTERED, this.beanName); } try { return new TypedValue(beanResolver.resolve(state.getEvaluationContext(), this.beanName)); } catch (AccessException ex) { throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_BEAN_RESOLUTION, this.beanName, ex.getMessage()); } }
@Override public Object resolve(EvaluationContext context, String beanName) throws AccessException { try { return this.beanFactory.getBean(beanName); } catch (BeansException ex) { throw new AccessException("Could not resolve bean reference against BeanFactory", ex); } }
@Override public void setValue(@Nullable Object newValue) { Class<?> contextObjectClass = getObjectClass(this.targetObject); try { if (Indexer.this.cachedWriteName != null && Indexer.this.cachedWriteName.equals(this.name) && Indexer.this.cachedWriteTargetType != null && Indexer.this.cachedWriteTargetType.equals(contextObjectClass)) { // It is OK to use the cached accessor PropertyAccessor accessor = Indexer.this.cachedWriteAccessor; Assert.state(accessor != null, "No cached write accessor"); accessor.write(this.evaluationContext, this.targetObject, this.name, newValue); return; } List<PropertyAccessor> accessorsToTry = AstUtils.getPropertyAccessorsToTry( contextObjectClass, this.evaluationContext.getPropertyAccessors()); for (PropertyAccessor accessor : accessorsToTry) { if (accessor.canWrite(this.evaluationContext, this.targetObject, this.name)) { Indexer.this.cachedWriteName = this.name; Indexer.this.cachedWriteTargetType = contextObjectClass; Indexer.this.cachedWriteAccessor = accessor; accessor.write(this.evaluationContext, this.targetObject, this.name, newValue); return; } } } catch (AccessException ex) { throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_PROPERTY_WRITE, this.name, ex.getMessage()); } }
@Override public void write(EvaluationContext context, @Nullable Object target, String name, @Nullable Object newValue) throws AccessException { throw new AccessException("Beans in a BeanFactory are read-only"); }
throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_METHOD_INVOCATION, this.name, value.getClass().getName(), ex.getMessage());
/** * Decode the AccessException, throwing a lightweight evaluation exception or, * if the cause was a RuntimeException, throw the RuntimeException directly. */ private void throwSimpleExceptionIfPossible(Object value, AccessException ex) { if (ex.getCause() instanceof InvocationTargetException) { Throwable rootCause = ex.getCause().getCause(); if (rootCause instanceof RuntimeException) { throw (RuntimeException) rootCause; } throw new ExpressionInvocationTargetException(getStartPosition(), "A problem occurred when trying to execute method '" + this.name + "' on object of type [" + value.getClass().getName() + "]", rootCause); } }
@Override public void write(EvaluationContext context, @Nullable Object target, String name, @Nullable Object newValue) throws AccessException { throw new AccessException("Beans in a BeanFactory are read-only"); }
name, ex.getMessage());
@Nullable private Object resolveImplicitVariable(String name) throws AccessException { if (this.variableResolver == null) { return null; } try { return this.variableResolver.resolveVariable(name); } catch (Exception ex) { throw new AccessException( "Unexpected exception occurred accessing '" + name + "' as an implicit variable", ex); } } }
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { BeanResolver beanResolver = state.getEvaluationContext().getBeanResolver(); if (beanResolver == null) { throw new SpelEvaluationException( getStartPosition(), SpelMessage.NO_BEAN_RESOLVER_REGISTERED, this.beanName); } try { return new TypedValue(beanResolver.resolve(state.getEvaluationContext(), this.beanName)); } catch (AccessException ex) { throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_BEAN_RESOLUTION, this.beanName, ex.getMessage()); } }