Package org.springframework.expression

Examples of org.springframework.expression.TypedValue


            // AST tree on a different class (Spring internally caches property accessors).
            // So this exception might be considered "normal" by Spring AST evaluator and
            // just use it to refresh the property accessor cache.
            throw new AccessException("Cannot read target of class " + target.getClass().getName());
        }
        return new TypedValue(((Beans)target).get(name));
    }
View Full Code Here


      this.typeDescriptor = typeDescriptor;
    }

    public TypedValue getValue() {
      Object arrayElement = accessArrayElement(this.array, this.idx);
      return new TypedValue(arrayElement, this.typeDescriptor.elementTypeDescriptor(arrayElement));
    }
View Full Code Here

      this.mapEntryTypeDescriptor = mapEntryTypeDescriptor;
    }

    public TypedValue getValue() {
      Object value = this.map.get(this.key);
      return new TypedValue(value, this.mapEntryTypeDescriptor.getMapValueTypeDescriptor(value));
    }
View Full Code Here

              this.collection.size(), this.index);
        }
      }
      if (this.collection instanceof List) {
        Object o = ((List) this.collection).get(this.index);
        return new TypedValue(o, this.collectionEntryTypeDescriptor.elementTypeDescriptor(o));
      }
      int pos = 0;
      for (Object o : this.collection) {
        if (pos == this.index) {
          return new TypedValue(o, this.collectionEntryTypeDescriptor.elementTypeDescriptor(o));
        }
        pos++;
      }
      throw new IllegalStateException("Failed to find indexed element " + this.index + ": " + this.collection);
    }
View Full Code Here

    public TypedValue getValue() {
      if (this.index >= this.target.length()) {
        throw new SpelEvaluationException(getStartPosition(), SpelMessage.STRING_INDEX_OUT_OF_BOUNDS,
            this.target.length(), index);
      }
      return new TypedValue(String.valueOf(this.target.charAt(this.index)));
    }
View Full Code Here

   * @throws EvaluationException if the condition does not evaluate correctly to a boolean or there is a problem
   * executing the chosen alternative
   */
  @Override
  public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
    TypedValue value = children[0].getValueInternal(state);
    if (value.getValue()!=null && !((value.getValue() instanceof String) && ((String)value.getValue()).length()==0)) {
      return value;
    } else {
      return children[1].getValueInternal(state);
    }
  }
View Full Code Here

    // The operand is going to be read and then assigned to, we don't want to evaluate it twice.

    ValueRef lvalue = operand.getValueRef(state);

    final TypedValue operandTypedValue = lvalue.getValue();//operand.getValueInternal(state);
    final Object operandValue = operandTypedValue.getValue();
    TypedValue returnValue = operandTypedValue;
    TypedValue newValue = null;

    if (operandValue instanceof Number) {
      Number op1 = (Number) operandValue;
      if (op1 instanceof Double) {
        newValue = new TypedValue(op1.doubleValue() - 1.0d, operandTypedValue.getTypeDescriptor());
      } else if (op1 instanceof Float) {
        newValue = new TypedValue(op1.floatValue() - 1.0f, operandTypedValue.getTypeDescriptor());
      } else if (op1 instanceof Long) {
        newValue = new TypedValue(op1.longValue() - 1L, operandTypedValue.getTypeDescriptor());
      } else if (op1 instanceof Short) {
        newValue = new TypedValue(op1.shortValue() - (short)1, operandTypedValue.getTypeDescriptor());
      } else {
        newValue = new TypedValue(op1.intValue() - 1, operandTypedValue.getTypeDescriptor());
      }
    }
    if (newValue==null) {
      try {
        newValue = state.operate(Operation.SUBTRACT, returnValue.getValue(), 1);
      } catch (SpelEvaluationException see) {
        if (see.getMessageCode()==SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES) {
          // This means the operand is not decrementable
          throw new SpelEvaluationException(operand.getStartPosition(),SpelMessage.OPERAND_NOT_DECREMENTABLE,operand.toStringAST());
        } else {
          throw see;
        }
      }
    }

    // set the new value
    try {
      lvalue.setValue(newValue.getValue());
    } catch (SpelEvaluationException see) {
      // if unable to set the value the operand is not writable (e.g. 1-- )
      if (see.getMessageCode()==SpelMessage.SETVALUE_NOT_SUPPORTED) {
        throw new SpelEvaluationException(operand.getStartPosition(),SpelMessage.OPERAND_NOT_DECREMENTABLE);
      } else {
View Full Code Here

  public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
    SpelNodeImpl operand = getLeftOperand();

    ValueRef lvalue = operand.getValueRef(state);

    final TypedValue operandTypedValue = lvalue.getValue();
    final Object operandValue = operandTypedValue.getValue();
    TypedValue returnValue = operandTypedValue;
    TypedValue newValue = null;

    if (operandValue instanceof Number) {
      Number op1 = (Number) operandValue;
      if (op1 instanceof Double) {
        newValue = new TypedValue(op1.doubleValue() + 1.0d, operandTypedValue.getTypeDescriptor());
      } else if (op1 instanceof Float) {
        newValue = new TypedValue(op1.floatValue() + 1.0f, operandTypedValue.getTypeDescriptor());
      } else if (op1 instanceof Long) {
        newValue = new TypedValue(op1.longValue() + 1L, operandTypedValue.getTypeDescriptor());
      } else if (op1 instanceof Short) {
        newValue = new TypedValue(op1.shortValue() + (short)1, operandTypedValue.getTypeDescriptor());
      } else {
        newValue = new TypedValue(op1.intValue() + 1, operandTypedValue.getTypeDescriptor());
      }
    }
    if (newValue==null) {
      try {
        newValue = state.operate(Operation.ADD, returnValue.getValue(), 1);
      } catch (SpelEvaluationException see) {
        if (see.getMessageCode()==SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES) {
          // This means the operand is not incrementable
          throw new SpelEvaluationException(operand.getStartPosition(),SpelMessage.OPERAND_NOT_INCREMENTABLE,operand.toStringAST());
        } else {
          throw see;
        }
      }
    }

    // set the name value
    try {
      lvalue.setValue(newValue.getValue());
    } catch (SpelEvaluationException see) {
      // if unable to set the value the operand is not writable (e.g. 1++ )
      if (see.getMessageCode()==SpelMessage.SETVALUE_NOT_SUPPORTED) {
        throw new SpelEvaluationException(operand.getStartPosition(),SpelMessage.OPERAND_NOT_INCREMENTABLE);
      } else {
View Full Code Here

    return getValueInternal(state.getActiveContextObject(), state.getEvaluationContext(), state.getConfiguration().isAutoGrowNullReferences());
  }

  private TypedValue getValueInternal(TypedValue contextObject, EvaluationContext eContext, boolean isAutoGrowNullReferences) throws EvaluationException {

    TypedValue result = readProperty(contextObject, eContext, this.name);

    // Dynamically create the objects if the user has requested that optional behavior
    if (result.getValue() == null && isAutoGrowNullReferences &&
        nextChildIs(Indexer.class, PropertyOrFieldReference.class)) {
      TypeDescriptor resultDescriptor = result.getTypeDescriptor();
      // Creating lists and maps
      if ((resultDescriptor.getType().equals(List.class) || resultDescriptor.getType().equals(Map.class))) {
        // Create a new collection or map ready for the indexer
        if (resultDescriptor.getType().equals(List.class)) {
          try {
            if (isWritableProperty(this.name,contextObject,eContext)) {
              List<?> newList = ArrayList.class.newInstance();
              writeProperty(contextObject, eContext, this.name, newList);
              result = readProperty(contextObject, eContext, this.name);
            }
          }
          catch (InstantiationException ex) {
            throw new SpelEvaluationException(getStartPosition(), ex,
                SpelMessage.UNABLE_TO_CREATE_LIST_FOR_INDEXING);
          }
          catch (IllegalAccessException ex) {
            throw new SpelEvaluationException(getStartPosition(), ex,
                SpelMessage.UNABLE_TO_CREATE_LIST_FOR_INDEXING);
          }
        }
        else {
          try {
            if (isWritableProperty(this.name,contextObject,eContext)) {
              Map<?,?> newMap = HashMap.class.newInstance();
              writeProperty(contextObject, eContext, name, newMap);
              result = readProperty(contextObject, eContext, this.name);
            }
          }
          catch (InstantiationException ex) {
            throw new SpelEvaluationException(getStartPosition(), ex,
                SpelMessage.UNABLE_TO_CREATE_MAP_FOR_INDEXING);
          }
          catch (IllegalAccessException ex) {
            throw new SpelEvaluationException(getStartPosition(), ex,
                SpelMessage.UNABLE_TO_CREATE_MAP_FOR_INDEXING);
          }
        }
      }
      else {
        // 'simple' object
        try {
          if (isWritableProperty(this.name,contextObject,eContext)) {
            Object newObject  = result.getTypeDescriptor().getType().newInstance();
            writeProperty(contextObject, eContext, name, newObject);
            result = readProperty(contextObject, eContext, this.name);
          }
        }
        catch (InstantiationException ex) {
          throw new SpelEvaluationException(getStartPosition(), ex,
              SpelMessage.UNABLE_TO_DYNAMICALLY_CREATE_OBJECT, result.getTypeDescriptor().getType());
        }
        catch (IllegalAccessException ex) {
          throw new SpelEvaluationException(getStartPosition(), ex,
              SpelMessage.UNABLE_TO_DYNAMICALLY_CREATE_OBJECT, result.getTypeDescriptor().getType());
        }       
      }
    }
    return result;
  }
View Full Code Here

      TypeCode tc = TypeCode.valueOf(typename.toUpperCase());
      if (tc != TypeCode.OBJECT) {
        // it is a primitive type
        Class<?> clazz = tc.getType();
        clazz = makeArrayIfNecessary(clazz);
        return new TypedValue(clazz);
      }
    }
    Class<?> clazz = state.findType(typename);
    clazz = makeArrayIfNecessary(clazz);
    return new TypedValue(clazz);
  }
View Full Code Here

TOP

Related Classes of org.springframework.expression.TypedValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.