001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.context.expression; 018 019import org.springframework.beans.factory.config.BeanExpressionContext; 020import org.springframework.expression.AccessException; 021import org.springframework.expression.EvaluationContext; 022import org.springframework.expression.PropertyAccessor; 023import org.springframework.expression.TypedValue; 024 025/** 026 * EL property accessor that knows how to traverse the beans and contextual objects 027 * of a Spring {@link org.springframework.beans.factory.config.BeanExpressionContext}. 028 * 029 * @author Juergen Hoeller 030 * @author Andy Clement 031 * @since 3.0 032 */ 033public class BeanExpressionContextAccessor implements PropertyAccessor { 034 035 @Override 036 public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException { 037 return ((BeanExpressionContext) target).containsObject(name); 038 } 039 040 @Override 041 public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException { 042 return new TypedValue(((BeanExpressionContext) target).getObject(name)); 043 } 044 045 @Override 046 public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException { 047 return false; 048 } 049 050 @Override 051 public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException { 052 throw new AccessException("Beans in a BeanFactory are read-only"); 053 } 054 055 @Override 056 public Class<?>[] getSpecificTargetClasses() { 057 return new Class<?>[] {BeanExpressionContext.class}; 058 } 059 060}