Пример #1
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);
        }
Пример #2
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));
        }
Пример #3
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);
        }
Пример #4
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());
            }
        }
Пример #5
0
        /// <summary>
        /// Deep-Equal boolean operation.
        /// </summary>
        /// <param name="one">
        ///            input1 xpath expression/variable. </param>
        /// <param name="two">
        ///            input2 xpath expression/variable. </param>
        /// <param name="context">
        ///            Current dynamic context </param>
        /// <returns> Result of fn:deep-equal operation. </returns>
        public static bool deep_equal(ResultSequence one, ResultSequence two, EvaluationContext context, string collationURI)
        {
            if (one.empty() && two.empty())
            {
                return(true);
            }

            if (one.size() != two.size())
            {
                return(false);
            }

            var onei = one.iterator();
            var twoi = two.iterator();

            while (onei.MoveNext())
            {
                AnyType a = (AnyType)onei.Current;
                twoi.MoveNext();
                AnyType b = (AnyType)twoi.Current;

                if (!deep_equal(a, b, context, collationURI))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #6
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)));
        }
Пример #7
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);
        }
Пример #8
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);
        }
Пример #9
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);
        }
Пример #10
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);
        }
Пример #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>
        /// 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();
            }
        }
Пример #13
0
        /// <summary>
        /// Doc operation.
        /// </summary>
        /// <param name="args">
        ///            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:doc 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 doc(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence doc(ICollection args, EvaluationContext ec)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

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

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

            if (arg1 == null || arg1.empty())
            {
                return(ResultSequenceFactory.create_new());
            }

            string uri = ((XSString)arg1.item(0)).value();

            DynamicContext dc       = ec.DynamicContext;
            var            resolved = dc.resolveUri(uri);

            if (resolved == null)
            {
                throw DynamicError.invalid_doc(null);
            }

            Document doc = dc.getDocument(resolved);

            if (doc == null)
            {
                throw DynamicError.doc_not_found(null);
            }

            return(new DocType(doc, ec.StaticContext.TypeModel));
        }
Пример #14
0
        /// <summary>
        /// Unordered operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:unordered operation. </returns>
        public static ResultSequence unordered(ICollection args)
        {
            Debug.Assert(args.Count == 1);

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

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

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

            // XXX lame
            ArrayList tmp = new ArrayList();

            for (IEnumerator i = arg.iterator(); i.MoveNext();)
            {
                tmp.Add(i.Current);
            }

            throw new Exception();
            //Collections.shuffle(tmp);

            //ResultBuffer rb = new ResultBuffer();
            //for (IEnumerator i = tmp.GetEnumerator(); i.MoveNext();)
            //{
            //	rb.add((AnyType) i.Current);
            //}

            //return rb.Sequence;
        }
Пример #15
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);
        }
Пример #16
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);
        }
Пример #17
0
        /// <summary>
        /// Min operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <param name="dynamic">
        ///            Dynamic context </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:min 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 min(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext context) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence min(ICollection args, DynamicContext context)
        {
            ResultSequence arg = FnMax.get_arg(args, typeof(CmpLt));

            if (arg.empty())
            {
                return(ResultSequenceFactory.create_new());
            }

            CmpLt max = null;

            TypePromoter tp = new ComparableTypePromoter();

            tp.considerSequence(arg);

            for (var i = arg.iterator(); i.MoveNext();)
            {
                AnyAtomicType conv = tp.promote((AnyType)i.Current);

                if (conv != null)
                {
                    if (conv is XSDouble && ((XSDouble)conv).nan() || conv is XSFloat && ((XSFloat)conv).nan())
                    {
                        return(ResultSequenceFactory.create_new(tp.promote(new XSFloat(float.NaN))));
                    }
                    if (max == null || ((CmpLt)conv).lt((AnyType)max, context))
                    {
                        max = (CmpLt)conv;
                    }
                }
            }
            return(ResultSequenceFactory.create_new((AnyType)max));
        }
Пример #18
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 inScopePrefixes(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext dc) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence inScopePrefixes(ICollection args, DynamicContext dc)
        {
            //		Collection cargs = Function.convert_arguments(args, expected_args());
            ICollection cargs = args;
            var         i     = cargs.GetEnumerator();

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

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

            ResultBuffer rs = new ResultBuffer();

            Item anytype = arg1.item(0);

            if (!(anytype is ElementType))
            {
                throw new DynamicError(TypeError.invalid_type(null));
            }

            ElementType element    = (ElementType)anytype;
            IList       prefixList = lookupPrefixes(element);

            createPrefixResultSet(rs, prefixList);
            return(rs.Sequence);
        }
Пример #19
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);
        }
Пример #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)));
        }
        /// <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);
        }
Пример #22
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));
        }
Пример #23
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));
            }
        }
Пример #24
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>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence adjustDate(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext dc) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence adjustDate(ICollection args, DynamicContext dc)
        {
            ICollection cargs = Function.convert_arguments(args, expectedArgs());

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

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

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

            if (argiter.MoveNext())
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                arg2 = (ResultSequence)argiter.Current;
            }

            XSDate            date     = (XSDate)arg1.item(0);
            XSDayTimeDuration timezone = null;

            if (arg2.empty())
            {
                if (date.timezoned())
                {
                    XSDate localized = new XSDate(date.calendar(), null);
                    return(localized);
                }
                return(arg1);
            }

            timezone = (XSDayTimeDuration)arg2.item(0);
            if (timezone.lt(minDuration, dc) || timezone.gt(maxDuration, dc))
            {
                throw DynamicError.invalidTimezone();
            }

            if (date.tz() == null)
            {
                return(new XSDate(date.calendar(), timezone));
            }

            XMLGregorianCalendar xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar)date.normalizeCalendar(date.calendar(), date.tz()));

            Duration duration = _datatypeFactory.newDuration(timezone.StringValue);

            xmlCalendar.add(duration);

            return(new XSDate(xmlCalendar.toGregorianCalendar(), timezone));
        }
Пример #25
0
        /// <summary>
        /// Exists operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:exists 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 exists(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence exists(ICollection args)
        {
            Debug.Assert(args.Count == 1);

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

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

            return(XSBoolean.valueOf(!arg1.empty()));
        }
Пример #26
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));
        }
Пример #27
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);
            }
        }
Пример #28
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);
        }
Пример #29
0
        /// <summary>
        /// Tokenize operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:tokenize operation. </returns>
        public static ResultSequence tokenize(ICollection args)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            ResultBuffer rs = new ResultBuffer();

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

            argiter.MoveNext();
            ResultSequence arg1 = (ResultSequence)argiter.Current;
            string         str1 = "";

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

            argiter.MoveNext();
            ResultSequence arg2    = (ResultSequence)argiter.Current;
            string         pattern = ((XSString)arg2.first()).value();
            string         flags   = null;

            if (argiter.MoveNext())
            {
                ResultSequence flagRS = null;
                flagRS = (ResultSequence)argiter.Current;
                flags  = flagRS.first().StringValue;
                if (validflags.IndexOf(flags, StringComparison.Ordinal) == -1 && flags.Length > 0)
                {
                    throw DynamicError.regex_flags_error(null);
                }
            }

            try
            {
                ArrayList ret = tokenize(pattern, flags, str1);

                for (IEnumerator retIter = ret.GetEnumerator(); retIter.MoveNext();)
                {
                    rs.add(new XSString((string)retIter.Current));
                }
            }
            catch (Exception)
            {
                throw DynamicError.regex_error(null);
            }

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

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

            argiter.MoveNext();
            ResultSequence arg1 = (ResultSequence)argiter.Current;
            string         str1 = "";
            string         str2 = "";

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

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

            if (!(arg2 == null || arg2.empty()))
            {
                str2 = ((XSString)arg2.first()).value();
            }

            int str1len = str1.Length;
            int str2len = str2.Length;

            if (str2len == 0)
            {
                return(new XSString(str1));
            }

            int index = str1.IndexOf(str2, StringComparison.Ordinal);

            if (index == -1)
            {
                return(new XSString(""));
            }

            string result = "";

            if ((index + str2len) < str1len)
            {
                index += str2len;
                result = str1.Substring(index, str1len - index);
            }

            return(new XSString(result));
        }