Example #1
0
        /// <summary>
        /// Creates a new ResultSequence consisting of the extractable long in the
        /// supplied ResultSequence
        /// </summary>
        /// <param name="arg">
        ///            The ResultSequence from which the long is to be extracted </param>
        /// <returns> New ResultSequence consisting of the 'long' 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 a long.
            Item aat = arg.first();

            try
            {
                System.Numerics.BigInteger.TryParse(aat.StringValue, out System.Numerics.BigInteger bigInt);

                // doing the range checking
                System.Numerics.BigInteger min = new System.Numerics.BigInteger(-9223372036854775808L);
                System.Numerics.BigInteger max = new System.Numerics.BigInteger(9223372036854775807L);

                if (bigInt.CompareTo(min) < 0 || bigInt.CompareTo(max) > 0)
                {
                    // invalid input
                    DynamicError.throw_type_error();
                }

                return(new XSLong(bigInt));
            }
            catch (System.FormatException)
            {
                throw DynamicError.cant_cast(null);
            }
        }
Example #2
0
        /// <summary>
        /// Creates a new ResultSequence consisting of the extractable gMonth in the
        /// supplied ResultSequence
        /// </summary>
        /// <param name="arg">
        ///            The ResultSequence from which the gMonth is to be extracted </param>
        /// <returns> New ResultSequence consisting of the supplied month </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);
            }

            XSGMonth val = castGMonth(aat);

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

            return(val);
        }
        /// <summary>
        /// Creates a new ResultSequence consisting of the extractable unsignedShort
        /// in the supplied ResultSequence
        /// </summary>
        /// <param name="arg">
        ///            The ResultSequence from which the unsignedShort is to be extracted </param>
        /// <returns> New ResultSequence consisting of the 'unsignedShort' 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 a unsignedShort.
            Item aat = arg.first();

            try
            {
                System.Numerics.BigInteger.TryParse(aat.StringValue, out System.Numerics.BigInteger bigInt);

                // doing the range checking
                // min value is 0
                // max value is 65535
                System.Numerics.BigInteger min = new System.Numerics.BigInteger(0);
                System.Numerics.BigInteger max = new System.Numerics.BigInteger(65535L);

                if (bigInt.CompareTo(min) < 0 || bigInt.CompareTo(max) > 0)
                {
                    // invalid input
                    throw DynamicError.cant_cast(null);
                }

                return(new XSUnsignedShort(bigInt));
            }
            catch (System.FormatException)
            {
                throw DynamicError.cant_cast(null);
            }
        }
Example #4
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);
            }
        }
Example #5
0
        /// <summary>
        /// Creates a new result sequence consisting of the retrievable decimal
        /// number in the supplied result sequence
        /// </summary>
        /// <param name="arg">
        ///            The result sequence from which to extract the decimal number. </param>
        /// <exception cref="DynamicError"> </exception>
        /// <returns> A new result sequence consisting of the decimal 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 (aat.StringValue.IndexOf("-INF", StringComparison.Ordinal) != -1)
            {
                throw DynamicError.cant_cast(null);
            }

            if (!isLexicalValue(aat.StringValue))
            {
                throw DynamicError.invalidLexicalValue();
            }

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

            try
            {
                // XPath doesn't allow for converting Exponents to Decimal values.

                return(castDecimal(aat));
            }
            catch (System.FormatException)
            {
                throw DynamicError.cant_cast(null);
            }
        }
Example #6
0
        /// <summary>
        /// Initialises using a String represented number
        /// </summary>
        /// <param name="init">
        ///            String representation of the number to be stored </param>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public XSDouble(String init) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public XSDouble(string init)
        {
            try
            {
                if (init.Equals("-INF"))
                {
                    _value = new double?(double.NegativeInfinity);
                }
                else if (init.Equals("INF"))
                {
                    _value = new double?(double.PositiveInfinity);
                }
                else
                {
                    _value = Convert.ToDouble(init);
                }
            }
            catch (System.FormatException)
            {
                throw DynamicError.cant_cast(null);
            }
        }
Example #7
0
        /// <summary>
        /// Creates a new ResultSequence consisting of the extractable time from the
        /// supplied ResultSequence
        /// </summary>
        /// <param name="arg">
        ///            The ResultSequence from which to extract the time </param>
        /// <returns> New ResultSequence consisting of the supplied time </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 (!isCastable(aat))
            {
                throw DynamicError.invalidType();
            }

            CalendarType t = castTime(aat);

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

            return(t);
        }
Example #8
0
        /// <summary>
        /// Creates a new result sequence consisting of the retrievable date value in
        /// the supplied result sequence
        /// </summary>
        /// <param name="arg">
        ///            The result sequence from which to extract the date value. </param>
        /// <exception cref="DynamicError"> </exception>
        /// <returns> A new result sequence consisting of the date value 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 (!isCastable(aat))
            {
                throw DynamicError.invalidType();
            }

            XSDate dt = castDate(aat);

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

            return(dt);
        }
Example #9
0
        /// <summary>
        /// Creates a new result sequence consisting of the retrievable boolean value
        /// in the supplied result sequence
        /// </summary>
        /// <param name="arg">
        ///            The result sequence from which to extract the boolean value. </param>
        /// <exception cref="DynamicError"> </exception>
        /// <returns> A new result sequence consisting of the boolean value 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 anyType = arg.first();

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

            string str_value = anyType.StringValue;


            if (!(isCastable(anyType, str_value)))
            {
                throw DynamicError.cant_cast(null);
            }

            return(XSBoolean.valueOf(!isFalse(str_value)));
        }
Example #10
0
        /// <summary>
        /// Creates a new ResultSequence consisting of the hexBinary value
        /// </summary>
        /// <param name="arg">
        ///            The ResultSequence from which to construct hexBinary value </param>
        /// <returns> New ResultSequence representing hexBinary value </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 CalendarType || aat is XSBoolean || aat is XSAnyURI)
            {
                throw DynamicError.invalidType();
            }

            string str_value = aat.StringValue;

            if (!(aat is XSHexBinary || aat is XSString || aat is XSUntypedAtomic || aat is XSBase64Binary))
            {
                throw DynamicError.cant_cast(null);
            }

            if (aat is XSUntypedAtomic || aat is XSString)
            {
                string[] nonHexValues = null;
                try
                {
                    nonHexValues = str_value.Split("[0-9a-fA-F]", true);
                }
                catch (Exception)
                {
                    throw DynamicError.throw_type_error();
                }

                string[] binValues = null;
                try
                {
                    binValues = str_value.Split("[0-1]", true);
                }
                catch (Exception)
                {
                    throw DynamicError.throw_type_error();
                }

                if (nonHexValues.Length > 0 || binValues.Length == 0)
                {
                    throw DynamicError.invalidForCastConstructor();
                }
            }


            sbyte[] decodedValue = null;

            if (aat is XSBase64Binary)
            {
                throw new Exception();
                //decodedValue = Base64.decode(str_value);
                //decodedValue = HexBin.encode(decodedValue).Bytes;
            }
            else
            {
                decodedValue = str_value.GetBytes();
            }

            if (decodedValue != null)
            {
                return(new XSHexBinary(StringHelperClass.NewString(decodedValue)));
            }
            else
            {
                // invalid hexBinary string
                throw DynamicError.throw_type_error();
            }
        }