Package net.sf.lapg.templates.api

Examples of net.sf.lapg.templates.api.EvaluationException


    if (kind == MINUS) {
      Object value = env.evaluate(expr, context, false);
      if (value instanceof Integer) {
        return -((Integer) value).intValue();
      } else {
        throw new EvaluationException("unary minus expression should be Integer");
      }
    }

    throw new EvaluationException("internal error: unknown kind");
  }
View Full Code Here


    Object select = env.evaluate(selectExpression, context, false);
    Object prevVar = context.getVariable(varName);
    try {
      Iterator<?> it = env.getCollectionIterator(select);
      if(it == null) {
        throw new EvaluationException("`" + selectExpression.toString() + "` should be array or collection (instead of "+select.getClass().getCanonicalName()+")");
      }

      if(instruction == SELECT || instruction == REJECT || instruction == COLLECT || instruction == COLLECTUNIQUE) {
        Collection<Object> result = instruction == COLLECTUNIQUE ? new LinkedHashSet<Object>() : new ArrayList<Object>();
        while(it.hasNext()) {
          Object curr = it.next();
          context.setVariable(varName, curr);
          Object val = env.evaluate(foreachExpr, context, instruction == COLLECT || instruction == COLLECTUNIQUE);
          if(instruction != COLLECT && instruction != COLLECTUNIQUE) {
            boolean b = env.toBoolean(val) ^ (instruction == REJECT);
            if(b) {
              result.add(curr);
            }
          } else if(val instanceof Collection<?>) {
            for(Object v : (Collection<?>) val) {
              if(v!=null) {
                result.add(v);
              }
            }
          } else if(val instanceof Object[]) {
            for(Object v : (Object[])val) {
              if(v!=null) {
                result.add(v);
              }
            }
          } else if(val != null){
            result.add(val);
          }
        }
        return instruction == COLLECTUNIQUE ? new ArrayList<Object>(result) : result;
      } else if(instruction == SORT) {
        List<Object> result = new ArrayList<Object>();
        final Map<Object, Comparable<Object>> sortKey = new HashMap<Object, Comparable<Object>>();
        while(it.hasNext()) {
          Object curr = it.next();
          context.setVariable(varName, curr);
          Object val = env.evaluate(foreachExpr, context, false);
          if(!(val instanceof Comparable<?>)) {
            throw new EvaluationException("`" + foreachExpr.toString() + "` should implement Comparable (instead of "+val.getClass().getCanonicalName()+")");
          }
          sortKey.put(curr, (Comparable<Object>)val);
          result.add(curr);
        }
        Object[] arr = result.toArray();
View Full Code Here

      throws EvaluationException {
    int paramCount = parameters != null ? parameters.length : 0, argsCount = arguments != null ? arguments.length
        : 0;

    if (paramCount != argsCount) {
      throw new EvaluationException("Wrong number of arguments used while calling `" + toString()
          + "`: should be " + paramCount + " instead of " + argsCount);
    }

    Object result;
    if (isCached) {
View Full Code Here

        return l >= r;
      case GT:
        return l > r;
      }
    } else {
      throw new EvaluationException("relational arguments should be integer");
    }

    throw new EvaluationException("internal error: unknown kind");
  }
View Full Code Here

  public String apply(EvaluationContext context, IEvaluationStrategy env, Object[] arguments) throws EvaluationException {
    int paramCount = parameters != null ? parameters.length : 0, argsCount = arguments != null ? arguments.length
        : 0;

    if (paramCount != argsCount) {
      throw new EvaluationException("Wrong number of arguments used while calling `" + toString()
          + "`: should be " + paramCount + " instead of " + argsCount);
    }

    StringBuffer sb = new StringBuffer();
    if (paramCount > 0) {
View Full Code Here

      if( left instanceof Object[] && right instanceof Object[] ) {
        return concatenate((Object[])left,(Object[])right);
      } else if( left instanceof String || right instanceof String ) {
        return left.toString() + right.toString();
      } else {
        throw new EvaluationException("arguments of plus should be arrays, strings or integers ("+left.getClass().getCanonicalName() + " + "+right.getClass().getCanonicalName()+")");
      }

    } else {
      throw new EvaluationException("arithmetic arguments should be integer");
    }

    return null;
  }
View Full Code Here

    super(input, line);
  }

  @Override
  public Object evaluate(EvaluationContext context, IEvaluationStrategy env) throws EvaluationException {
    throw new EvaluationException("illegal expression");
  }
View Full Code Here

  }

  public String toString(Object o, ExpressionNode referer) throws EvaluationException {
    if( o instanceof Collection<?> || o instanceof Object[] ) {
      String message = "Evaluation of `"+referer.toString()+"` results in collection, cannot convert to String";
      EvaluationException ex = new HandledEvaluationException(message);
      fireError(referer, message);
      throw ex;
    }
    return o.toString();
  }
View Full Code Here

  public Object evaluate(ExpressionNode expr, EvaluationContext context, boolean permitNull) throws EvaluationException {
    try {
      Object result = expr.evaluate(context, this);
      if( result == null && !permitNull ) {
        String message = "Evaluation of `"+expr.toString()+"` failed for " + getTitle(context.getThisObject()) + ": null";
        EvaluationException ex = new HandledEvaluationException(message);
        fireError(expr, message);
        throw ex;
      }
      return result;
    } catch( HandledEvaluationException ex ) {
      throw ex;
    } catch( Throwable th ) {
      Throwable cause = th.getCause() != null ? th.getCause() : th;
      String message = "Evaluation of `"+expr.toString()+"` failed for " + getTitle(context.getThisObject()) + ": " + cause.getMessage();
      EvaluationException ex = new HandledEvaluationException(message);
      fireError(expr, message);
      throw ex;
    }
  }
View Full Code Here

    Object select = env.evaluate(selectExpression, context, false);
    Object prevVar = context.getVariable(varName);
    try {
      Iterator<?> it = env.getCollectionIterator(select);
      if(it == null) {
        throw new EvaluationException("`" + selectExpression.toString() + "` should be array or collection (instead of "+select.getClass().getCanonicalName()+")");
      }

      Map<Object,Object> result = new HashMap<Object,Object>();
      while(it.hasNext()) {
        Object curr = it.next();
View Full Code Here

TOP

Related Classes of net.sf.lapg.templates.api.EvaluationException

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.