Example #1
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));
            }
        }
Example #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected static boolean hasValue(org.eclipse.wst.xml.xpath2.api.ResultBuffer rs, org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType item, org.eclipse.wst.xml.xpath2.api.DynamicContext context, String collationURI) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        protected internal static bool hasValue(ResultBuffer rs, AnyAtomicType item, DynamicContext context, string collationURI)
        {
            XSString itemStr = new XSString(item.StringValue);

            for (IEnumerator i = rs.iterator(); i.MoveNext();)
            {
                AnyType at = (AnyType)i.Current;

                if (!(at is CmpEq))
                {
                    continue;
                }

                if (isBoolean(item, at))
                {
                    XSBoolean boolat = (XSBoolean)at;
                    if (boolat.eq(item, context))
                    {
                        return(true);
                    }
                }

                if (isNumeric(item, at))
                {
                    NumericType numericat = (NumericType)at;
                    if (numericat.eq(item, context))
                    {
                        return(true);
                    }
                }

                if (isDuration(item, at))
                {
                    XSDuration durat = (XSDuration)at;
                    if (durat.eq(item, context))
                    {
                        return(true);
                    }
                }

                if (needsStringComparison(item, at))
                {
                    XSString xstr1 = new XSString(at.StringValue);
                    if (FnCompare.compare_string(collationURI, xstr1, itemStr, context).Equals(System.Numerics.BigInteger.Zero))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected static boolean hasValue(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType itema, org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType itemb, org.eclipse.wst.xml.xpath2.api.DynamicContext context, String collationURI) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        protected internal static bool hasValue(AnyType itema, AnyType itemb, DynamicContext context, string collationURI)
        {
            XSString itemStr = new XSString(itema.StringValue);

            if (isBoolean(itema, itemb))
            {
                XSBoolean boolat = (XSBoolean)itema;
                if (boolat.eq(itemb, context))
                {
                    return(true);
                }
            }

            if (isNumeric(itema, itemb))
            {
                NumericType numericat = (NumericType)itema;
                if (numericat.eq(itemb, context))
                {
                    return(true);
                }
            }

            if (isDuration(itema, itemb))
            {
                XSDuration durat = (XSDuration)itema;
                if (durat.eq(itemb, context))
                {
                    return(true);
                }
            }

            if (needsStringComparison(itema, itemb))
            {
                XSString xstr1 = new XSString(itema.StringValue);
                if (FnCompare.compare_string(collationURI, xstr1, itemStr, context).Equals(System.Numerics.BigInteger.Zero))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #4
0
        /// <summary>
        /// Years-from-Duration operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:years-from-duration 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 years_from_duration(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence years_from_duration(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);
            }

            XSDuration ymd = (XSDuration)arg1.first();

            int res = ymd.year();

            if (ymd.negative())
            {
                res *= -1;
            }

            return(new XSInteger(new System.Numerics.BigInteger(res)));
        }
        /// <summary>
        /// Seconds-from-Duration operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:seconds-from-duration 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 seconds_from_duration(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence seconds_from_duration(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);
            }

            XSDuration dtd = (XSDuration)arg1.first();

            double res = dtd.seconds();

            if (dtd.negative())
            {
                res *= -1;
            }

            return(new XSDecimal(new decimal(res)));
        }
Example #6
0
        /// <summary>
        /// Index-Of operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <param name="dynamicContext"> </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:index-of operation. </returns>
        public static ResultSequence index_of(ICollection args, DynamicContext dc)
        {
            Function.convert_arguments(args, expected_args());

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

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

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

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

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

            string collationUri = dc.CollationProvider.DefaultCollation;

            if (citer.MoveNext())
            {
                ResultSequence arg3 = (ResultSequence)citer.Current;
                if (!arg3.empty())
                {
                    XSString collation = (XSString)arg3.first();
                    collationUri = collation.StringValue;
                }
            }

            ResultBuffer  rb = new ResultBuffer();
            AnyAtomicType at = (AnyAtomicType)arg2.first();

            get_comparable(at);

            int index = 1;

            for (var i = arg1.iterator(); i.MoveNext();)
            {
                AnyType cmptype = (AnyType)i.Current;
                get_comparable(cmptype);

                if (!(at is CmpEq))
                {
                    continue;
                }

                if (isBoolean(cmptype, at))
                {
                    XSBoolean boolat = (XSBoolean)cmptype;
                    if (boolat.eq(at, dc))
                    {
                        rb.add(new XSInteger(new System.Numerics.BigInteger(index)));
                    }
                }
                else
                {
                    if (isNumeric(cmptype, at))
                    {
                        NumericType numericat = (NumericType)at;
                        if (numericat.eq(cmptype, dc))
                        {
                            rb.add(new XSInteger(new System.Numerics.BigInteger(index)));
                        }
                    }
                    else
                    {
                        if (isDuration(cmptype, at))
                        {
                            XSDuration durat = (XSDuration)at;
                            if (durat.eq(cmptype, dc))
                            {
                                rb.add(new XSInteger(new System.Numerics.BigInteger(index)));
                            }
                        }
                        else
                        {
                            if (at is QName && cmptype is QName)
                            {
                                QName qname = (QName)at;
                                if (qname.eq(cmptype, dc))
                                {
                                    rb.add(new XSInteger(new System.Numerics.BigInteger(index)));
                                }
                            }
                            else
                            {
                                if (needsStringComparison(cmptype, at))
                                {
                                    XSString xstr1   = new XSString(cmptype.StringValue);
                                    XSString itemStr = new XSString(at.StringValue);
                                    if (FnCompare.compare_string(collationUri, xstr1, itemStr, dc).Equals(System.Numerics.BigInteger.Zero))
                                    {
                                        rb.add(new XSInteger(new System.Numerics.BigInteger(index)));
                                    }
                                }
                            }
                        }
                    }
                }

                index++;
            }

            return(rb.Sequence);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="schema">
 ///            Schema information of document. May be null </param>
 /// <param name="doc">
 ///            Document [root] node of XML source.
 /// @since 2.0 </param>
 public DefaultDynamicContext(TypeModel schema) : base(schema)
 {
     _focus            = null;
     _tz               = new XSDayTimeDuration(0, 5, 0, 0, true);
     _loaded_documents = new Hashtable();
 }