コード例 #1
0
ファイル: XPathParser.java プロジェクト: Buzov/jlibs-1
 @Override
 public void endUnaryExpr(int operator) {
   FunctionCall functionCall = new FunctionCall(Functions.MULTIPLY);
   functionCall.addValidMember(new Literal(-1d, DataType.NUMBER), 0);
   functionCall.addMember(pop(), 1);
   push(functionCall.simplify());
 }
コード例 #2
0
ファイル: XPathParser.java プロジェクト: Buzov/jlibs-1
 private void endBinaryOperator(Function function) {
   FunctionCall functionCall = new FunctionCall(function);
   Object member2 = pop();
   Object member1 = pop();
   functionCall.addMember(member1, 0);
   functionCall.addMember(member2, 1);
   push(functionCall.simplify());
 }
コード例 #3
0
ファイル: XPathParser.java プロジェクト: Buzov/jlibs-1
  @Override
  public void endPredicate() {
    predicateDepth--;
    Object predicate = pop();
    Predicated predicated = (Predicated) peek();

    Expression predicateExpr;
    if (predicate instanceof Expression) {
      predicateExpr = (Expression) predicate;
      if (predicateExpr.resultType == DataType.NUMBER) {
        if (predicate instanceof Literal) {
          Double d = (Double) predicateExpr.getResult();
          int pos = d.intValue();
          if (d != pos) predicateExpr = new Literal(Boolean.FALSE, DataType.BOOLEAN);
          else {
            Step step = predicated instanceof Step ? (Step) predicated : null;
            if (step != null
                && (step.axis == Axis.SELF
                    || ((step.axis == Axis.ATTRIBUTE || step.axis == Axis.NAMESPACE)
                        && step.constraint instanceof QName)
                    || step.predicateSet.getPredicate() instanceof ExactPosition))
              predicateExpr = new Literal(pos == 1, DataType.BOOLEAN);
            else predicateExpr = new ExactPosition(pos);
          }
        } else {
          FunctionCall equals = new FunctionCall(Functions.NUMBER_EQUALS_NUMBER);
          equals.addValidMember(new Position(), 0);
          equals.addValidMember(predicateExpr, 1);
          predicateExpr = equals;
        }
      } else predicateExpr = Functions.typeCast(predicateExpr, DataType.BOOLEAN);
    } else predicateExpr = Functions.typeCast(predicate, DataType.BOOLEAN);

    if (predicated instanceof LocationPath) {
      LocationPath path = (LocationPath) predicated;
      if (path.contexts.size() == 0) {
        LocationPath newPath = new LocationPath(Scope.LOCAL, 0);
        newPath.contexts.add(path);
        pop();
        push(newPath);
        predicated = newPath;
      }
    }
    predicated.addPredicate(predicateExpr);
  }
コード例 #4
0
ファイル: XPathParser.java プロジェクト: Buzov/jlibs-1
 @Override
 public void endFunction() throws SAXPathException {
   ArrayDeque params = popFrame();
   javax.xml.namespace.QName name = (javax.xml.namespace.QName) params.pollFirst();
   if (name.getNamespaceURI().length() == 0)
     push(createFunction(name.getLocalPart(), params).simplify());
   else {
     int noOfParams = params.size();
     XPathFunction function = functionResolver.resolveFunction(name, noOfParams);
     if (function == null) throw new SAXPathException("Unknown Function: " + name);
     FunctionCall functionCall =
         new FunctionCall(
             new Functions.UserFunction(name.getNamespaceURI(), name.getLocalPart(), function),
             noOfParams);
     for (int i = 0; i < noOfParams; i++) functionCall.addMember(params.pollFirst(), i);
     push(functionCall);
   }
 }
コード例 #5
0
ファイル: XPathParser.java プロジェクト: Buzov/jlibs-1
 private Expression createFunction(String name, ArrayDeque params) throws SAXPathException {
   int noOfParams = params.size();
   switch (noOfParams) {
     case 0:
       {
         LocationPath locationPath =
             predicateDepth == 0 ? LocationPath.DOCUMENT_CONTEXT : LocationPath.LOCAL_CONTEXT;
         Expression expr = locationPath.apply(name);
         if (expr != null) return expr;
         return createFunction(name, 0);
       }
     case 1:
       {
         if (name.equals("lang")) {
           langInterested = true;
           FunctionCall functionCall = new FunctionCall(Functions.LANGUAGE_MATCH);
           functionCall.addValidMember(new Language(), 0);
           functionCall.addMember(params.pollFirst(), 1);
           return functionCall;
         } else {
           Object current = params.pollFirst();
           if (current instanceof LocationPath) {
             Expression expr = ((LocationPath) current).apply(name);
             if (expr != null) return expr;
           }
           FunctionCall functionCall = (FunctionCall) createFunction(name, 1);
           functionCall.addMember(current, 0);
           return functionCall;
         }
       }
     default:
       FunctionCall functionCall = (FunctionCall) createFunction(name, noOfParams);
       for (int i = 0; i < noOfParams; i++) functionCall.addMember(params.pollFirst(), i);
       return functionCall;
   }
 }