示例#1
0
        // convert argument according to section 3.1.5 of xpath 2.0 spec
        /// <summary>
        /// Convert the input argument according to section 3.1.5 of specification.
        /// </summary>
        /// <param name="arg">
        ///            input argument. </param>
        /// <param name="expected">
        ///            Expected Sequence type. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Converted argument. </returns>
        public static org.eclipse.wst.xml.xpath2.api.ResultSequence convert_argument(org.eclipse.wst.xml.xpath2.api.ResultSequence arg, SeqType expected)
        {
            ResultBuffer result = new ResultBuffer();

            // XXX: Should use type_class instead and use item.getClass().isAssignableTo(expected.type_class())
            AnyType expected_type = expected.type();

            // expected is atomic
            if (expected_type is AnyAtomicType)
            {
                AnyAtomicType expected_aat = (AnyAtomicType)expected_type;

                // atomize
                org.eclipse.wst.xml.xpath2.api.ResultSequence rs = FnData.atomize(arg);

                // cast untyped to expected type
                for (var i = rs.iterator(); i.MoveNext();)
                {
                    AnyType item = (AnyType)i.Current;

                    if (item is XSUntypedAtomic)
                    {
                        // create a new item of the expected
                        // type initialized with from the string
                        // value of the item
                        ResultSequence converted = null;
                        if (expected_aat is XSString)
                        {
                            XSString strType = new XSString(item.StringValue);
                            converted = ResultSequenceFactory.create_new(strType);
                        }
                        else
                        {
                            converted = ResultSequenceFactory.create_new(item);
                        }

                        result.concat(converted);
                    }
                    // xs:anyURI promotion to xs:string
                    else if (item is XSAnyURI && expected_aat is XSString)
                    {
                        result.add(new XSString(item.StringValue));
                    }
                    // numeric type promotion
                    else if (item is NumericType)
                    {
                        if (expected_aat is XSDouble)
                        {
                            XSDouble doubleType = new XSDouble(item.StringValue);
                            result.add(doubleType);
                        }
                        else
                        {
                            result.add(item);
                        }
                    }
                    else
                    {
                        result.add(item);
                    }
                }
                // do sequence type matching on converted arguments
                return(expected.match(result.Sequence));
            }
            else
            {
                // do sequence type matching on converted arguments
                return(expected.match(arg));
            }
        }
        /// <summary>
        /// Convert-Operand operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fs: operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence convert_operand(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence convert_operand(ICollection args)
        {
            Debug.Assert(args.Count == 2);

            IEnumerator iter = args.GetEnumerator();

            iter.MoveNext();
            ResultSequence actual = (ResultSequence)iter.Current;

            iter.MoveNext();
            ResultSequence expected = (ResultSequence)iter.Current;

            if (expected == null || expected.size() != 1)
            {
                DynamicError.throw_type_error();
            }

            Item at = expected.first();

            if (!(at is AnyAtomicType))
            {
                DynamicError.throw_type_error();
            }

            AnyAtomicType exp_aat = (AnyAtomicType)at;

            ResultBuffer result = new ResultBuffer();

            // 1
            if (actual.empty())
            {
                return(result.Sequence);
            }

            // convert sequence
            for (var i = actual.iterator(); i.MoveNext();)
            {
                AnyType item = (AnyType)i.Current;

                // 2
                if (item is XSUntypedAtomic)
                {
                    // a
                    if (exp_aat is XSUntypedAtomic)
                    {
                        result.add(new XSString(item.StringValue));
                    }
                    // b
                    else if (exp_aat is NumericType)
                    {
                        result.add(new XSDouble(item.StringValue));
                    }
                    // c
                    else
                    {
                        Debug.Assert(exp_aat is CtrType);
                        CtrType cons = (CtrType)exp_aat;
                        result.concat(cons.constructor(new XSString(item.StringValue)));
                    }
                }
                // 4
                else
                {
                    result.add(item);
                }
            }

            return(result.Sequence);
        }
示例#3
0
        /// <summary>
        /// Insert-Before operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:insert-before operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence insert_before(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence insert_before(ICollection args)
        {
            Debug.Assert(args.Count == 3);

            ResultBuffer rs = new ResultBuffer();

            // get args
            IEnumerator citer = args.GetEnumerator();

            citer.MoveNext();
            ResultSequence target = (ResultSequence)citer.Current;

            citer.MoveNext();
            ResultSequence arg2 = (ResultSequence)citer.Current;

            citer.MoveNext();
            ResultSequence inserts = (ResultSequence)citer.Current;

            // sanity chex
            if (arg2.size() != 1)
            {
                DynamicError.throw_type_error();
            }

            Item at = arg2.first();

            if (!(at is XSInteger))
            {
                DynamicError.throw_type_error();
            }

            // XXX cloning!
            if (target.empty())
            {
                return(inserts);
            }
            if (inserts.empty())
            {
                return(target);
            }

            int position = (int)((XSInteger)at).int_value();

            if (position < 1)
            {
                position = 1;
            }
            int target_size = target.size();

            if (position > target_size)
            {
                position = target_size + 1;
            }

            int curpos = 1;

            for (var i = target.iterator(); i.MoveNext();)
            {
                at = (AnyType)i.Current;

                if (curpos == position)
                {
                    rs.concat(inserts);
                }

                rs.add(at);

                curpos++;
            }
            if (curpos == position)
            {
                rs.concat(inserts);
            }

            return(rs.Sequence);
        }
示例#4
0
        /// <summary>
        /// Subsequence operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:subsequence operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence subsequence(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence subsequence(ICollection args)
        {
            ResultBuffer rs = new ResultBuffer();

            // get args
            IEnumerator citer = args.GetEnumerator();

            citer.MoveNext();
            ResultSequence seq = (ResultSequence)citer.Current;

            if (seq.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            citer.MoveNext();
            ResultSequence startLoc = (ResultSequence)citer.Current;
            ResultSequence length   = null;

            if (citer.MoveNext())
            {
                length = (ResultSequence)citer.Current;
            }

            Item at = startLoc.first();

            if (!(at is NumericType))
            {
                DynamicError.throw_type_error();
            }

            at = new XSDouble(at.StringValue);

            int start            = (int)((XSDouble)at).double_value();
            int effectiveNoItems = 0;             // no of items beyond index >= 1 that are added to the result

            if (length != null)
            {
                // the 3rd argument is present
                if (length.size() != 1)
                {
                    DynamicError.throw_type_error();
                }
                at = length.first();
                if (!(at is NumericType))
                {
                    DynamicError.throw_type_error();
                }
                at = new XSDouble(at.StringValue);
                int len = (int)((XSDouble)at).double_value();
                if (len < 0)
                {
                    DynamicError.throw_type_error();
                }

                if (start <= 0)
                {
                    effectiveNoItems = start + len - 1;
                    start            = 1;
                }
                else
                {
                    effectiveNoItems = len;
                }
            }
            else
            {
                // 3rd argument is absent
                if (start <= 0)
                {
                    start            = 1;
                    effectiveNoItems = seq.size();
                }
                else
                {
                    effectiveNoItems = seq.size() - start + 1;
                }
            }

            int pos        = 1;      // index running parallel to the iterator
            int addedItems = 0;

            if (effectiveNoItems > 0)
            {
                for (var seqIter = seq.iterator(); seqIter.MoveNext();)
                {
                    at = (AnyType)seqIter.Current;
                    if (start <= pos && addedItems < effectiveNoItems)
                    {
                        rs.add(at);
                        addedItems++;
                    }
                    pos++;
                }
            }

            return(rs.Sequence);
        }