本文整理汇总了Java中org.springframework.expression.PropertyAccessor类的典型用法代码示例。如果您正苦于以下问题:Java PropertyAccessor类的具体用法?Java PropertyAccessor怎么用?Java PropertyAccessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PropertyAccessor类属于org.springframework.expression包,在下文中一共展示了PropertyAccessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAddingRemovingAccessors
import org.springframework.expression.PropertyAccessor; //导入依赖的package包/类
@Test
public void testAddingRemovingAccessors() {
StandardEvaluationContext ctx = new StandardEvaluationContext();
// reflective property accessor is the only one by default
List<PropertyAccessor> propertyAccessors = ctx.getPropertyAccessors();
assertEquals(1,propertyAccessors.size());
StringyPropertyAccessor spa = new StringyPropertyAccessor();
ctx.addPropertyAccessor(spa);
assertEquals(2,ctx.getPropertyAccessors().size());
List<PropertyAccessor> copy = new ArrayList<PropertyAccessor>();
copy.addAll(ctx.getPropertyAccessors());
assertTrue(ctx.removePropertyAccessor(spa));
assertFalse(ctx.removePropertyAccessor(spa));
assertEquals(1,ctx.getPropertyAccessors().size());
ctx.setPropertyAccessors(copy);
assertEquals(2,ctx.getPropertyAccessors().size());
}
示例2: isWritableProperty
import org.springframework.expression.PropertyAccessor; //导入依赖的package包/类
public boolean isWritableProperty(String name, TypedValue contextObject, EvaluationContext eContext) throws SpelEvaluationException {
List<PropertyAccessor> accessorsToTry = getPropertyAccessorsToTry(contextObject.getValue(), eContext.getPropertyAccessors());
if (accessorsToTry != null) {
for (PropertyAccessor accessor : accessorsToTry) {
try {
if (accessor.canWrite(eContext, contextObject.getValue(), name)) {
return true;
}
}
catch (AccessException ae) {
// let others try
}
}
}
return false;
}
示例3: isWritableProperty
import org.springframework.expression.PropertyAccessor; //导入依赖的package包/类
public boolean isWritableProperty(String name, TypedValue contextObject, EvaluationContext evalContext)
throws EvaluationException {
List<PropertyAccessor> accessorsToTry =
getPropertyAccessorsToTry(contextObject.getValue(), evalContext.getPropertyAccessors());
if (accessorsToTry != null) {
for (PropertyAccessor accessor : accessorsToTry) {
try {
if (accessor.canWrite(evalContext, contextObject.getValue(), name)) {
return true;
}
}
catch (AccessException ex) {
// let others try
}
}
}
return false;
}
示例4: getPropertyAccessors
import org.springframework.expression.PropertyAccessor; //导入依赖的package包/类
/**
* Automatically load all PropertyAccessor implementations
* (annotated with {@link Component}) from
* com.fortify.util.spring.propertyaccessor (sub-)packages.
* @return
*/
private static final List<PropertyAccessor> getPropertyAccessors() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext("com.fortify.util.spring.propertyaccessor");
try {
// Initialize list with discovered PropertyAccessors
List<PropertyAccessor> result = new ArrayList<PropertyAccessor>(ctx.getBeansOfType(PropertyAccessor.class).values());
// Add the standard PropertyAccessors
result.addAll(new StandardEvaluationContext().getPropertyAccessors());
// Order the accessors
result.sort(new OrderComparator());
LOG.info("[Process] Loaded PropertyAccessors: "+result);
return result;
} finally {
ctx.close();
}
}
示例5: converterCorrectlyInstalled
import org.springframework.expression.PropertyAccessor; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void converterCorrectlyInstalled() {
Expression expression = pojo.getExpression();
assertThat(expression.getValue("{\"a\": {\"b\": 5}}").toString()).isEqualTo("5");
List<PropertyAccessor> propertyAccessors =
TestUtils.getPropertyValue(this.evaluationContext, "propertyAccessors", List.class);
assertThat(propertyAccessors).hasAtLeastOneElementOfType(JsonPropertyAccessor.class);
propertyAccessors =
TestUtils.getPropertyValue(this.config.evaluationContext, "propertyAccessors", List.class);
assertThat(propertyAccessors).hasAtLeastOneElementOfType(JsonPropertyAccessor.class);
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:17,代码来源:SpelExpressionConverterConfigurationTests.java
示例6: preBuilderTest
import org.springframework.expression.PropertyAccessor; //导入依赖的package包/类
/**
* Test the default perbuilder
*/
@Test
public void preBuilderTest(){
DefaultPreBuilder<DefaultSpelTestObj> t = new DefaultPreBuilder<DefaultSpelTestObj>(DefaultSpelTestObj.class);
DefaultSpelTestObj obj = t.build(rules);
SpelTransformer<DefaultSpelTestObj, DefaultSpelTestObj> transformer = new SpelTransformer<DefaultSpelTestObj, DefaultSpelTestObj>();
transformer.setRules(rules);
List<PropertyAccessor> l = new ArrayList<PropertyAccessor>();
l.add(new ReflectivePropertyAccessor());
transformer.setInputaccessors(l);
transformer.setOutputaccessors(l);
transformer.setOutputPreBuilder(t);
DefaultSpelTestObj result = (DefaultSpelTestObj) transformer
.transform(in);
}
示例7: getValue
import org.springframework.expression.PropertyAccessor; //导入依赖的package包/类
@Override
public TypedValue getValue() {
Class<?> targetObjectRuntimeClass = getObjectClass(this.targetObject);
try {
if (Indexer.this.cachedReadName != null && Indexer.this.cachedReadName.equals(this.name) &&
Indexer.this.cachedReadTargetType != null &&
Indexer.this.cachedReadTargetType.equals(targetObjectRuntimeClass)) {
// It is OK to use the cached accessor
return Indexer.this.cachedReadAccessor.read(this.evaluationContext, this.targetObject, this.name);
}
List<PropertyAccessor> accessorsToTry = AstUtils.getPropertyAccessorsToTry(
targetObjectRuntimeClass, this.evaluationContext.getPropertyAccessors());
if (accessorsToTry != null) {
for (PropertyAccessor accessor : accessorsToTry) {
if (accessor.canRead(this.evaluationContext, this.targetObject, this.name)) {
if (accessor instanceof ReflectivePropertyAccessor) {
accessor = ((ReflectivePropertyAccessor) accessor).createOptimalAccessor(
this.evaluationContext, this.targetObject, this.name);
}
Indexer.this.cachedReadAccessor = accessor;
Indexer.this.cachedReadName = this.name;
Indexer.this.cachedReadTargetType = targetObjectRuntimeClass;
return accessor.read(this.evaluationContext, this.targetObject, this.name);
}
}
}
}
catch (AccessException ex) {
throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE,
this.targetObjectTypeDescriptor.toString());
}
throw new SpelEvaluationException(getStartPosition(), SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE,
this.targetObjectTypeDescriptor.toString());
}
示例8: setValue
import org.springframework.expression.PropertyAccessor; //导入依赖的package包/类
@Override
public void setValue(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
Indexer.this.cachedWriteAccessor.write(this.evaluationContext, this.targetObject, this.name, newValue);
return;
}
List<PropertyAccessor> accessorsToTry =
AstUtils.getPropertyAccessorsToTry(contextObjectClass, this.evaluationContext.getPropertyAccessors());
if (accessorsToTry != null) {
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());
}
}
示例9: getPropertyAccessorsToTry
import org.springframework.expression.PropertyAccessor; //导入依赖的package包/类
/**
* Determines the set of property resolvers that should be used to try and access a
* property on the specified target type. The resolvers are considered to be in an
* ordered list, however in the returned list any that are exact matches for the input
* target type (as opposed to 'general' resolvers that could work for any type) are
* placed at the start of the list. In addition, there are specific resolvers that
* exactly name the class in question and resolvers that name a specific class but it
* is a supertype of the class we have. These are put at the end of the specific
* resolvers set and will be tried after exactly matching accessors but before generic
* accessors.
* @param targetType the type upon which property access is being attempted
* @return a list of resolvers that should be tried in order to access the property
*/
public static List<PropertyAccessor> getPropertyAccessorsToTry(Class<?> targetType, List<PropertyAccessor> propertyAccessors) {
List<PropertyAccessor> specificAccessors = new ArrayList<PropertyAccessor>();
List<PropertyAccessor> generalAccessors = new ArrayList<PropertyAccessor>();
for (PropertyAccessor resolver : propertyAccessors) {
Class<?>[] targets = resolver.getSpecificTargetClasses();
if (targets == null) { // generic resolver that says it can be used for any type
generalAccessors.add(resolver);
}
else {
if (targetType != null) {
int pos = 0;
for (Class<?> clazz : targets) {
if (clazz == targetType) { // put exact matches on the front to be tried first?
specificAccessors.add(pos++, resolver);
}
else if (clazz.isAssignableFrom(targetType)) { // put supertype matches at the end of the
// specificAccessor list
generalAccessors.add(resolver);
}
}
}
}
}
List<PropertyAccessor> resolvers = new ArrayList<PropertyAccessor>();
resolvers.addAll(specificAccessors);
resolvers.addAll(generalAccessors);
return resolvers;
}
示例10: getPropertyAccessorsToTry
import org.springframework.expression.PropertyAccessor; //导入依赖的package包/类
/**
* Determines the set of property resolvers that should be used to try and access a property on the specified target
* type. The resolvers are considered to be in an ordered list, however in the returned list any that are exact
* matches for the input target type (as opposed to 'general' resolvers that could work for any type) are placed at
* the start of the list. In addition, there are specific resolvers that exactly name the class in question and
* resolvers that name a specific class but it is a supertype of the class we have. These are put at the end of the
* specific resolvers set and will be tried after exactly matching accessors but before generic accessors.
* @param contextObject the object upon which property access is being attempted
* @return a list of resolvers that should be tried in order to access the property
*/
private List<PropertyAccessor> getPropertyAccessorsToTry(Object contextObject, List<PropertyAccessor> propertyAccessors) {
Class<?> targetType = (contextObject != null ? contextObject.getClass() : null);
List<PropertyAccessor> specificAccessors = new ArrayList<PropertyAccessor>();
List<PropertyAccessor> generalAccessors = new ArrayList<PropertyAccessor>();
for (PropertyAccessor resolver : propertyAccessors) {
Class<?>[] targets = resolver.getSpecificTargetClasses();
if (targets == null) {
// generic resolver that says it can be used for any type
generalAccessors.add(resolver);
}
else if (targetType != null) {
for (Class<?> clazz : targets) {
if (clazz == targetType) {
specificAccessors.add(resolver);
break;
}
else if (clazz.isAssignableFrom(targetType)) {
generalAccessors.add(resolver);
}
}
}
}
List<PropertyAccessor> resolvers = new ArrayList<PropertyAccessor>();
resolvers.addAll(specificAccessors);
generalAccessors.removeAll(specificAccessors);
resolvers.addAll(generalAccessors);
return resolvers;
}
示例11: initializePropertyAccessors
import org.springframework.expression.PropertyAccessor; //导入依赖的package包/类
private synchronized void initializePropertyAccessors() {
if (this.propertyAccessors == null) {
List<PropertyAccessor> defaultAccessors = new ArrayList<PropertyAccessor>();
defaultAccessors.add(new ReflectivePropertyAccessor());
this.propertyAccessors = defaultAccessors;
}
}
示例12: getPropertyAccessorsToTry
import org.springframework.expression.PropertyAccessor; //导入依赖的package包/类
/**
* Determines the set of property resolvers that should be used to try and access a
* property on the specified target type. The resolvers are considered to be in an
* ordered list, however in the returned list any that are exact matches for the input
* target type (as opposed to 'general' resolvers that could work for any type) are
* placed at the start of the list. In addition, there are specific resolvers that
* exactly name the class in question and resolvers that name a specific class but it
* is a supertype of the class we have. These are put at the end of the specific resolvers
* set and will be tried after exactly matching accessors but before generic accessors.
* @param targetType the type upon which property access is being attempted
* @return a list of resolvers that should be tried in order to access the property
*/
public static List<PropertyAccessor> getPropertyAccessorsToTry(
Class<?> targetType, List<PropertyAccessor> propertyAccessors) {
List<PropertyAccessor> specificAccessors = new ArrayList<PropertyAccessor>();
List<PropertyAccessor> generalAccessors = new ArrayList<PropertyAccessor>();
for (PropertyAccessor resolver : propertyAccessors) {
Class<?>[] targets = resolver.getSpecificTargetClasses();
if (targets == null) { // generic resolver that says it can be used for any type
generalAccessors.add(resolver);
}
else {
if (targetType != null) {
int pos = 0;
for (Class<?> clazz : targets) {
if (clazz == targetType) { // put exact matches on the front to be tried first?
specificAccessors.add(pos++, resolver);
}
else if (clazz.isAssignableFrom(targetType)) { // put supertype matches at the end of the
// specificAccessor list
generalAccessors.add(resolver);
}
}
}
}
}
List<PropertyAccessor> resolvers = new LinkedList<PropertyAccessor>();
resolvers.addAll(specificAccessors);
resolvers.addAll(generalAccessors);
return resolvers;
}
示例13: getValueInternal
import org.springframework.expression.PropertyAccessor; //导入依赖的package包/类
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
TypedValue tv = getValueInternal(state.getActiveContextObject(), state.getEvaluationContext(),
state.getConfiguration().isAutoGrowNullReferences());
PropertyAccessor accessorToUse = this.cachedReadAccessor;
if (accessorToUse instanceof CompilablePropertyAccessor) {
CompilablePropertyAccessor accessor = (CompilablePropertyAccessor) accessorToUse;
this.exitTypeDescriptor = CodeFlow.toDescriptor(accessor.getPropertyType());
}
return tv;
}
示例14: getPropertyAccessorsToTry
import org.springframework.expression.PropertyAccessor; //导入依赖的package包/类
/**
* Determines the set of property resolvers that should be used to try and access a property
* on the specified target type. The resolvers are considered to be in an ordered list,
* however in the returned list any that are exact matches for the input target type (as
* opposed to 'general' resolvers that could work for any type) are placed at the start of the
* list. In addition, there are specific resolvers that exactly name the class in question
* and resolvers that name a specific class but it is a supertype of the class we have.
* These are put at the end of the specific resolvers set and will be tried after exactly
* matching accessors but before generic accessors.
* @param contextObject the object upon which property access is being attempted
* @return a list of resolvers that should be tried in order to access the property
*/
private List<PropertyAccessor> getPropertyAccessorsToTry(Object contextObject, List<PropertyAccessor> propertyAccessors) {
Class<?> targetType = (contextObject != null ? contextObject.getClass() : null);
List<PropertyAccessor> specificAccessors = new ArrayList<PropertyAccessor>();
List<PropertyAccessor> generalAccessors = new ArrayList<PropertyAccessor>();
for (PropertyAccessor resolver : propertyAccessors) {
Class<?>[] targets = resolver.getSpecificTargetClasses();
if (targets == null) {
// generic resolver that says it can be used for any type
generalAccessors.add(resolver);
}
else if (targetType != null) {
for (Class<?> clazz : targets) {
if (clazz == targetType) {
specificAccessors.add(resolver);
break;
}
else if (clazz.isAssignableFrom(targetType)) {
generalAccessors.add(resolver);
}
}
}
}
List<PropertyAccessor> resolvers = new ArrayList<PropertyAccessor>();
resolvers.addAll(specificAccessors);
generalAccessors.removeAll(specificAccessors);
resolvers.addAll(generalAccessors);
return resolvers;
}
示例15: generateCode
import org.springframework.expression.PropertyAccessor; //导入依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
PropertyAccessor accessorToUse = this.cachedReadAccessor;
if (!(accessorToUse instanceof CompilablePropertyAccessor)) {
throw new IllegalStateException("Property accessor is not compilable: " + accessorToUse);
}
((CompilablePropertyAccessor) accessorToUse).generateCode(this.name, mv, cf);
cf.pushDescriptor(this.exitTypeDescriptor);
}