Java Code Examples for org.springframework.expression.spel.support.ReflectivePropertyAccessor

The following examples show how to use org.springframework.expression.spel.support.ReflectivePropertyAccessor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-analysis-note   Source File: Indexer.java    License: MIT License 6 votes vote down vote up
@Override
public boolean isCompilable() {
	if (this.indexedType == IndexedType.ARRAY) {
		return (this.exitTypeDescriptor != null);
	}
	else if (this.indexedType == IndexedType.LIST) {
		return this.children[0].isCompilable();
	}
	else if (this.indexedType == IndexedType.MAP) {
		return (this.children[0] instanceof PropertyOrFieldReference || this.children[0].isCompilable());
	}
	else if (this.indexedType == IndexedType.OBJECT) {
		// If the string name is changing the accessor is clearly going to change (so no compilation possible)
		return (this.cachedReadAccessor != null &&
				this.cachedReadAccessor instanceof ReflectivePropertyAccessor.OptimalPropertyAccessor &&
				getChild(0) instanceof StringLiteral);
	}
	return false;
}
 
Example 2
Source Project: java-technology-stack   Source File: Indexer.java    License: MIT License 6 votes vote down vote up
@Override
public boolean isCompilable() {
	if (this.indexedType == IndexedType.ARRAY) {
		return (this.exitTypeDescriptor != null);
	}
	else if (this.indexedType == IndexedType.LIST) {
		return this.children[0].isCompilable();
	}
	else if (this.indexedType == IndexedType.MAP) {
		return (this.children[0] instanceof PropertyOrFieldReference || this.children[0].isCompilable());
	}
	else if (this.indexedType == IndexedType.OBJECT) {
		// If the string name is changing the accessor is clearly going to change (so no compilation possible)
		return (this.cachedReadAccessor != null &&
				this.cachedReadAccessor instanceof ReflectivePropertyAccessor.OptimalPropertyAccessor &&
				getChild(0) instanceof StringLiteral);
	}
	return false;
}
 
Example 3
Source Project: lams   Source File: Indexer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean isCompilable() {
	if (this.indexedType == IndexedType.ARRAY) {
		return (this.exitTypeDescriptor != null);
	}
	else if (this.indexedType == IndexedType.LIST) {
		return this.children[0].isCompilable();
	}
	else if (this.indexedType == IndexedType.MAP) {
		return (this.children[0] instanceof PropertyOrFieldReference || this.children[0].isCompilable());
	}
	else if (this.indexedType == IndexedType.OBJECT) {
		// If the string name is changing the accessor is clearly going to change (so compilation is not possible)
		if (this.cachedReadAccessor != null && 
				(this.cachedReadAccessor instanceof ReflectivePropertyAccessor.OptimalPropertyAccessor) &&
				(getChild(0) instanceof StringLiteral)) {
			return true;
		}
	}
	return false;
}
 
Example 4
Source Project: spring4-understanding   Source File: Indexer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean isCompilable() {
	if (this.indexedType == IndexedType.ARRAY) {
		return (this.exitTypeDescriptor != null);
	}
	else if (this.indexedType == IndexedType.LIST) {
		return this.children[0].isCompilable();
	}
	else if (this.indexedType == IndexedType.MAP) {
		return (this.children[0] instanceof PropertyOrFieldReference || this.children[0].isCompilable());
	}
	else if (this.indexedType == IndexedType.OBJECT) {
		// If the string name is changing the accessor is clearly going to change (so compilation is not possible)
		if (this.cachedReadAccessor != null && 
				(this.cachedReadAccessor instanceof ReflectivePropertyAccessor.OptimalPropertyAccessor) &&
				(getChild(0) instanceof StringLiteral)) {
			return true;
		}
	}
	return false;
}
 
Example 5
Source Project: spring-analysis-note   Source File: SpelReproTests.java    License: MIT License 5 votes vote down vote up
@Test
public void SPR9994_bridgeMethods() throws Exception {
	ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor();
	StandardEvaluationContext context = new StandardEvaluationContext();
	Object target = new GenericImplementation();
	TypedValue value = accessor.read(context, target, "property");
	assertEquals(Integer.class, value.getTypeDescriptor().getType());
}
 
Example 6
Source Project: spring-analysis-note   Source File: SpelReproTests.java    License: MIT License 5 votes vote down vote up
@Test
public void SPR10162_onlyBridgeMethod() throws Exception {
	ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor();
	StandardEvaluationContext context = new StandardEvaluationContext();
	Object target = new OnlyBridgeMethod();
	TypedValue value = accessor.read(context, target, "property");
	assertEquals(Integer.class, value.getTypeDescriptor().getType());
}
 
Example 7
Source Project: java-technology-stack   Source File: SpelReproTests.java    License: MIT License 5 votes vote down vote up
@Test
public void SPR9994_bridgeMethods() throws Exception {
	ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor();
	StandardEvaluationContext context = new StandardEvaluationContext();
	Object target = new GenericImplementation();
	TypedValue value = accessor.read(context, target, "property");
	assertEquals(Integer.class, value.getTypeDescriptor().getType());
}
 
Example 8
Source Project: java-technology-stack   Source File: SpelReproTests.java    License: MIT License 5 votes vote down vote up
@Test
public void SPR10162_onlyBridgeMethod() throws Exception {
	ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor();
	StandardEvaluationContext context = new StandardEvaluationContext();
	Object target = new OnlyBridgeMethod();
	TypedValue value = accessor.read(context, target, "property");
	assertEquals(Integer.class, value.getTypeDescriptor().getType());
}
 
Example 9
Source Project: spring4-understanding   Source File: SpelReproTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void SPR9994_bridgeMethods() throws Exception {
	ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor();
	StandardEvaluationContext context = new StandardEvaluationContext();
	Object target = new GenericImplementation();
	TypedValue value = accessor.read(context, target, "property");
	assertEquals(Integer.class, value.getTypeDescriptor().getType());
}
 
Example 10
Source Project: spring4-understanding   Source File: SpelReproTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void SPR10162_onlyBridgeMethod() throws Exception {
	ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor();
	StandardEvaluationContext context = new StandardEvaluationContext();
	Object target = new OnlyBridgeMethod();
	TypedValue value = accessor.read(context, target, "property");
	assertEquals(Integer.class, value.getTypeDescriptor().getType());
}
 
Example 11
Source Project: lams   Source File: Indexer.java    License: GNU General Public License v2.0 4 votes vote down vote up
@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;
					if (accessor instanceof ReflectivePropertyAccessor.OptimalPropertyAccessor) {
						ReflectivePropertyAccessor.OptimalPropertyAccessor optimalAccessor =
								(ReflectivePropertyAccessor.OptimalPropertyAccessor) accessor;
						Member member = optimalAccessor.member;
						Indexer.this.exitTypeDescriptor = CodeFlow.toDescriptor(member instanceof Method ?
								((Method) member).getReturnType() : ((Field) member).getType());
					}
					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());
}
 
Example 12
Source Project: spring4-understanding   Source File: Indexer.java    License: Apache License 2.0 4 votes vote down vote up
@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;
					if (accessor instanceof ReflectivePropertyAccessor.OptimalPropertyAccessor) {
						ReflectivePropertyAccessor.OptimalPropertyAccessor optimalAccessor =
								(ReflectivePropertyAccessor.OptimalPropertyAccessor) accessor;
						Member member = optimalAccessor.member;
						Indexer.this.exitTypeDescriptor = CodeFlow.toDescriptor(member instanceof Method ?
								((Method) member).getReturnType() : ((Field) member).getType());
					}
					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());
}