@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 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 testRootContextObject() { ExpressionState state = getState(); assertEquals(Inventor.class, state.getRootContextObject().getValue().getClass()); // although the root object is being set on the evaluation context, the value in the 'state' remains what it was when constructed ((StandardEvaluationContext) state.getEvaluationContext()).setRootObject(null); assertEquals(Inventor.class, state.getRootContextObject().getValue().getClass()); // assertEquals(null, state.getRootContextObject().getValue()); state = new ExpressionState(new StandardEvaluationContext()); assertEquals(TypedValue.NULL, state.getRootContextObject()); ((StandardEvaluationContext) state.getEvaluationContext()).setRootObject(null); assertEquals(null, state.getRootContextObject().getValue()); }
state.pushActiveContextObject(state.getRootContextObject()); indexValue = this.children[0].getValueInternal(state); index = indexValue.getValue();
@Test public void testRootObjectConstructor() { EvaluationContext ctx = getContext(); // TypedValue root = ctx.getRootObject(); // supplied should override root on context ExpressionState state = new ExpressionState(ctx,new TypedValue("i am a string")); TypedValue stateRoot = state.getRootContextObject(); assertEquals(String.class, stateRoot.getTypeDescriptor().getType()); assertEquals("i am a string", stateRoot.getValue()); }
state.pushActiveContextObject(state.getRootContextObject()); indexValue = this.children[0].getValueInternal(state); index = indexValue.getValue();
@Test public void testActiveContextObject() { ExpressionState state = getState(); assertEquals(state.getRootContextObject().getValue(), state.getActiveContextObject().getValue()); try { state.popActiveContextObject(); fail("stack should be empty..."); } catch (IllegalStateException ese) { // success } state.pushActiveContextObject(new TypedValue(34)); assertEquals(34, state.getActiveContextObject().getValue()); state.pushActiveContextObject(new TypedValue("hello")); assertEquals("hello", state.getActiveContextObject().getValue()); state.popActiveContextObject(); assertEquals(34, state.getActiveContextObject().getValue()); state.popActiveContextObject(); assertEquals(state.getRootContextObject().getValue(), state.getActiveContextObject().getValue()); state = new ExpressionState(new StandardEvaluationContext()); assertEquals(TypedValue.NULL, state.getActiveContextObject()); }
@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; }
state.pushActiveContextObject(state.getRootContextObject()); indexValue = this.children[0].getValueInternal(state); index = indexValue.getValue();