internal override Querytype getName()
 {
     if (_VarQuery != null)
     {
         return(_VarQuery.getName());
     }
     return(Querytype.None);
 }
Exemple #2
0
        private IQuery ProcessAxis(Axis root, IQuery qyInput, int parent, Axis.AxisType parentaxis)
        {
            IQuery result = null;
            String URN    = String.Empty;

            if (root.Prefix.Length > 0)
            {
                _hasPrefix = true;
            }
            hasReverseAxis = false;
            switch (root.TypeOfAxis)
            {
            case Axis.AxisType.Ancestor:
                result       = new XPathAncestorQuery(qyInput, false, root.Name, root.Prefix, URN, root.Type);
                _specialAxis = hasReverseAxis = true;
                break;

            case Axis.AxisType.AncestorOrSelf:
                result       = new XPathAncestorQuery(qyInput, true, root.Name, root.Prefix, URN, root.Type);
                _specialAxis = hasReverseAxis = true;
                break;

            case Axis.AxisType.Child:
                if (_slashslash)
                {
                    result = new XPathDescendantQuery(qyInput, false, root.Name, root.Prefix, URN, root.Type, abbrAxis);
                    if (_specialAxis || (qyInput != null && (int)qyInput.getName() > (int)Querytype.Self))
                    {
                        result = new CacheQuery(result);
                    }
                    _slashslash  = false;
                    _specialAxis = true;
                    break;
                }
                if (_specialAxis || (qyInput != null && (int)qyInput.getName() > (int)Querytype.Self))
                {
                    result = new CacheChildrenQuery(qyInput, root.Name, root.Prefix, URN, root.Type);
                }
                else
                {
                    result = new ChildrenQuery(qyInput, root.Name, root.Prefix, URN, root.Type);
                }
                break;

            case Axis.AxisType.Parent:
                result = new ParentQuery(qyInput, root.Name, root.Prefix, URN, root.Type);
                break;

            case Axis.AxisType.Descendant:
                switch (parent)
                {
                case Smart_D:
                    result = new SmartXPathDescendantQuery(qyInput, false, root.Name, root.Prefix, URN, root.Type);
                    break;

                case Regular_D:
                    result = new XPathDescendantQuery(qyInput, false, root.Name, root.Prefix, URN, root.Type);
                    if (_specialAxis || (qyInput != null && (int)qyInput.getName() > (int)Querytype.Self))
                    {
                        result = new CacheQuery(result);
                    }
                    _specialAxis = true;
                    break;
                }
                break;

            case Axis.AxisType.DescendantOrSelf:
                switch (parent)
                {
                case Smart_D:
                    result = new SmartXPathDescendantQuery(qyInput, true, root.Name, root.Prefix, URN, root.Type, root.abbrAxis);
                    break;

                case Regular_D:
                    if (_smart <= 1 || root.Type != XPathNodeType.All ||
                        parentaxis != Axis.AxisType.Child)
                    {
                        result = new XPathDescendantQuery(
                            qyInput,
                            true,
                            root.Name,
                            root.Prefix,
                            URN,
                            root.Type,
                            root.abbrAxis);
                        if (_specialAxis || (qyInput != null && (int)qyInput.getName() > (int)Querytype.Self))
                        {
                            result = new CacheQuery(result);
                        }
                        _specialAxis = true;
                    }
                    else
                    {
                        _slashslash = true;
                        abbrAxis    = root.abbrAxis;
                        result      = qyInput;
                    }
                    break;
                }
                break;

            case Axis.AxisType.Preceding:
                result = new PrecedingQuery(
                    qyInput,
                    root.Name,
                    root.Prefix,
                    URN,
                    root.Type);
                _specialAxis = hasReverseAxis = true;
                break;

            case Axis.AxisType.Following:
                result = new FollowingQuery(
                    qyInput,
                    root.Name,
                    root.Prefix,
                    URN,
                    root.Type);
                _specialAxis = true;
                break;

            case Axis.AxisType.FollowingSibling:
                result = new FollSiblingQuery(
                    qyInput,
                    root.Name,
                    root.Prefix,
                    URN,
                    root.Type);
                if (_specialAxis || (qyInput != null && (int)qyInput.getName() > (int)Querytype.Self))
                {
                    result = new DocumentOrderQuery(result);
                }
                break;

            case Axis.AxisType.PrecedingSibling:
                result = new PreSiblingQuery(
                    qyInput,
                    root.Name,
                    root.Prefix,
                    URN,
                    root.Type);
                hasReverseAxis = true;
                break;

            case Axis.AxisType.Attribute:
                result = new AttributeQuery(
                    qyInput,
                    root.Name,
                    root.Prefix,
                    URN,
                    root.Type);
                break;

            case Axis.AxisType.Self:
                result = new XPathSelfQuery(
                    qyInput,
                    root.Name,
                    root.Prefix,
                    URN,
                    root.Type);
                break;

            case Axis.AxisType.Namespace:
                if (
                    (root.Type == XPathNodeType.All || root.Type == XPathNodeType.Element || root.Type == XPathNodeType.Attribute) &&
                    root.Prefix == string.Empty
                    )
                {
                    result = new NamespaceQuery(qyInput, root.Name, root.Prefix, URN, root.Type);
                }
                else
                {
                    result = new EmptyNamespaceQuery();
                }
                break;

            default:
                throw new XPathException(Res.Xp_NotSupported, _query);
            }
            return(result);
        }
Exemple #3
0
        protected XPathNavigator MatchNode(XPathNavigator current, IQuery query)
        {
            XPathNavigator context;

            if (current != null)
            {
                context = query.MatchNode(current);
                if (context != null)
                {
                    if (_opnd.ReturnType() == XPathResultType.Number)
                    {
                        if (_opnd.getName() == Querytype.Constant)
                        {
                            XPathNavigator result = current.Clone();

                            int i = 0;
                            if (query.getName() == Querytype.Child)
                            {
                                result.MoveToParent();
                                result.MoveToFirstChild();
                                while (true)
                                {
                                    if (((ChildrenQuery)query).matches(result))
                                    {
                                        i++;
                                        if (current.IsSamePosition(result))
                                        {
                                            if (XmlConvert.ToXPathDouble(_opnd.getValue(current, null)) == i)
                                            {
                                                return(context);
                                            }
                                            else
                                            {
                                                return(null);
                                            }
                                        }
                                    }
                                    if (!result.MoveToNext())
                                    {
                                        return(null);
                                    }
                                }
                            }
                            if (query.getName() == Querytype.Attribute)
                            {
                                result.MoveToParent();
                                result.MoveToFirstAttribute();
                                while (true)
                                {
                                    if (((AttributeQuery)query).matches(result))
                                    {
                                        i++;
                                    }
                                    if (current.IsSamePosition(result))
                                    {
                                        if (XmlConvert.ToXPathDouble(_opnd.getValue(current, null)) == i)
                                        {
                                            return(context);
                                        }
                                        else
                                        {
                                            return(null);
                                        }
                                    }
                                    if (!result.MoveToNextAttribute())
                                    {
                                        return(null);
                                    }
                                }
                            }
                        }
                        else
                        {
                            setContext(context.Clone());
                            XPathNavigator result = advance();
                            while (result != null)
                            {
                                if (result.IsSamePosition(current))
                                {
                                    return(context);
                                }
                                result = advance();
                            }
                        }
                    }
                    if (_opnd.ReturnType() == XPathResultType.NodeSet)
                    {
                        _opnd.setContext(current);
                        if (_opnd.advance() != null)
                        {
                            return(context);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    if (_opnd.ReturnType() == XPathResultType.Boolean)
                    {
                        if (noPosition)
                        {
                            if ((bool)_opnd.getValue(current, null))
                            {
                                return(context);
                            }
                            return(null);
                        }
                        setContext(context.Clone());
                        XPathNavigator result = advance();
                        while (result != null)
                        {
                            if (result.IsSamePosition(current))
                            {
                                return(context);
                            }
                            result = advance();
                        }
                        return(null);
                    }
                    if (_opnd.ReturnType() == XPathResultType.String)
                    {
                        if (_opnd.getValue(context, null).ToString().Length > 0)
                        {
                            return(context);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }
Exemple #4
0
        protected XPathNavigator MatchNode(XPathNavigator current, IQuery query) {
            XPathNavigator context;
            if (current != null) {
                context = query.MatchNode(current);
                if (context != null) {
                    if (_opnd.ReturnType() == XPathResultType.Number) {
                        if (_opnd.getName() == Querytype.Constant) {
                            XPathNavigator result = current.Clone();

                            int i=0;
                            if (query.getName() == Querytype.Child) {
                                result.MoveToParent();
                                result.MoveToFirstChild();
                                while (true) {
                                    if (((ChildrenQuery)query).matches(result)){
                                        i++;
                                    if (current.IsSamePosition(result))
                                        if (XmlConvert.ToXPathDouble(_opnd.getValue(current, null)) ==  i)
                                            return context;
                                        else
                                            return null;
                                    }        
                                    if (!result.MoveToNext())
                                        return null;

                                }
                            }
                            if (query.getName() == Querytype.Attribute) {
                                result.MoveToParent();
                                result.MoveToFirstAttribute();
                                while (true) {
                                    if (((AttributeQuery)query).matches(result))
                                        i++;
                                    if (current.IsSamePosition(result))
                                        if (XmlConvert.ToXPathDouble(_opnd.getValue(current, null)) == i)
                                            return context;
                                        else
                                            return null;
                                    if (!result.MoveToNextAttribute())
                                        return null;
                         
                                }
                            }
                        }
                        else {
                            setContext(context.Clone());
                            XPathNavigator result = advance();
                            while (result != null) {
                                if (result.IsSamePosition(current))
                                    return context;
                                result = advance();
                            }
                        }

                    }
                    if (_opnd.ReturnType() == XPathResultType.NodeSet) {
                        _opnd.setContext(current); 
                        if (_opnd.advance() != null)
                            return context;
                        else
                            return null;
                    }
                    if (_opnd.ReturnType() == XPathResultType.Boolean) {
                        if (noPosition) {
                            if ((bool)_opnd.getValue(current, null)) {
                                return context;
                            }
                            return null;
                        }
                        setContext(context.Clone());
                        XPathNavigator result = advance();
                        while (result != null) {
                            if (result.IsSamePosition(current))
                                return context;
                            result = advance();
                        }
                        return null;
                    }
                    if (_opnd.ReturnType() == XPathResultType.String)
                        if (_opnd.getValue(context, null).ToString().Length >0)
                            return context;
                        else
                            return null;

                }
                else
                    return null;
            }
            return null;
        } 
Exemple #5
0
        private IQuery ProcessAxis(Axis root , IQuery qyInput, int parent,  Axis.AxisType parentaxis) {
            IQuery result = null;
            String URN = String.Empty;
            if ( root.Prefix.Length > 0) {
                _hasPrefix = true;
            }
            hasReverseAxis = false;
            switch (root.TypeOfAxis) {
            case Axis.AxisType.Ancestor:
                result = new XPathAncestorQuery( qyInput , false, root.Name, root.Prefix, URN, root.Type );
                _specialAxis = hasReverseAxis = true;
                break;
            case Axis.AxisType.AncestorOrSelf:
                result = new XPathAncestorQuery( qyInput, true, root.Name, root.Prefix, URN, root.Type );
                _specialAxis = hasReverseAxis = true;
                break;
            case Axis.AxisType.Child:
                if (_slashslash){
                    result = new XPathDescendantQuery( qyInput, false, root.Name, root.Prefix, URN, root.Type, abbrAxis); 
                   if (_specialAxis || (qyInput != null && (int)qyInput.getName() > (int) Querytype.Self)) {
                        result =  new CacheQuery(result);
                    }
                    _slashslash = false;
                    _specialAxis = true;
                    break;
                }
                if (_specialAxis || (qyInput != null && (int)qyInput.getName() > (int) Querytype.Self))
                    result = new CacheChildrenQuery( qyInput, root.Name, root.Prefix, URN, root.Type );                                                                                                           
                else
                    result = new ChildrenQuery( qyInput, root.Name, root.Prefix, URN, root.Type );
                break;
            case Axis.AxisType.Parent:
                result = new ParentQuery( qyInput, root.Name, root.Prefix, URN, root.Type );                        
                break;
            case Axis.AxisType.Descendant:
                switch (parent) {
                case Smart_D : 
                    result = new SmartXPathDescendantQuery( qyInput, false, root.Name, root.Prefix, URN, root.Type);
                    break;  
                case Regular_D :
                    result = new XPathDescendantQuery(qyInput, false, root.Name, root.Prefix, URN, root.Type);
                    if (_specialAxis || (qyInput != null && (int)qyInput.getName() > (int) Querytype.Self))
                        result = new CacheQuery(result);
                    _specialAxis = true;
			        break;
                }
                break;
            case Axis.AxisType.DescendantOrSelf:
                switch (parent) {
                case Smart_D : 
                    result = new SmartXPathDescendantQuery(qyInput, true, root.Name, root.Prefix, URN, root.Type, root.abbrAxis);                                                            
                    break;  
                case Regular_D :
                       if ( _smart <= 1 || root.Type != XPathNodeType.All ||
                        parentaxis != Axis.AxisType.Child) {
                            result = new XPathDescendantQuery(
                                                           qyInput,
                                                     true,
                                                     root.Name,
                                                     root.Prefix,
                                                     URN,
                                                     root.Type,
                                                     root.abbrAxis);
                            if (_specialAxis || (qyInput != null && (int)qyInput.getName() > (int) Querytype.Self))
                                result =  new CacheQuery(result);
                        _specialAxis = true;

                        }
                        else
                        {
                            _slashslash = true;
                            abbrAxis = root.abbrAxis;
                            result = qyInput;
                        }
        			break;
                }
                break;
            case Axis.AxisType.Preceding:
                result = new PrecedingQuery(
                                           qyInput,
                                           root.Name,
                                           root.Prefix,
                                           URN,
                                           root.Type);
               _specialAxis = hasReverseAxis = true;
                break;

            case Axis.AxisType.Following :
                result = new FollowingQuery(
                                           qyInput,
                                           root.Name,
                                           root.Prefix,
                                           URN,
                                           root.Type);
                _specialAxis = true;
                break;
            case Axis.AxisType.FollowingSibling :
                result = new FollSiblingQuery(
                                           qyInput,
                                           root.Name,
                                           root.Prefix,
                                           URN,
                                           root.Type);
                if (_specialAxis || (qyInput != null && (int)qyInput.getName() > (int) Querytype.Self)) {
                    result =  new DocumentOrderQuery(result);
                }
                break;
            case Axis.AxisType.PrecedingSibling :
                result = new PreSiblingQuery(
                                           qyInput,
                                           root.Name,
                                           root.Prefix,
                                           URN,
                                           root.Type);
                hasReverseAxis = true;
                break;
            case Axis.AxisType.Attribute:
                result = new AttributeQuery(
                                           qyInput,
                                           root.Name,
                                           root.Prefix,
                                           URN,
                                           root.Type);
                break;
            case Axis.AxisType.Self:
                result = new XPathSelfQuery(
                                           qyInput,
                                           root.Name,
                                           root.Prefix,
                                           URN,
                                           root.Type);
                break;
            case Axis.AxisType.Namespace:
                if (
                    (root.Type == XPathNodeType.All || root.Type == XPathNodeType.Element || root.Type == XPathNodeType.Attribute) &&
                    root.Prefix == string.Empty
                ) {
                    result = new NamespaceQuery(qyInput, root.Name, root.Prefix, URN, root.Type);
                }
                else {
                    result = new EmptyNamespaceQuery();
                }
                break;
            default:
                throw new XPathException(Res.Xp_NotSupported, _query);
            }
            return result;
        }