Package org.objectweb.medor.expression.api

Examples of org.objectweb.medor.expression.api.Expression


    if (hasMethod) {
      stack.push(node.value);
    }
        visit((SimpleNode) node, data);
    if (hasMethod) {
      Expression e2 = (Expression) stack.pop();
      Expression e1 = (Expression) stack.pop();
      String methodName = (String) stack.pop();
      if (methodName.startsWith("null.")) {
        methodName = methodName.substring("null.".length());
      }
      stack.push(e1);
View Full Code Here


                                stack.push(child1);
                                if (debug) {
                                    logger.log(BasicLevel.DEBUG, "push(" + child1 + ")");
                                }
                            } else {
                                Expression ret = null;
                                switch (op) {
                                case SpeedoQLConstants.OR:
                                    ret = new ConditionalOr((Expression) child1, (Expression) child2);
                                    break;
                                case SpeedoQLConstants.AND:
View Full Code Here

        tab = tab.substring(1);
        Stack stack = (Stack) data;
        if (stack.size() > 0
                && !CONTAINS_PATH_SET.equals(stack.peek())
                && !REMOVER.equals(stack.peek())) {
            Expression ret = (Expression) stack.pop();
            for (int i = 0; i < node.jjtGetNumChildren() - 1; i++) {
                if (debug) {
                    logger.log(BasicLevel.DEBUG, "Visit ConditionalExpression... children...[" + i + "]");
                }
View Full Code Here

        return null;
    }

    public Object visit(ASTLiteral node, Object data) {
    Stack stack = (Stack) data;
    Expression e = null;
    if (node.value == null) {
      //special case for null: will be replaced later
      e = new DummyOperand();
    } else if (node.value instanceof Integer) {
            e = new BasicOperand(((Integer) node.value).intValue());
View Full Code Here

          stack.pop();
        Object oe = stack.pop();
                if (debug) {
                    logger.log(BasicLevel.DEBUG, "pop expression: " + oe);
                }
        Expression str = (Expression) oe;
        if (e instanceof BasicParameterOperand) {
            e = new StringComparatorParameterOperand((BasicParameterOperand) e, null, ".*");
        } else  if (e instanceof BasicOperand) {
          try {
            e = new BasicOperand(((BasicOperand) e).getString() + ".*");
          } catch (TypingException e1) {
            throw new JDOException(
              "Bad parameter type for the 'startsWith' method", e1);
          }
        }
        e = new Like(str, e);
        break;
      }
    case ENDS_WITH_OPERATOR:
      {
          stack.pop();
        Object oe = stack.pop();
                if (debug) {
                    logger.log(BasicLevel.DEBUG, "pop expression: " + oe);
                }
        Expression str = (Expression) oe;
        if (e instanceof BasicParameterOperand) {
            e = new StringComparatorParameterOperand((BasicParameterOperand) e, ".*", null);
        } else  if (e instanceof BasicOperand) {
          try {
            e = new BasicOperand("%" + ((BasicOperand) e).getString());
          } catch (TypingException e1) {
            throw new JDOException(
              "Bad parameter type for the 'startsWith' method", e1);
          }
        }
        e = new Like(str, e);
        break;
      }
    case EQUALS_OPERATOR:
//TODO: Support the equals operator
      break;
    case MATCHES_OPERATOR:
      {
          stack.pop();
        Object oe = stack.pop();
                if (debug) {
                    logger.log(BasicLevel.DEBUG, "pop expression: " + oe);
                }
        Expression str = (Expression) oe;
        if (e instanceof BasicParameterOperand) {
            //e = new StringComparatorParameterOperand((BasicParameterOperand) e, "%", "%");
        } else  if (e instanceof BasicOperand) {
          try {
            e = new BasicOperand(((BasicOperand) e).getString());
          } catch (TypingException e1) {
            throw new JDOException(
              "Bad parameter type for the 'startsWith' method", e1);
          }
        }
        e = new Like(str, e);
        break;
      }
    case SUBSTRING_OPERATOR:
      {
        stack.pop();
        Object o = stack.pop();
        if (o == STR_OPERAND_SUBSTRING) {
                    if (debug) {
                        logger.log(BasicLevel.DEBUG, "push(" + ExpressionPrinter.e2str(e) + ")");
                    }
          stack.push(e);
                    if (debug) {
                        logger.log(BasicLevel.DEBUG, "push(BEGIN_OPERAND_SUBSTRING)");
                    }
          stack.push(BEGIN_OPERAND_SUBSTRING);
                    if (debug) {
                        logger.log(BasicLevel.DEBUG, "push(" + opName + ")");
                    }
          stack.push(opName);
          return null;
        } else if (o == BEGIN_OPERAND_SUBSTRING) {
          Expression begin = (Expression) stack.pop();
          Expression str = (Expression) stack.pop();
          e = new Substring(str, begin, e);
        } else {
          throw new JDOException("Protocol error: " + o);
        }
        break;
View Full Code Here

            String[] spli = splitPath(pathset);
            String rest = mergePath(spli, 1, spli.length - 1);
            QueryBuilder subquery = new QueryBuilder(qb);
            subquery.define("", qb.navigate(spli[0]));
            QueryTreeField setField = subquery.project(subquery.navigate(rest));
            Expression e = new MemberOf(
                    Collections.singletonList(((Object[]) params.get(name))[1]),
                    Collections.singletonList(new BasicFieldOperand(setField)));
            if (debug) {
                logger.log(BasicLevel.DEBUG, tab + "push(" + ExpressionPrinter.e2str(e) + ")");
            }
            stack.push(e);
        } else if (splitted.length == 1) {
            if (debug) {
                logger.log(BasicLevel.DEBUG, tab + "Push the parameterOperand " + name);
            }
            Expression e = (Expression) ((Object[]) params.get(name))[1];
        if (stack.size() > 0 && stack.peek() instanceof String) {
            e = treatMethodOperator((String) stack.peek(), stack, e);
        }
            stack.push(e);
        } else if (splitted.length == 2 && "contains".equals(splitted[1])) {
View Full Code Here

                //myParam.contains(...)
                if (debug) {
                    logger.log(BasicLevel.DEBUG, tab + "(" +  name + ") InCollection (" + o + ")");
                }
                Field qtf =  (Field) fields.get(name);
                Expression e = new InCollection(
                        new BasicFieldOperand(qtf),
                        (ParameterOperand) o, qtf.getType());
                stack.push(e);
               
            } else if (o instanceof String) {
                String pathset = (String) o;
                String[] spli = splitPath(pathset);
                if (vars.containsKey(splitted[0])) {
                    //x.y.bs.contains(b)
                    //The variable definition is managed by the Variable visitor
                    //thus forget the expression
                    if ((nbNot % 2) == 0) {
                        stack.push(REMOVER);
                    } else {
                        QueryTreeField f = (QueryTreeField) fields.get(name);
                      stack.push(new Not(new IsEmpty(new BasicFieldOperand(f))));
                    }
                } else {
                    //x.y.bs.contains(u.v.b)
                    String rest = mergePath(spli, 1, spli.length - 2);
                    QueryBuilder subquery = new QueryBuilder(qb);
                    subquery.define("", qb.navigate(spli[0]));
                    QueryTreeField setField = subquery.project(subquery.navigate(rest));
                    QueryTreeField f = (QueryTreeField) fields.get(name);

                    stack.push(new MemberOf(
                            Collections.singletonList(
                                    new BasicFieldOperand(f)),
                            Collections.singletonList(
                                    new BasicFieldOperand(setField))
                          ));
                }
            } else {
                if (debug) {
                    logger.log(BasicLevel.DEBUG, tab + "Do not use the pathset of the contain operator");
                }
                stack.push(REMOVER);
            }
            return;
        }

        //maybe there is an operator
        String last = splitted[splitted.length - 1];
        operatorId = isMethodOperator(last);
        if (operatorId == -1) {
            //No operator found ==> default case
            if (debug) {
                logger.log(BasicLevel.DEBUG, tab + "create a fieldOperand with:" + name);
            }
        Field f = (Field) fields.get(name);
        if (f == null) {
            throw new SpeedoException("Internal error: No field '" + name + "' found during filter parsing");
        }
        stack.push(new BasicFieldOperand(f));
            return;
        }
        //There is an operator
        String begin = buildStringwithout(splitted, splitted.length-1, ".");
        if (operatorId == CONTAINS_OPERATOR) {
            //The contains contraint is managed during the QueryTree creation
        //see the variable vistor
          //However push some stuff in the stack in order to known that
          // the next qualifiedName is used in a contain constraint.
            if (debug) {
                logger.log(BasicLevel.DEBUG, tab + "contains operator: set=" + begin);
            }
            stack.push(begin);
            stack.push(CONTAINS_PATH_SET);
            return;
        } else if (operatorId == IS_EMPTY_OPERATOR) {
            if (debug) {
               logger.log(BasicLevel.DEBUG, tab + "Visit IsEmpty: " + begin);
            }
            String rest = mergePath(splitted, 1, splitted.length - 2);
            QueryBuilder subquery = new QueryBuilder(qb);
            subquery.define("", qb.navigate(splitted[0]));
            Field f = subquery.project(subquery.navigate(rest));
            stack.push(new IsEmpty(new BasicFieldOperand(f)));
            return;
        }
               
        if (debug) {
            logger.log(BasicLevel.DEBUG, tab + "create a fieldOperand with:" + begin);
        }
        Field f = (Field) fields.get(begin);
        Expression e = new BasicFieldOperand(f);
        switch (operatorId) {
        case TO_LOWER_OPERATOR:
            e = new StringLower(e);
            stack.push(e);
            break;
View Full Code Here

TOP

Related Classes of org.objectweb.medor.expression.api.Expression

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.