Ejemplo n.º 1
0
        /// <summary>
        /// Distinct-values operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:distinct-values 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 distinct_values(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext context) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence distinct_values(ICollection args, DynamicContext context)
        {
            ResultBuffer rs = new ResultBuffer();

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

            citer.MoveNext();
            ResultSequence arg1 = (ResultSequence)citer.Current;
            ResultSequence arg2 = ResultBuffer.EMPTY;

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

            string collationURI = context.CollationProvider.DefaultCollation;

            if (!(arg2 == null || arg2.empty()))
            {
                XSString collation = (XSString)arg2.item(0);
                collationURI = collation.StringValue;
            }

            for (var iter = arg1.iterator(); iter.MoveNext();)
            {
                AnyAtomicType atomizedItem = (AnyAtomicType)FnData.atomize((Item)iter.Current);
                if (!contains(rs, atomizedItem, context, collationURI))
                {
                    rs.add(atomizedItem);
                }
            }

            return(rs.Sequence);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts arguments to values.
        /// </summary>
        /// <param name="args">
        ///            Result from expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of conversion. </returns>
        private static ICollection value_convert_args(ICollection args)
        {
            var result = new ArrayList(args.Count);

            // atomize arguments
            for (IEnumerator i = args.GetEnumerator(); i.MoveNext();)
            {
                ResultSequence rs = (ResultSequence)i.Current;

                //FnData.fast_atomize(rs);
                rs = FnData.atomize(rs);

                if (rs.empty())
                {
                    return(new ArrayList());
                }

                if (rs.size() > 1)
                {
                    throw new DynamicError(TypeError.invalid_type(null));
                }

                Item arg = rs.first();

                if (arg is XSUntypedAtomic)
                {
                    arg = new XSString(arg.StringValue);
                }

                result.Add(arg);
            }

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// A fast Equality operation, no conversion for the inputs performed.
        /// </summary>
        /// <param name="one">
        ///            input1 of any type. </param>
        /// <param name="two">
        ///            input2 of any type. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of Equality operation. </returns>
        public static bool fs_eq_fast(AnyType one, AnyType two, DynamicContext context)
        {
            one = FnData.atomize((Item)one);
            two = FnData.atomize((Item)two);

            if (one is XSUntypedAtomic)
            {
                one = new XSString(one.StringValue);
            }

            if (two is XSUntypedAtomic)
            {
                two = new XSString(two.StringValue);
            }

            if (!(one is CmpEq))
            {
                DynamicError.throw_type_error();
            }

            CmpEq cmpone = (CmpEq)one;

            return(cmpone.eq(two, context));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Obtain numeric value from expression.
        /// </summary>
        /// <param name="arg">
        ///            input expression. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Resulting numeric type from the operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType get_single_numeric_arg(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static NumericType get_single_numeric_arg(ResultSequence arg)
        {
            int size = arg.size();

            if (size > 1)
            {
                DynamicError.throw_type_error();
            }

            if (size == 0)
            {
                return(null);
            }

            arg = FnData.atomize(arg);
            AnyType at = (AnyType)arg.item(0);

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

            return((NumericType)at);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Convert and promote arguments for operation.
        /// </summary>
        /// <param name="args">
        ///            input arguments. </param>
        /// <param name="sc"> </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of conversion. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static java.util.Collection convert_args(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        private static ICollection convert_args(ICollection args)
        {
            var result = new ArrayList();

            // Keep track of numeric types for promotion
            bool has_float  = false;
            bool has_double = false;

            // atomize arguments
            for (IEnumerator i = args.GetEnumerator(); i.MoveNext();)
            {
                ResultSequence rs = FnData.atomize((ResultSequence)i.Current);

                if (rs.empty())
                {
                    return(new ArrayList());
                }

                if (rs.size() > 1)
                {
                    throw new DynamicError(TypeError.invalid_type(null));
                }

                AnyType arg = (AnyType)rs.item(0);

                if (arg is XSUntypedAtomic)
                {
                    arg = new XSDouble(arg.StringValue);
                }

                if (arg is XSDouble)
                {
                    has_double = true;
                }
                if (arg is XSFloat)
                {
                    has_float = true;
                }
                result.Add(ResultBuffer.wrap(arg));
            }

            if (has_double)
            {
                has_float = false;
            }

            if (has_double || has_float)
            {
                var result2 = new ArrayList();

                // promote arguments
                for (IEnumerator i = result.GetEnumerator(); i.MoveNext();)
                {
                    ResultSequence rs = (ResultSequence)i.Current;

                    Item arg = rs.item(0);

                    if (has_double && (arg is XSFloat))
                    {
                        arg = new XSDouble(((XSFloat)arg).float_value());
                    }
                    else if (has_double && (arg is XSDecimal))
                    {
                        arg = new XSDouble(((XSDecimal)arg).double_value());
                    }
                    else if (has_float && (arg is XSDecimal))
                    {
                        arg = new XSFloat((float)((XSDecimal)arg).double_value());
                    }
                    result2.Add(arg);
                }
                return(result2);
            }

            return(result);
        }
Ejemplo n.º 6
0
        // voodoo 3
        /// <summary>
        /// Actual equality operation for fs_eq_general.
        /// </summary>
        /// <param name="args">
        ///            input arguments. </param>
        /// <param name="type">
        ///            type of the arguments. </param>
        /// <param name="mname">
        ///            Method name for template simulation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of the operation. </returns>
        public static ResultSequence do_cmp_general_op(ICollection args, Type type, string mname, DynamicContext dc)
        {
            // do the voodoo
            MethodBase comparator = null;

            try
            {
                Type[]   margsdef  = new Type[] { type };
                Type[]   margsdef2 = new Type[] { typeof(ICollection), typeof(DynamicContext) };
                object[] margs3    = new object[] { mname, margsdef2 };
                var      v1        = typeof(GenericIComparer)
                                     .GetMethod("GetComparer");
                var v2 = v1.MakeGenericMethod(margsdef);

                comparator = (MethodBase)v2.Invoke(null, margs3);
            }
            catch
            {
                throw new Exception("Can't find method : " + mname);
            }

            // sanity check args and get them
            if (args.Count != 2)
            {
                DynamicError.throw_type_error();
            }

            IEnumerator argiter = args.GetEnumerator();

            argiter.MoveNext();
            ResultSequence one = (ResultSequence)argiter.Current;

            argiter.MoveNext();
            ResultSequence two = (ResultSequence)argiter.Current;

            // XXX ?
            if (one.empty() || two.empty())
            {
                return(ResultSequenceFactory.create_new(new XSBoolean(false)));
            }

            // atomize
            one = FnData.atomize(one);
            two = FnData.atomize(two);

            // we gotta find a pair that satisfied the condition
            for (IEnumerator i = one.iterator(); i.MoveNext();)
            {
                AnyType a = (AnyType)i.Current;
                for (IEnumerator j = two.iterator(); j.MoveNext();)
                {
                    AnyType b = (AnyType)j.Current;

                    if (do_general_pair(a, b, comparator, dc))
                    {
                        return(ResultSequenceFactory.create_new(new XSBoolean(true)));
                    }
                }
            }

            return(ResultSequenceFactory.create_new(new XSBoolean(false)));
        }
Ejemplo n.º 7
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));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Number operation.
        /// </summary>
        /// <param name="arg">
        ///            Result from the expressions evaluation. </param>
        /// <param name="dc">
        ///            Result of dynamic context operation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:number operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble fn_number(org.eclipse.wst.xml.xpath2.api.ResultSequence arg, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static XSDouble fn_number(ResultSequence arg, EvaluationContext ec)
        {
            if (arg.size() > 1)
            {
                throw new DynamicError(TypeError.invalid_type("bad argument passed to fn:number()"));
            }
            else if (arg.size() == 1)
            {
                Item at = arg.first();

                /*
                 * if (!(at instanceof AnyAtomicType))
                 *      DynamicError.throw_type_error();
                 */

                if (at is AnyAtomicType)
                {
                    if ((at is XSDouble))
                    {
                        return((XSDouble)at);
                    }
                    else if ((at is XSFloat))
                    {
                        float value = ((XSFloat)at).float_value();
                        if (float.IsNaN(value))
                        {
                            return(new XSDouble(double.NaN));
                        }
                        else if (value == float.NegativeInfinity)
                        {
                            return(new XSDouble(double.NegativeInfinity));
                        }
                        else if (value == float.PositiveInfinity)
                        {
                            return(new XSDouble(double.PositiveInfinity));
                        }
                        else
                        {
                            return(new XSDouble((double)value));
                        }
                    }
                    else
                    {
                        XSDouble d = XSDouble.parse_double(at.StringValue);
                        return(d != null ? d : new XSDouble(double.NaN));
                    }
                }
                else if (at is NodeType)
                {
                    XSDouble d = XSDouble.parse_double((FnData.atomize(at)).StringValue);
                    return(d != null ? d : new XSDouble(double.NaN));
                }
            }
            else
            {
                return(new XSDouble(double.NaN));
            }

            // unreach
            return(null);
        }