This commit is contained in:
Andy Clement 2008-08-16 01:41:13 +00:00
parent 3d4158ea51
commit 2d732ba398
1 changed files with 18 additions and 18 deletions

View File

@ -1,22 +1,21 @@
package org.springframework.expression; package org.springframework.expression;
// TODO (asc) Do we need a 'caching is allowed' option to be configurable at parse time?
/** /**
* A CacheablePropertyAccessor is an optimized PropertyAccessor where the two parts of accessing the * A CacheablePropertyAccessor is an optimized PropertyAccessor where the two parts of accessing the property are
* property are separated: (1) resolving the property and (2) retrieving its value. In some cases there is * separated: (1) resolving the property and (2) retrieving its value. In some cases there is a large cost to
* a large cost to discovering which property an expression refers to and once discovered it will * discovering which property an expression refers to and once discovered it will always resolve to the same property.
* always resolve to the same property. In these situations a CacheablePropertyAccessor enables the * In these situations a CacheablePropertyAccessor enables the resolution to be done once and a reusable object (an
* resolution to be done once and a reusable object (an executor) returned that can be called over and * executor) returned that can be called over and over to retrieve the property value without going through resolution
* over to retrieve the property value without going through resolution again. * again.
* <p> * <p>
* *
* @author Andy Clement * @author Andy Clement
*/ */
public abstract class CacheablePropertyAccessor implements PropertyAccessor { public abstract class CacheablePropertyAccessor implements PropertyAccessor {
/** /**
* Attempt to resolve the named property and return an executor that can be called to * Attempt to resolve the named property and return an executor that can be called to get the value of that
* get the value of that property. Return null if the property cannot be resolved. * property. Return null if the property cannot be resolved.
* *
* @param context the evaluation context * @param context the evaluation context
* @param target the target upon which the property is being accessed * @param target the target upon which the property is being accessed
@ -26,8 +25,8 @@ public abstract class CacheablePropertyAccessor implements PropertyAccessor {
public abstract PropertyReaderExecutor getReaderAccessor(EvaluationContext context, Object target, Object name); public abstract PropertyReaderExecutor getReaderAccessor(EvaluationContext context, Object target, Object name);
/** /**
* Attempt to resolve the named property and return an executor that can be called to * Attempt to resolve the named property and return an executor that can be called to set the value of that
* set the value of that property. Return null if the property cannot be resolved. * property. Return null if the property cannot be resolved.
* *
* @param context the evaluation context * @param context the evaluation context
* @param target the target upon which the property is being accessed * @param target the target upon which the property is being accessed
@ -37,21 +36,22 @@ public abstract class CacheablePropertyAccessor implements PropertyAccessor {
public abstract PropertyWriterExecutor getWriterAccessor(EvaluationContext context, Object target, Object name); public abstract PropertyWriterExecutor getWriterAccessor(EvaluationContext context, Object target, Object name);
// Implementation of PropertyAccessor follows, based on the resolver/executor model // Implementation of PropertyAccessor follows, based on the resolver/executor model
public final boolean canRead(EvaluationContext context, Object target, Object name) throws AccessException { public final boolean canRead(EvaluationContext context, Object target, Object name) throws AccessException {
return getReaderAccessor(context,target,name) != null; return getReaderAccessor(context, target, name) != null;
} }
public final boolean canWrite(EvaluationContext context, Object target, Object name) throws AccessException { public final boolean canWrite(EvaluationContext context, Object target, Object name) throws AccessException {
return getWriterAccessor(context,target,name) != null; return getWriterAccessor(context, target, name) != null;
} }
public final Object read(EvaluationContext context, Object target, Object name) throws AccessException { public final Object read(EvaluationContext context, Object target, Object name) throws AccessException {
return getReaderAccessor(context,target,name).execute(context,target); return getReaderAccessor(context, target, name).execute(context, target);
} }
public final void write(EvaluationContext context, Object target, Object name, Object newValue) throws AccessException { public final void write(EvaluationContext context, Object target, Object name, Object newValue)
getWriterAccessor(context,target,name).execute(context,target,newValue); throws AccessException {
getWriterAccessor(context, target, name).execute(context, target, newValue);
} }
} }