Beispiel #1
0
 public virtual IEnumerator iterator()
 {
     return(rs.iterator());
 }
Beispiel #2
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));
            }
        }