Package org.exist.dom

Examples of org.exist.dom.ContextItem


        final Collator collator = getCollator( contextSequence );

        if( ( contextSequence != null ) && !contextSequence.isEmpty() && !contextSequence.getDocumentSet().contains( nodes.getDocumentSet() ) ) {

            for( final NodeProxy item : nodes ) {
                ContextItem context = item.getContext();

                if( context == null ) {
                    throw( new XPathException( this, "Internal error: context node missing" ) );
                }
                final AtomicValue lv = item.atomize();

                do {
                    final Sequence rs = getRight().eval( context.getNode().toSequence() );

                    for( final SequenceIterator i2 = rs.iterate(); i2.hasNext(); ) {
                        final AtomicValue rv = i2.nextItem().atomize();

                        if( compareAtomic( collator, lv, rv ) ) {
                            result.add( item );
                        }
                    }
                } while( ( context = context.getNextDirect() ) != null );
            }
        } else {

            for( final NodeProxy item : nodes ) {
                final AtomicValue lv = item.atomize();
                final Sequence    rs = getRight().eval( contextSequence );

                for( final SequenceIterator i2 = rs.iterate(); i2.hasNext(); ) {
                    final AtomicValue rv = i2.nextItem().atomize();

                    if( compareAtomic( collator, lv, rv ) ) {
                        result.add( item );
                    }
                }
            }
        }

        if( context.getProfiler().traceFunctions() ) {
            context.getProfiler().traceIndexUsage( context, PerformanceStats.RANGE_IDX_TYPE, this, PerformanceStats.NO_INDEX, System.currentTimeMillis() - start );
        }
        return( result );
    }
View Full Code Here


    for(int i = 0; i < orderSpecs.length; i++) {
      final Expression expr = orderSpecs[i].getSortExpression();
      final NodeSet result = expr.eval(null).toNodeSet();
      for(final Iterator j = result.iterator(); j.hasNext(); ) {
        final NodeProxy p = (NodeProxy)j.next();
        ContextItem context = p.getContext();
        //TODO : review to consider transverse context
        while(context != null) {
          if(context.getNode() instanceof OrderedNodeProxy) {
            final OrderedNodeProxy cp = (OrderedNodeProxy)context.getNode();
            cp.values[i] = p.atomize();
          }
          context = context.getNextDirect();
        }
      }
    }
  }
View Full Code Here

    final NodeSet result = new ExtArrayNodeSet();
        final Collator collator = getCollator(contextSequence);
        if (contextSequence != null && !contextSequence.isEmpty()) {
            for (final Iterator<NodeProxy> i = nodes.iterator(); i.hasNext();) {
                final NodeProxy current = i.next();
                ContextItem context = current.getContext();
                if (context==null) {
                   throw new XPathException(this,"Context is missing for node set comparison");
                }
                do {
                    final AtomicValue lv = current.atomize();
                    final Sequence rs = getRight().eval(context.getNode().toSequence());                   
                    if (!rs.hasOne())
                        {throw new XPathException(this,
                                "Type error: sequence with less or more than one item is not allowed here");}                   
                    if (compareAtomic(collator, lv, rs.itemAt(0).atomize(), Constants.TRUNC_NONE, relation))
                        {result.add(current);}
                } while ((context = context.getNextDirect()) != null);
            }
        } else {
            final Sequence rs = getRight().eval(null);
            if (!rs.hasOne())
                {throw new XPathException(this,
View Full Code Here

            int sizeHint = Constants.NO_SIZE_HINT;
            if (lastDoc == null || currentNode.getDocument() != lastDoc) {
                lastDoc = currentNode.getDocument();
                sizeHint = nodes.getSizeHint(lastDoc);
            }
            ContextItem contextItem = currentNode.getContext();
            if (contextItem == null) {
                throw new XPathException(this,
                    "Internal evaluation error: context is missing for node " +
                    currentNode.getNodeId() + " !");
            }
            // TODO : review to consider transverse context
            while (contextItem != null) {
                if (contextItem.getContextId() == getExpressionId()) {
                    final NodeProxy next = contextItem.getNode();
                    if (contextIsVirtual || contextSet.contains(next)) {
                        next.addMatches(currentNode);
                        result.add(next, sizeHint);
                    }
                }
                contextItem = contextItem.getNextDirect();
            }
        }
        if (contextSequence.isCacheable())
            {cached = new CachedResult(contextSequence, null, result);}
        contextSet.setTrackMatches(true);
View Full Code Here

                        outerNodeSet.getDocumentSet()).getDocumentCount() == 0)
                        {LOG.info("contextSet and outerNodeSet don't share any document");}
                final NewArrayNodeSet temp = new NewArrayNodeSet(100);
                for (final SequenceIterator i = ancestors.iterate(); i.hasNext();) {
                    NodeProxy p = (NodeProxy) i.nextItem();
                    ContextItem contextNode = p.getContext();
                    temp.reset();
                    while (contextNode != null) {
                        if (contextNode.getContextId() == getExpressionId())
                            {temp.add(contextNode.getNode());}
                        contextNode = contextNode.getNextDirect();
                    }
                    p.clearContext(getExpressionId());
                    // TODO : understand why we sort here...
                    temp.sortInDocumentOrder();
                    for (final SequenceIterator j = innerSeq.iterate(); j.hasNext();) {
                        final NumericValue v = (NumericValue) j.nextItem();
                        // Non integers return... nothing, not even an error !
                        if (!v.hasFractionalPart() && !v.isZero()) {
                            // ... whereas we don't want a sorted array here
                            // TODO : rename this method as getInDocumentOrder ? -pb
                            p = temp.get(v.getInt() - 1);
                            if (p != null) {
                                result.add(p);
                            }
                            // TODO : does null make sense here ? Well... sometimes ;-)
                        }
                    }
                }
                break;
            }
            default:
                for (final SequenceIterator i = outerSequence.iterate(); i.hasNext();) {
                    NodeProxy p = (NodeProxy) i.nextItem();
                    Sequence temp;
                    boolean reverseAxis = true;
                    switch (mode) {
                    case Constants.ANCESTOR_AXIS:
                        temp = contextSet.selectAncestors(p, false, Expression.IGNORE_CONTEXT);
                        break;
                    case Constants.ANCESTOR_SELF_AXIS:
                        temp = contextSet.selectAncestors(p, true, Expression.IGNORE_CONTEXT);
                        break;
                    case Constants.PARENT_AXIS:
                        // TODO : understand why the contextSet is not involved
                        // here
                        // NodeProxy.getParent returns a *theoretical* parent
                        // which is *not* guaranteed to be in the context set !
                        temp = p.getParents(Expression.NO_CONTEXT_ID);
                        break;
                    case Constants.PRECEDING_AXIS:
                        temp = contextSet.selectPreceding(p, Expression.IGNORE_CONTEXT);
                        break;
                    case Constants.PRECEDING_SIBLING_AXIS:
                        temp = contextSet.selectPrecedingSiblings(p, Expression.IGNORE_CONTEXT);
                        break;
                    case Constants.FOLLOWING_SIBLING_AXIS:
                        temp = contextSet.selectFollowingSiblings(p, Expression.IGNORE_CONTEXT);
                        reverseAxis = false;
                        break;
                    case Constants.FOLLOWING_AXIS:
                        temp = contextSet.selectFollowing(p, Expression.IGNORE_CONTEXT);
                        reverseAxis = false;
                        break;
                    case Constants.SELF_AXIS:
                        temp = p;
                        reverseAxis = false;
                        break;
                    default:
                        throw new IllegalArgumentException("Tried to test unknown axis");
                    }
                    if (!temp.isEmpty()) {
                        for (final SequenceIterator j = innerSeq.iterate(); j.hasNext();) {
                            final NumericValue v = (NumericValue) j.nextItem();
                            // Non integers return... nothing, not even an error !
                            if (!v.hasFractionalPart() && !v.isZero()) {
                                final int pos = (reverseAxis ?
                                    temp.getItemCount() - v.getInt() : v.getInt() - 1);
                                // Other positions are ignored
                                if (pos >= 0 && pos < temp.getItemCount()) {
                                    final NodeProxy t = (NodeProxy) temp.itemAt(pos);
                                    // for the current context: filter out those
                                    // context items not selected by the positional predicate
                                    ContextItem ctx = t.getContext();
                                    t.clearContext(Expression.IGNORE_CONTEXT);
                                    while (ctx != null) {
                                        if (ctx.getContextId() == outerContextId) {
                                            if (ctx.getNode().getNodeId().equals(p.getNodeId()))
                                                {t.addContextNode(outerContextId, ctx.getNode());}
                                        } else
                                            {t.addContextNode(ctx.getContextId(), ctx.getNode());}
                                        ctx = ctx.getNextDirect();
                                    }
                                    result.add(t);
                                }
                            }
                        }
View Full Code Here

          int sizeHint = Constants.NO_SIZE_HINT;
          if(lastDoc == null || current.getDocument() != lastDoc) {
            lastDoc = current.getDocument();
            sizeHint = nodes.getSizeHint(lastDoc);
          }
          ContextItem  context = current.getContext();               
          if (context == null) {              
            throw new XPathException(this, "Internal evaluation error: context node is missing for node " +
                current.getNodeId() + "!");
          }
  //        LOG.debug(current.debugContext());
          while (context != null) {
                      //TODO : Is this the context we want ? Not sure... would have prefered the LetExpr.
            if (context.getContextId() == whereExpr.getContextId()) {
              final NodeProxy contextNode = context.getNode();                   
              if(contextIsVirtual || contextSet.contains(contextNode)) {
                              contextNode.addMatches(current);
                result.add(contextNode, sizeHint);
              }
            }
                      context = context.getNextDirect();
          }
        }
        return result;
      }
    }
   
    if (contextSequence == null) {
      final Sequence innerSeq = whereExpr.eval(null);
      return innerSeq.effectiveBooleanValue() ? BooleanValue.TRUE : BooleanValue.FALSE;
    } else {
      // general where clause: just check the effective boolean value
      final ValueSequence result = new ValueSequence();
      int p = 0;     
      for (final SequenceIterator i = contextSequence.iterate(); i.hasNext(); p++) {
        final Item item = i.nextItem();
        context.setContextSequencePosition(p, contextSequence);
                final Sequence innerSeq = whereExpr.eval(contextSequence, item);               
        if (innerSeq.effectiveBooleanValue())
          {result.add(item);}                   
      }
      return result;
View Full Code Here

TOP

Related Classes of org.exist.dom.ContextItem

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.