Package org.springframework.expression.spel

Examples of org.springframework.expression.spel.SpelEvaluationException


      Function function = (Function) value;

      try {
        return new TypedValue(function.invoke(new Object[0]));
      } catch (Exception e) {
        throw new SpelEvaluationException(e, SpelMessage.FUNCTION_REFERENCE_CANNOT_BE_INVOKED, name,
            function.getDeclaringClass());
      }
    }
View Full Code Here


    public TypedValue execute(EvaluationContext context, Object target, Object... arguments) throws AccessException {

      try {
        return new TypedValue(function.invoke(arguments));
      } catch (Exception e) {
        throw new SpelEvaluationException(e, SpelMessage.FUNCTION_REFERENCE_CANNOT_BE_INVOKED, function.getName(),
            function.getDeclaringClass());
      }
    }
View Full Code Here

      return new MapIndexingValueRef(state.getTypeConverter(), (Map<?, ?>) targetObject, key,
          targetObjectTypeDescriptor);
    }

    if (targetObject == null) {
      throw new SpelEvaluationException(getStartPosition(), SpelMessage.CANNOT_INDEX_INTO_NULL_VALUE);
    }

    // if the object is something that looks indexable by an integer,
    // attempt to treat the index value as a number
    if (targetObject.getClass().isArray() || targetObject instanceof Collection || targetObject instanceof String) {
      int idx = (Integer) state.convertValue(index, TypeDescriptor.valueOf(Integer.class));
      if (targetObject.getClass().isArray()) {
        return new ArrayIndexingValueRef(state.getTypeConverter(), targetObject, idx, targetObjectTypeDescriptor);
      }
      else if (targetObject instanceof Collection) {
        return new CollectionIndexingValueRef((Collection<?>) targetObject, idx, targetObjectTypeDescriptor,
            state.getTypeConverter(), state.getConfiguration().isAutoGrowCollections());
      }
      else if (targetObject instanceof String) {
        return new StringIndexingLValue((String) targetObject, idx, targetObjectTypeDescriptor);
      }
    }

    // Try and treat the index value as a property of the context object
    // TODO could call the conversion service to convert the value to a String
    if (indexValue.getTypeDescriptor().getType() == String.class) {
      return new PropertyIndexingValueRef(targetObject, (String) indexValue.getValue(),
          state.getEvaluationContext(), targetObjectTypeDescriptor);
    }

    throw new SpelEvaluationException(getStartPosition(), SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE,
        targetObjectTypeDescriptor.toString());
  }
View Full Code Here

   * @param index the index into the collection that needs to be valid
   * @param collection the collection to grow with elements
   */
  private void growCollection(TypeDescriptor targetType, int index, Collection<Object> collection) {
    if (targetType.getElementTypeDescriptor() == null) {
      throw new SpelEvaluationException(getStartPosition(), SpelMessage.UNABLE_TO_GROW_COLLECTION_UNKNOWN_ELEMENT_TYPE);
    }
    TypeDescriptor elementType = targetType.getElementTypeDescriptor();
    Object newCollectionElement;
    try {
      int newElements = index - collection.size();
      while (newElements > 0) {
        collection.add(elementType.getType().newInstance());
        newElements--;
      }
      newCollectionElement = elementType.getType().newInstance();
    }
    catch (Exception ex) {
      throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.UNABLE_TO_GROW_COLLECTION);
    }
    collection.add(newCollectionElement);
  }
View Full Code Here

    }
  }

  private void checkAccess(int arrayLength, int index) throws SpelEvaluationException {
    if (index > arrayLength) {
      throw new SpelEvaluationException(getStartPosition(), SpelMessage.ARRAY_INDEX_OUT_OF_BOUNDS,
          arrayLength, index);
    }
  }
View Full Code Here

            }
          }
        }
      }
      catch (AccessException ex) {
        throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE,
            this.td.toString());
      }
      throw new SpelEvaluationException(getStartPosition(), SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE,
          this.td.toString());
    }
View Full Code Here

            }
          }
        }
      }
      catch (AccessException ex) {
        throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_PROPERTY_WRITE,
            this.name, ex.getMessage());
      }
    }
View Full Code Here

      if (this.index >= this.collection.size()) {
        if (this.growCollection) {
          growCollection(this.collectionEntryTypeDescriptor, this.index, this.collection);
        }
        else {
          throw new SpelEvaluationException(getStartPosition(), SpelMessage.COLLECTION_INDEX_OUT_OF_BOUNDS,
              this.collection.size(), this.index);
        }
      }
      if (this.collection instanceof List) {
        Object o = ((List) this.collection).get(this.index);
View Full Code Here

      if (this.index >= this.collection.size()) {
        if (this.growCollection) {
          growCollection(this.collectionEntryTypeDescriptor, this.index, this.collection);
        }
        else {
          throw new SpelEvaluationException(getStartPosition(), SpelMessage.COLLECTION_INDEX_OUT_OF_BOUNDS,
              this.collection.size(), this.index);
        }
      }
      if (this.collection instanceof List) {
        List list = (List) this.collection;
        if (this.collectionEntryTypeDescriptor.getElementTypeDescriptor() != null) {
          newValue = this.typeConverter.convertValue(newValue, TypeDescriptor.forObject(newValue),
              this.collectionEntryTypeDescriptor.getElementTypeDescriptor());
        }
        list.set(this.index, newValue);
      }
      else {
        throw new SpelEvaluationException(getStartPosition(), SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE,
            this.collectionEntryTypeDescriptor.toString());
      }
    }
View Full Code Here

      this.td = td;
    }

    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

TOP

Related Classes of org.springframework.expression.spel.SpelEvaluationException

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.