@Override public TypedValue getValueInternal(ExpressionState state) throws SpelEvaluationException { if (this.name.equals(THIS)) { return state.getActiveContextObject(); } if (this.name.equals(ROOT)) { TypedValue result = state.getRootContextObject(); this.exitTypeDescriptor = CodeFlow.toDescriptorFromObject(result.getValue()); return result; } TypedValue result = state.lookupVariable(this.name); Object value = result.getValue(); if (value == null || !Modifier.isPublic(value.getClass().getModifiers())) { // If the type is not public then when generateCode produces a checkcast to it // then an IllegalAccessError will occur. // If resorting to Object isn't sufficient, the hierarchy could be traversed for // the first public type. this.exitTypeDescriptor = "Ljava/lang/Object"; } else { this.exitTypeDescriptor = CodeFlow.toDescriptorFromObject(value); } // a null value will mean either the value was null or the variable was not found return result; }
@Override public ValueRef getValueRef(ExpressionState state) throws SpelEvaluationException { if (this.name.equals(THIS)) { return new ValueRef.TypedValueHolderValueRef(state.getActiveContextObject(),this); } if (this.name.equals(ROOT)) { return new ValueRef.TypedValueHolderValueRef(state.getRootContextObject(),this); } TypedValue result = state.lookupVariable(this.name); // a null value will mean either the value was null or the variable was not found return new VariableRef(this.name,result,state.getEvaluationContext()); }
@Override public ValueRef getValueRef(ExpressionState state) throws SpelEvaluationException { if (this.name.equals(THIS)) { return new ValueRef.TypedValueHolderValueRef(state.getActiveContextObject(),this); } if (this.name.equals(ROOT)) { return new ValueRef.TypedValueHolderValueRef(state.getRootContextObject(),this); } TypedValue result = state.lookupVariable(this.name); // a null value will mean either the value was null or the variable was not found return new VariableRef(this.name,result,state.getEvaluationContext()); }
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { TypedValue value = state.lookupVariable(this.name); if (value == TypedValue.NULL) { throw new SpelEvaluationException(getStartPosition(), SpelMessage.FUNCTION_NOT_DEFINED, this.name); } if (!(value.getValue() instanceof Method)) { // Possibly a static Java method registered as a function throw new SpelEvaluationException( SpelMessage.FUNCTION_REFERENCE_CANNOT_BE_INVOKED, this.name, value.getClass()); } try { return executeFunctionJLRMethod(state, (Method) value.getValue()); } catch (SpelEvaluationException ex) { ex.setPosition(getStartPosition()); throw ex; } }
@Override public TypedValue getValueInternal(ExpressionState state) throws SpelEvaluationException { if (this.name.equals(THIS)) { return state.getActiveContextObject(); } if (this.name.equals(ROOT)) { TypedValue result = state.getRootContextObject(); this.exitTypeDescriptor = CodeFlow.toDescriptorFromObject(result.getValue()); return result; } TypedValue result = state.lookupVariable(this.name); Object value = result.getValue(); if (value == null || !Modifier.isPublic(value.getClass().getModifiers())) { // If the type is not public then when generateCode produces a checkcast to it // then an IllegalAccessError will occur. // If resorting to Object isn't sufficient, the hierarchy could be traversed for // the first public type. this.exitTypeDescriptor = "Ljava/lang/Object"; } else { this.exitTypeDescriptor = CodeFlow.toDescriptorFromObject(value); } // a null value will mean either the value was null or the variable was not found return result; }
@Test public void testNoVariableInterference() { ExpressionState state = getState(); TypedValue typedValue = state.lookupVariable("foo"); assertEquals(TypedValue.NULL, typedValue); state.setLocalVariable("foo",34); typedValue = state.lookupVariable("foo"); assertEquals(TypedValue.NULL, typedValue); state.setVariable("goo", "hello"); assertNull(state.lookupLocalVariable("goo")); }
@Test public void testVariables() { ExpressionState state = getState(); TypedValue typedValue = state.lookupVariable("foo"); assertEquals(TypedValue.NULL, typedValue); state.setVariable("foo",34); typedValue = state.lookupVariable("foo"); assertEquals(34, typedValue.getValue()); assertEquals(Integer.class, typedValue.getTypeDescriptor().getType()); state.setVariable("foo","abc"); typedValue = state.lookupVariable("foo"); assertEquals("abc", typedValue.getValue()); assertEquals(String.class, typedValue.getTypeDescriptor().getType()); }
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { TypedValue value = state.lookupVariable(this.name); if (value == TypedValue.NULL) { throw new SpelEvaluationException(getStartPosition(), SpelMessage.FUNCTION_NOT_DEFINED, this.name); } if (!(value.getValue() instanceof Method)) { // Possibly a static Java method registered as a function throw new SpelEvaluationException( SpelMessage.FUNCTION_REFERENCE_CANNOT_BE_INVOKED, this.name, value.getClass()); } try { return executeFunctionJLRMethod(state, (Method) value.getValue()); } catch (SpelEvaluationException ex) { ex.setPosition(getStartPosition()); throw ex; } }
@Override public ValueRef getValueRef(ExpressionState state) throws SpelEvaluationException { if (this.name.equals(THIS)) { return new ValueRef.TypedValueHolderValueRef(state.getActiveContextObject(),this); } if (this.name.equals(ROOT)) { return new ValueRef.TypedValueHolderValueRef(state.getRootContextObject(),this); } TypedValue result = state.lookupVariable(this.name); // a null value will mean either the value was null or the variable was not found return new VariableRef(this.name,result,state.getEvaluationContext()); }
@Override public TypedValue getValueInternal(ExpressionState state) throws SpelEvaluationException { if (this.name.equals(THIS)) { return state.getActiveContextObject(); } if (this.name.equals(ROOT)) { TypedValue result = state.getRootContextObject(); this.exitTypeDescriptor = CodeFlow.toDescriptorFromObject(result.getValue()); return result; } TypedValue result = state.lookupVariable(this.name); Object value = result.getValue(); if (value == null || !Modifier.isPublic(value.getClass().getModifiers())) { // If the type is not public then when generateCode produces a checkcast to it // then an IllegalAccessError will occur. // If resorting to Object isn't sufficient, the hierarchy could be traversed for // the first public type. this.exitTypeDescriptor = "Ljava/lang/Object"; } else { this.exitTypeDescriptor = CodeFlow.toDescriptorFromObject(value); } // a null value will mean either the value was null or the variable was not found return result; }
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { TypedValue value = state.lookupVariable(this.name); if (value == TypedValue.NULL) { throw new SpelEvaluationException(getStartPosition(), SpelMessage.FUNCTION_NOT_DEFINED, this.name); } if (!(value.getValue() instanceof Method)) { // Possibly a static Java method registered as a function throw new SpelEvaluationException( SpelMessage.FUNCTION_REFERENCE_CANNOT_BE_INVOKED, this.name, value.getClass()); } try { return executeFunctionJLRMethod(state, (Method) value.getValue()); } catch (SpelEvaluationException ex) { ex.setPosition(getStartPosition()); throw ex; } }