Ejemplo n.º 1
0
        IQuery ProcessFunction(Function root, IQuery qyInput)
        {
            IQuery qy = null;

            switch (root.TypeOfFunction)
            {
            case FT.FuncPosition:
                qy = new MethodOperand(null, root.TypeOfFunction);
                return(qy);

            // we should be able to count how many attributes
            case FT.FuncCount:
                qy = ProcessNode((AstNode)(root.ArgumentList[0]), null);

                if (qy is AttributeQuery)
                {
                    return(new MethodOperand(qy, FT.FuncCount));
                }
                //none attribute count funciton result in error.

                break;

            case FT.FuncLocalName:
            case FT.FuncNameSpaceUri:
            case FT.FuncName:
                if (root.ArgumentList != null && root.ArgumentList.Count > 0)
                {
                    return(new MethodOperand(ProcessNode((AstNode)(root.ArgumentList[0]), null),
                                             root.TypeOfFunction));
                }
                else
                {
                    return(new MethodOperand(null, root.TypeOfFunction));
                }

            case FT.FuncString:
            case FT.FuncConcat:
            case FT.FuncStartsWith:
            case FT.FuncContains:
            case FT.FuncSubstringBefore:
            case FT.FuncSubstringAfter:
            case FT.FuncSubstring:
            case FT.FuncStringLength:
            case FT.FuncNormalize:
            case FT.FuncTranslate:
                ArrayList ArgList = null;
                if (root.ArgumentList != null)
                {
                    int count = 0;
                    ArgList = new ArrayList();
                    while (count < root.ArgumentList.Count)
                    {
                        ArgList.Add(ProcessNode((AstNode)root.ArgumentList[count++], null));
                    }
                }
                return(new StringFunctions(ArgList, root.TypeOfFunction));

            case FT.FuncNumber:
            //case FT.FuncSum:
            case FT.FuncFloor:
            case FT.FuncCeiling:
            case FT.FuncRound:
                if (root.ArgumentList != null)
                {
                    return(new NumberFunctions(ProcessNode((AstNode)root.ArgumentList[0], null),
                                               root.TypeOfFunction));
                }
                else
                {
                    return(new NumberFunctions(null));
                }

            case FT.FuncTrue:
            case FT.FuncFalse:
                return(new BooleanFunctions(null, root.TypeOfFunction));

            case FT.FuncNot:
            case FT.FuncLang:
            case FT.FuncBoolean:
                return(new BooleanFunctions(ProcessNode((AstNode)root.ArgumentList[0], null),
                                            root.TypeOfFunction));


            // Unsupport functions
            case FT.FuncID:

            // Last Function is not supported, because we don't know
            // how many we get in the list
            // <Root> <e a="1"/> <e a="2"/></Root>
            // /Root/e[last()=2]
            // we will not return the first one because
            // we don't if we have two e elements.
            case FT.FuncLast:
            //qy = new MethodOperand(null, root.TypeOfFunction);
            //return qy;

            default:
                throw new XPathReaderException("The XPath query is not supported.");
            }

            return(null);
        }
Ejemplo n.º 2
0
        IQuery ProcessFunction(Function root, IQuery qyInput) {

            IQuery qy = null;

            switch (root.TypeOfFunction) {

                case FT.FuncPosition :
                    qy =  new MethodOperand(null, root.TypeOfFunction);
                    return qy;

                // we should be able to count how many attributes
                case FT.FuncCount :
                    qy = ProcessNode((AstNode)(root.ArgumentList[0]), null);

                    if (qy is AttributeQuery) {
                        return new MethodOperand(qy, FT.FuncCount);
                    }
                    //none attribute count funciton result in error.

                    break;

                case FT.FuncLocalName :
                case FT.FuncNameSpaceUri :
                case FT.FuncName :
                    if (root.ArgumentList != null && root.ArgumentList.Count > 0) {
                        return new MethodOperand( ProcessNode((AstNode)(root.ArgumentList[0]),null),
                                                  root.TypeOfFunction);
                     } else{
                        return new MethodOperand(null, root.TypeOfFunction);
                    }

                case FT.FuncString:
                case FT.FuncConcat:
                case FT.FuncStartsWith:
                case FT.FuncContains:
                case FT.FuncSubstringBefore:
                case FT.FuncSubstringAfter:
                case FT.FuncSubstring:
                case FT.FuncStringLength:
                case FT.FuncNormalize:
                case FT.FuncTranslate:
                    ArrayList ArgList = null;
                    if (root.ArgumentList != null) {
                        int count = 0;
                        ArgList = new ArrayList();
                        while (count < root.ArgumentList.Count)
                            ArgList.Add(ProcessNode((AstNode)root.ArgumentList[count++], null));
                    }
                    return new StringFunctions(ArgList, root.TypeOfFunction);

                case FT.FuncNumber:
                //case FT.FuncSum:
                case FT.FuncFloor:
                case FT.FuncCeiling:
                case FT.FuncRound:
                    if (root.ArgumentList != null) {
                        return new NumberFunctions(ProcessNode((AstNode)root.ArgumentList[0], null),
                                                   root.TypeOfFunction);
                    } else {
                        return new NumberFunctions(null);
                    }
                    
                case FT.FuncTrue:
                case FT.FuncFalse:
                    return new BooleanFunctions(null, root.TypeOfFunction);

                case FT.FuncNot:
                case FT.FuncLang:
                case FT.FuncBoolean:
                    return new BooleanFunctions(ProcessNode((AstNode)root.ArgumentList[0], null),
                                                root.TypeOfFunction);


                // Unsupport functions
                case FT.FuncID :

                // Last Function is not supported, because we don't know
                // how many we get in the list
                // <Root> <e a="1"/> <e a="2"/></Root>
                // /Root/e[last()=2]
                // we will not return the first one because
                // we don't if we have two e elements.
                case FT.FuncLast :
                    //qy = new MethodOperand(null, root.TypeOfFunction);
                    //return qy;

                default :
                    throw new XPathReaderException("The XPath query is not supported.");
            }

            return null;
        }