Пример #1
0
        /// <summary>
        /// Obtain the string length of the arguments.
        /// </summary>
        /// <param name="args">
        ///            are used to obtain the string length. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> The result of obtaining the string length from the arguments. </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 string_length(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence string_length(ICollection args, EvaluationContext ec)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            ResultSequence arg1 = null;

            if (cargs.Count == 0)
            {
                // support for arity = 0
                return(getResultSetForArityZero(ec));
            }
            else
            {
                var i = cargs.GetEnumerator();
                i.MoveNext();
                arg1 = (ResultSequence)i.Current;
            }

            string str = "";

            if (!arg1.empty())
            {
                str = ((XSString)arg1.first()).value();
            }

            BigInteger.TryParse(str, out BigInteger v);
            return(new XSInteger(v));
        }
Пример #2
0
        /// <summary>
        /// Unary operation on the arguments.
        /// </summary>
        /// <param name="args">
        ///            input arguments. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of the operation. </returns>
        public static ResultSequence fs_plus_unary(ICollection args)
        {
            // make sure we got only one arg
            if (args.Count != 1)
            {
                DynamicError.throw_type_error();
            }
            var i = args.GetEnumerator();

            i.MoveNext();
            ResultSequence arg = (ResultSequence)i.Current;

            // make sure we got only one numeric atom
            if (arg.size() != 1)
            {
                DynamicError.throw_type_error();
            }
            Item at = arg.first();

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

            // no-op
            return(arg);
        }
Пример #3
0
        /// <summary>
        /// Creates a new ResultSequence consisting of the extractable integer in the
        /// supplied ResultSequence
        /// </summary>
        /// <param name="arg">
        ///            The ResultSequence from which the integer is to be extracted </param>
        /// <returns> New ResultSequence consisting of the integer supplied </returns>
        /// <exception cref="DynamicError"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence constructor(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public override ResultSequence constructor(ResultSequence arg)
        {
            if (arg.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            // the function conversion rules apply here too. Get the argument
            // and convert it's string value to an integer.
            Item aat = arg.first();

            if (aat is XSDuration || aat is CalendarType || aat is XSBase64Binary || aat is XSHexBinary || aat is XSAnyURI)
            {
                throw DynamicError.invalidType();
            }

            if (!isCastable(aat))
            {
                throw DynamicError.cant_cast(null);
            }


            try
            {
                System.Numerics.BigInteger bigInt = castInteger(aat);
                return(new XSInteger(bigInt));
            }
            catch (System.FormatException)
            {
                throw DynamicError.invalidLexicalValue();
            }
        }
Пример #4
0
        /// <summary>
        /// Namespace-uri-from-QName operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:namespace-uri-from-QName 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 namespace(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence @namespace(ICollection args)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            // get arg
            var i = cargs.GetEnumerator();

            i.MoveNext();
            ResultSequence arg1 = (ResultSequence)i.Current;

            if (arg1 == null || arg1.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            QName qname = (QName)arg1.first();

            string ns = qname.@namespace();

            if (string.ReferenceEquals(ns, null))
            {
                ns = "";
            }
            return(new XSAnyURI(ns));
        }
Пример #5
0
        /// <summary>
        /// Deep-Equal expression operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <param name="context">
        ///            Dynamic context </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:deep-equal 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 deep_equal(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext context) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence deep_equal(ICollection args, EvaluationContext context)
        {
            // get args
            IEnumerator citer = args.GetEnumerator();

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

            citer.MoveNext();
            ResultSequence arg2         = (ResultSequence)citer.Current;
            ResultSequence arg3         = null;
            string         collationURI = context.StaticContext.CollationProvider.DefaultCollation;

            if (citer.MoveNext())
            {
                arg3 = (ResultSequence)citer.Current;
                if (!(arg3 == null || arg3.empty()))
                {
                    collationURI = arg3.first().StringValue;
                }
            }

            bool result = deep_equal(arg1, arg2, context, collationURI);

            return(ResultSequenceFactory.create_new(new XSBoolean(result)));
        }
Пример #6
0
        /// <summary>
        /// Compare the arguments.
        /// </summary>
        /// <param name="args">
        ///            are compared (optional 3rd argument is the collation) </param>
        /// <param name="dynamicContext">
        ///            Current dynamic context </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> The result of the comparison of the arguments. </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 compare(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext context) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence compare(ICollection args, DynamicContext context)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            IEnumerator argiter = cargs.GetEnumerator();

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

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

            string collationUri = context.CollationProvider.DefaultCollation;

            if (argiter.MoveNext())
            {
                ResultSequence collArg = (ResultSequence)argiter.Current;
                collationUri = collArg.first().StringValue;
            }

            XSString xstr1 = arg1.empty() ? null : (XSString)arg1.first();
            XSString xstr2 = arg2.empty() ? null : (XSString)arg2.first();

            System.Numerics.BigInteger result = compare_string(collationUri, xstr1, xstr2, context);
            if (result != null)
            {
                return(ResultSequenceFactory.create_new(new XSInteger(result)));
            }
            else
            {
                return(ResultSequenceFactory.create_new());
            }
        }
Пример #7
0
        /// <summary>
        /// Prefix-from-QName operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:prefix-from-QName 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 prefix(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.StaticContext sc) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence prefix(ICollection args, StaticContext sc)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            // get arg
            var i = cargs.GetEnumerator();

            i.MoveNext();
            ResultSequence arg1 = (ResultSequence)i.Current;

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

            QName qname = (QName)arg1.first();

            string prefix = qname.prefix();

            if (!string.ReferenceEquals(prefix, null))
            {
                if (!XMLConstants.NULL_NS_URI.Equals(sc.NamespaceContext.getNamespaceURI(prefix)))
                {
                    return(new XSNCName(prefix));
                }
                else
                {
                    throw DynamicError.invalidPrefix();
                }
            }
            return(ResultBuffer.EMPTY);
        }
Пример #8
0
        /// <summary>
        /// Mathematical subtraction between this time stored and the supplied
        /// representation. This supplied representation must be of either type
        /// XSTime (in which case the result is the duration of time between these
        /// two times) or a XSDayTimeDuration (in which case the result is the time
        /// when this duration is subtracted from the time stored).
        /// </summary>
        /// <param name="arg">
        ///            The representation to subtract (either XSTim or
        ///            XDTDayTimeDuration) </param>
        /// <returns> A ResultSequence representing the result of the subtraction </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence minus(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public virtual ResultSequence minus(ResultSequence arg)
        {
            if (arg.size() != 1)
            {
                DynamicError.throw_type_error();
            }

            Item at = arg.first();

            if (!(at is XSTime) && !(at is XSDayTimeDuration))
            {
                throw DynamicError.throw_type_error();
            }

            if (at is XSTime)
            {
                return(minusXSTimeDuration(at));
            }

            if (at is XSDayTimeDuration)
            {
                return(minusXSDayTimeDuration(at));
            }
            return(null);            // unreach
        }
Пример #9
0
        /// <summary>
        /// Creates a new ResultSequence consisting of the extractable time duration
        /// from the supplied ResultSequence
        /// </summary>
        /// <param name="arg">
        ///            The ResultSequence from which to extract </param>
        /// <returns> New ResultSequence consisting of the time duration extracted </returns>
        /// <exception cref="DynamicError"> </exception>
        public override ResultSequence constructor(ResultSequence arg)
        {
            if (arg.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            AnyAtomicType aat = (AnyAtomicType)arg.first();

            if (aat is NumericType || aat is CalendarType || aat is XSBoolean || aat is XSBase64Binary || aat is XSHexBinary || aat is XSAnyURI)
            {
                throw DynamicError.invalidType();
            }

            if (!(isCastable(aat)))
            {
                throw DynamicError.cant_cast(null);
            }

            XSDuration duration = castDuration(aat);

            if (duration == null)
            {
                throw DynamicError.cant_cast(null);
            }

            return(duration);
        }
Пример #10
0
        /// <summary>
        /// Document-Uri operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:document-uri 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 document_uri(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence document_uri(ICollection args)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());
            var         i     = cargs.GetEnumerator();

            i.MoveNext();
            ResultSequence arg1 = (ResultSequence)i.Current;

            if (arg1 == null || arg1.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            NodeType nt = (NodeType)arg1.first();

            if (!(nt is DocType))
            {
                return(ResultBuffer.EMPTY);
            }

            DocType dt          = (DocType)nt;
            string  documentURI = dt.value().DocumentURI;

            if (!string.ReferenceEquals(documentURI, null))
            {
                XSAnyURI docUri = new XSAnyURI(documentURI);
                return(docUri);
            }
            return(ResultBuffer.EMPTY);
        }
Пример #11
0
        /// <summary>
        /// Compare the arguments as codepoints
        /// </summary>
        /// <param name="args">
        ///            are compared. </param>
        /// <param name="dynamicContext">
        ///            The current dynamic context </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> The result of the comparison of the arguments. </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 codepoint_equals(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext dynamicContext) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence codepoint_equals(ICollection args, DynamicContext dynamicContext)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            ResultBuffer rs = new ResultBuffer();

            IEnumerator argiter = cargs.GetEnumerator();

            argiter.MoveNext();
            ResultSequence arg1  = (ResultSequence)argiter.Current;
            XSString       xstr1 = arg1 == null || arg1.empty() ? null : (XSString)arg1.first();

            argiter.MoveNext();
            ResultSequence arg2  = (ResultSequence)argiter.Current;
            XSString       xstr2 = arg2 == null || arg2.empty() ? null : (XSString)arg2.first();

            // This delegates to FnCompare
            System.Numerics.BigInteger result = FnCompare.compare_string(org.eclipse.wst.xml.xpath2.api.CollationProvider_Fields.CODEPOINT_COLLATION, xstr1, xstr2, dynamicContext);
            if (result != null)
            {
                rs.add(new XSBoolean(System.Numerics.BigInteger.Zero.Equals(result)));
            }

            return(rs.Sequence);
        }
Пример #12
0
        /// <summary>
        /// Join the arguments.
        /// </summary>
        /// <param name="args">
        ///            are joined. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> The result of the arguments being joined together. </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 string_join(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence string_join(ICollection args)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            IEnumerator argi = cargs.GetEnumerator();

            argi.MoveNext();
            ResultSequence arg1 = (ResultSequence)argi.Current;

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

            string result    = "";
            string separator = ((XSString)arg2.first()).value();

            StringBuilder buf   = new StringBuilder();
            bool          first = false;

            for (var i = arg1.iterator(); i.MoveNext();)
            {
                if (!first)
                {
                    buf.Append(separator);
                }
                first = false;
                XSString item = (XSString)i.Current;
                buf.Append(item.value());
            }

            result = buf.ToString();
            return(new XSString(result));
        }
Пример #13
0
        /// <summary>
        /// Resolve the QName of the given arguments.
        /// </summary>
        /// <param name="args">
        ///            Result from teh expressions evaluation. </param>
        /// <param name="sc">
        ///            Result of static context operation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of the fn:QName 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 resolve_QName(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.StaticContext sc) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence resolve_QName(ICollection args, StaticContext sc)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            // get args
            IEnumerator argiter = cargs.GetEnumerator();

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

            string ns = null;

            if (!(arg1 == null || arg1.empty()))
            {
                ns = ((XSString)arg1.first()).value();
            }

            argiter.MoveNext();
            ResultSequence arg2 = (ResultSequence)argiter.Current;
            string         name = ((XSString)arg2.first()).value();

            QName qn = QName.parse_QName(name);

            if (qn == null)
            {
                throw DynamicError.lexical_error(null);
            }
            qn.set_namespace(ns);

            return(qn);
        }
Пример #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence fn_round_half_to_even(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence fn_round_half_to_even(ICollection args)
        {
            if (args.Count > 2 || args.Count <= 1)
            {
                throw new DynamicError(TypeError.invalid_type(null));
            }

            IEnumerator argIt = args.GetEnumerator();

            argIt.MoveNext();
            ResultSequence rsArg1 = (ResultSequence)argIt.Current;

            argIt.MoveNext();
            ResultSequence rsPrecision = (ResultSequence)argIt.Current;

            NumericType nt = FnAbs.get_single_numeric_arg(rsArg1);

            // empty arg
            if (nt == null)
            {
                return(ResultBuffer.EMPTY);
            }

            NumericType ntPrecision = (NumericType)rsPrecision.first();

            return(nt.round_half_to_even(int.Parse(ntPrecision.StringValue)));
        }
        /// <summary>
        /// Base-Uri operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:base-uri 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 string_to_codepoints(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence string_to_codepoints(ICollection args)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            var i = cargs.GetEnumerator();

            i.MoveNext();
            ResultSequence arg1 = (ResultSequence)i.Current;

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

            XSString xstr = (XSString)arg1.first();

            CodePointIterator cpi = new StringCodePointIterator(xstr.value());

            ResultBuffer rs = new ResultBuffer();

            for (int codePoint = cpi.current(); codePoint != org.eclipse.wst.xml.xpath2.processor.@internal.utils.CodePointIterator_Fields.DONE; codePoint = cpi.next())
            {
                rs.add(new XSInteger(new System.Numerics.BigInteger(codePoint)));
            }
            return(rs.Sequence);
        }
Пример #16
0
        /// <summary>
        /// Mathematical multiplication between this duration stored and the supplied
        /// duration of time (of type XSYearMonthDuration)
        /// </summary>
        /// <param name="arg">
        ///            The duration of time to multiply by </param>
        /// <returns> New XSYearMonthDuration representing the resulting duration
        ///         after the multiplication </returns>
        /// <exception cref="DynamicError"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence times(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public virtual ResultSequence times(ResultSequence arg)
        {
            ResultSequence convertedRS = arg;

            if (arg.size() == 1)
            {
                Item argValue = arg.first();
                if (argValue is XSDecimal)
                {
                    convertedRS = ResultSequenceFactory.create_new(new XSDouble(argValue.StringValue));
                }
            }

            XSDouble val = (XSDouble)NumericType.get_single_type(convertedRS, typeof(XSDouble));

            if (val.nan())
            {
                throw DynamicError.nan();
            }

            if (val.infinite())
            {
                throw DynamicError.overflowDateTime();
            }

            int res = (int)Math.Round(monthValue() * val.double_value());

            return(ResultSequenceFactory.create_new(new XSYearMonthDuration(res)));
        }
Пример #17
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);
        }
Пример #18
0
        /// <summary>
        /// Creates a new ResultSequence consisting of the extractable gDay in the
        /// supplied ResultSequence
        /// </summary>
        /// <param name="arg">
        ///            The ResultSequence from which the gDay is to be extracted </param>
        /// <returns> New ResultSequence consisting of the supplied day </returns>
        /// <exception cref="DynamicError"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence constructor(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public override ResultSequence constructor(ResultSequence arg)
        {
            if (arg.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            AnyAtomicType aat = (AnyAtomicType)arg.first();

            if (aat is NumericType || aat is XSDuration || aat is XSTime || isGDataType(aat) || aat is XSBoolean || aat is XSBase64Binary || aat is XSHexBinary || aat is XSAnyURI)
            {
                throw DynamicError.invalidType();
            }

            if (!isCastable(aat))
            {
                throw DynamicError.cant_cast(null);
            }

            XSGDay val = castGDay(aat);

            if (val == null)
            {
                throw DynamicError.cant_cast(null);
            }

            return(val);
        }
Пример #19
0
        /// <summary>
        /// Node-Name operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:node-name 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 node_name(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence node_name(ICollection args)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            var i = cargs.GetEnumerator();

            i.MoveNext();
            ResultSequence arg1 = (ResultSequence)i.Current;

            if (arg1 == null || arg1.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            NodeType nt = (NodeType)arg1.first();

            QName nodename = nt.node_name();

            if (nodename == null)
            {
                return(ResultBuffer.EMPTY);
            }

            return(nodename);
        }
Пример #20
0
        /// <summary>
        /// Normalize space in the arguments.
        /// </summary>
        /// <param name="args">
        ///            are used to obtain space from, in order to be normalized. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> The result of normalizing the space in the arguments. </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 normalize_space(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence normalize_space(ICollection args, EvaluationContext ec)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            ResultSequence arg1 = null;

            if (cargs.Count == 0)
            {
                // support for arity = 0
                arg1 = getResultSetForArityZero(ec);
            }
            else
            {
                var i = cargs.GetEnumerator();
                i.MoveNext();
                arg1 = (ResultSequence)i.Current;
            }

            string str = "";

            if (!arg1.empty())
            {
                str = ((XSString)arg1.first()).value();
            }
            return(new XSString(normalize(str)));
        }
Пример #21
0
        /// <summary>
        /// Creates a new result sequence consisting of the retrievable double number
        /// in the supplied result sequence
        /// </summary>
        /// <param name="arg">
        ///            The result sequence from which to extract the double number. </param>
        /// <exception cref="DynamicError"> </exception>
        /// <returns> A new result sequence consisting of the double number supplied. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence constructor(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public override ResultSequence constructor(ResultSequence arg)
        {
            if (arg.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            Item aat = arg.first();

            if (aat is XSDuration || aat is CalendarType || aat is XSBase64Binary || aat is XSHexBinary || aat is XSAnyURI)
            {
                throw DynamicError.invalidType();
            }

            if (!isCastable(aat))
            {
                throw DynamicError.cant_cast(null);
            }

            XSDouble d = castDouble(aat);

            if (d == null)
            {
                throw DynamicError.cant_cast(null);
            }

            return(d);
        }
Пример #22
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 id(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext context) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence id(ICollection args, EvaluationContext context)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            ResultBuffer rs = new ResultBuffer();

            IEnumerator argIt = cargs.GetEnumerator();

            argIt.MoveNext();
            ResultSequence idrefRS = (ResultSequence)argIt.Current;

            string[] idrefst = idrefRS.first().StringValue.Split(" ", true);

            ArrayList      idrefs   = createIDRefs(idrefst);
            ResultSequence nodeArg  = null;
            NodeType       nodeType = null;

            if (argIt.MoveNext())
            {
                nodeArg  = (ResultSequence)argIt.Current;
                nodeType = (NodeType)nodeArg.first();
            }
            else
            {
                if (context.ContextItem == null)
                {
                    throw DynamicError.contextUndefined();
                }
                if (!(context.ContextItem is NodeType))
                {
                    throw new DynamicError(TypeError.invalid_type(null));
                }
                nodeType = (NodeType)context.ContextItem;
                if (nodeType.node_value().OwnerDocument == null)
                {
                    throw DynamicError.contextUndefined();
                }
            }

            Node node = nodeType.node_value();

            if (node.OwnerDocument == null)
            {
                // W3C Test suite seems to want XPDY0002
                throw DynamicError.contextUndefined();
                //throw DynamicError.noContextDoc();
            }

            if (hasIDREF(idrefs, node))
            {
                ElementType element = new ElementType((Element)node, context.StaticContext.TypeModel);
                rs.add(element);
            }

            processAttributes(node, idrefs, rs, context);
            processChildNodes(node, idrefs, rs, context);

            return(rs.Sequence);
        }
Пример #23
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected org.eclipse.wst.xml.xpath2.api.Item get_single_arg(org.eclipse.wst.xml.xpath2.api.ResultSequence rs) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        protected internal virtual Item get_single_arg(ResultSequence rs)
        {
            if (rs.size() != 1)
            {
                DynamicError.throw_type_error();
            }

            return(rs.first());
        }
Пример #24
0
        // voodoo 2
        /// <summary>
        /// Actual equality operation for fs_eq_value.
        /// </summary>
        /// <param name="args">
        ///            input arguments. </param>
        /// <param name="type">
        ///            type of the arguments. </param>
        /// <param name="mname">
        ///            Method name for template simulation. </param>
        /// <param name="dynamicContext">
        ///             Dynamic error. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of the operation. </returns>
        public static ResultSequence do_cmp_value_op(ICollection args, Type type, string mname, DynamicContext context)
        {
            // sanity check args + convert em
            if (args.Count != 2)
            {
                DynamicError.throw_type_error();
            }

            ICollection cargs = value_convert_args(args);

            if (cargs.Count == 0)
            {
                return(ResultBuffer.EMPTY);
            }

            // make sure arugments are comparable by equality
            IEnumerator argi = cargs.GetEnumerator();

            argi.MoveNext();
            Item arg = ((ResultSequence)argi.Current).first();

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

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

            if (!(type.IsInstanceOfType(arg)))
            {
                DynamicError.throw_type_error();
            }
            try
            {
                Type[]   margsdef  = new Type[] { type };
                Type[]   margsdef2 = new Type[] { typeof(AnyType), typeof(DynamicContext) };
                object[] margs3    = new object[] { mname, margsdef2 };
                var      v1        = typeof(GenericIComparer)
                                     .GetMethod("GetComparer");
                var v2     = v1.MakeGenericMethod(margsdef);
                var method = (MethodBase)v2.Invoke(null, margs3);

                object[] margs = new object[] { arg2.first(), context };

                object[] real_args = new object[] { arg, margs };

                bool cmpres = (bool)method.Invoke(arg, margs);

                return(ResultSequenceFactory.create_new(new XSBoolean(cmpres)));
            }
            catch
            {
                Debug.Assert(false);
                throw new Exception("cannot compare using method " + mname);
            }
        }
Пример #25
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected org.eclipse.wst.xml.xpath2.api.Item convertArg(AnyType arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        protected internal virtual Item convertArg(AnyType arg)
        {
            ResultSequence rs = ResultSequenceFactory.create_new(arg);

            rs = constructor(rs);
            Item carg = rs.first();

            return(carg);
        }
Пример #26
0
        /// <summary>
        /// Evaluate the function using the arguments passed.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <param name="sc">
        ///            Result of static context operation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of the fn:dateTime operation. </returns>
        public static ResultSequence dateTime(ICollection args, StaticContext sc)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            // get args
            IEnumerator argiter = cargs.GetEnumerator();

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

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

            // if either of the parameter is an empty sequence, the result
            // is an empty sequence
            if (arg1 == null || arg2 == null || arg1.empty() || arg2.empty())
            {
                return(ResultBuffer.EMPTY);
            }
            XSDate param1 = (XSDate)arg1.first();
            XSTime param2 = (XSTime)arg2.first();

            Calendar cal = Calendar.getInstance();

            cal.set(param1.year(), param1.month() - 1, param1.day());
            cal.set(Calendar.HOUR_OF_DAY, param2.hour());
            cal.set(Calendar.MINUTE, param2.minute());
            cal.set(Calendar.SECOND, (int)Math.Floor(param2.second()));
            cal.set(Calendar.MILLISECOND, 0);

            XSDuration dateTimeZone = param1.tz();
            XSDuration timeTimeZone = param2.tz();

            if ((dateTimeZone != null && timeTimeZone != null) && !dateTimeZone.StringValue.Equals(timeTimeZone.StringValue))
            {
                // it's an error, if the arguments have different timezones
                throw DynamicError.inconsistentTimeZone();
            }
            else if (dateTimeZone == null && timeTimeZone != null)
            {
                return(new XSDateTime(cal, timeTimeZone));
            }
            else if (dateTimeZone != null && timeTimeZone == null)
            {
                return(new XSDateTime(cal, dateTimeZone));
            }
            else if ((dateTimeZone != null && timeTimeZone != null) && dateTimeZone.StringValue.Equals(timeTimeZone.StringValue))
            {
                return(new XSDateTime(cal, dateTimeZone));
            }
            else
            {
                return(new XSDateTime(cal, null));
            }
        }
Пример #27
0
        /// <summary>
        /// Language operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:lang 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 lang(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence lang(ICollection args, EvaluationContext ec)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            // get arg
            IEnumerator citer = cargs.GetEnumerator();

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

            if (cargs.Count == 1)
            {
                if (ec.ContextItem == null)
                {
                    throw DynamicError.contextUndefined();
                }
                arg2 = (AnyType)ec.ContextItem;
            }
            else
            {
                citer.MoveNext();
                arg2 = (ResultSequence)citer.Current;
            }

            string lang = "";

            if (!(arg1 == null || arg1.empty()))
            {
                lang = ((XSString)arg1.first()).value();
            }


            if (!(arg2.first() is NodeType))
            {
                throw DynamicError.invalidType();
            }

            NodeType an = (NodeType)arg2.first();

            return(new XSBoolean(test_lang(an.node_value(), lang)));
        }
Пример #28
0
        /// <summary>
        /// Creates a new ResultSequence consisting of the extractable String in the
        /// supplied ResultSequence
        /// </summary>
        /// <param name="arg">
        ///            The ResultSequence from which to extract the String </param>
        /// <returns> New ResultSequence consisting of the supplied String </returns>
        /// <exception cref="DynamicError"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence constructor(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public override ResultSequence constructor(ResultSequence arg)
        {
            if (arg.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            //AnyAtomicType aat = (AnyAtomicType) arg.first();
            Item aat = arg.first();

            return(new XSString(aat.StringValue));
        }
Пример #29
0
        /// <summary>
        /// Creates a new ResultSequence consisting of the retrievable float in the
        /// supplied ResultSequence
        /// </summary>
        /// <param name="arg">
        ///            The ResultSequence from which to extract the float </param>
        /// <returns> New ResultSequence consisting of the float supplied </returns>
        /// <exception cref="DynamicError"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence constructor(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public override ResultSequence constructor(ResultSequence arg)
        {
            if (arg.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            AnyType aat = (AnyType)arg.first();

            if (aat is XSDuration || aat is CalendarType || aat is XSBase64Binary || aat is XSHexBinary || aat is XSAnyURI)
            {
                throw DynamicError.invalidType();
            }

            if (!(aat.string_type().Equals("xs:string") || aat is NodeType || aat.string_type().Equals("xs:untypedAtomic") || aat.string_type().Equals("xs:boolean") || aat is NumericType))
            {
                throw DynamicError.cant_cast(null);
            }


            try
            {
                float f;
                if (aat.StringValue.Equals("INF"))
                {
                    f = float.PositiveInfinity;
                }
                else if (aat.StringValue.Equals("-INF"))
                {
                    f = float.NegativeInfinity;
                }
                else if (aat is XSBoolean)
                {
                    if (aat.StringValue.Equals("true"))
                    {
                        f = 1.0f;
                    }
                    else
                    {
                        f = 0.0f;
                    }
                }
                else
                {
                    f = Convert.ToSingle(aat.StringValue);
                }
                return(new XSFloat(f));
            }
            catch (System.FormatException)
            {
                throw DynamicError.cant_cast(null);
            }
        }
Пример #30
0
        /// <summary>
        /// Resolve-QName operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <param name="sc">
        ///            Result of static context operation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:resolve-QName 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 resolve_QName(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.StaticContext sc) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence resolve_QName(ICollection args, StaticContext sc)
        {
            //Collection cargs = Function.convert_arguments(args, expected_args());
            ICollection cargs = args;

            // get args
            IEnumerator argiter = cargs.GetEnumerator();

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

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

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

            string name = ((XSString)arg1.first()).value();

            QName qn = QName.parse_QName(name);

            if (qn == null)
            {
                throw DynamicError.lexical_error(null);
            }

            ElementType xselement = (ElementType)arg2.first();
            Element     element   = (Element)xselement.node_value();

            if (!string.ReferenceEquals(qn.prefix(), null))
            {
                string namespaceURI = element.lookupNamespaceURI(qn.prefix());

                if (string.ReferenceEquals(namespaceURI, null))
                {
                    throw DynamicError.invalidPrefix();
                }
                qn.set_namespace(namespaceURI);
            }
            else
            {
                if (qn.local().Equals(element.LocalName) && element.isDefaultNamespace(element.NamespaceURI))
                {
                    qn.set_namespace(element.NamespaceURI);
                }
            }


            return(qn);
        }