Beispiel #1
0
        public virtual ResultSequence getVariable([email protected] name)
        {
            object @var = dc.get_variable(new QName(name));

            if (@var == null)
            {
                return(ResultBuffer.EMPTY);
            }
            if (@var is ResultSequence)
            {
                return((ResultSequence)@var);
            }
            return(ResultBuffer.wrap((Item)@var));
        }
Beispiel #2
0
        /// <summary>
        /// Name 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: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 name(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence name(ICollection args, EvaluationContext ec)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            // get arg
            ResultSequence arg1 = null;

            if (cargs.Count == 0)
            {
                if (ec.ContextItem == null)
                {
                    throw DynamicError.contextUndefined();
                }
                else
                {
                    arg1 = ResultBuffer.wrap(ec.ContextItem);
                }
            }
            else
            {
                var i = cargs.GetEnumerator();
                i.MoveNext();
                arg1 = (ResultSequence)i.Current;
            }

            if (arg1.empty())
            {
                return(new XSString(""));
            }

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

            QName name = an.node_name();

            string sname = "";

            if (name != null)
            {
                sname = name.StringValue;
            }

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

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

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

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

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

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

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

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

            if (has_double)
            {
                has_float = false;
            }

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

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

                    Item arg = rs.item(0);

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

            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// Root operation.
        /// </summary>
        /// <param name="arg">
        ///            Result from the expressions evaluation. </param>
        /// <param name="dc">
        ///            Result of dynamic context operation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:root operation. </returns>
        public static ResultSequence fn_root(ICollection args, EvaluationContext ec)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            if (cargs.Count > 1)
            {
                throw new DynamicError(TypeError.invalid_type(null));
            }

            ResultSequence arg = null;

            if (cargs.Count == 0)
            {
                if (ec.ContextItem == null)
                {
                    throw DynamicError.contextUndefined();
                }
                arg = ResultBuffer.wrap(ec.ContextItem);
            }
            else
            {
                var i = cargs.GetEnumerator();
                i.MoveNext();
                arg = (ResultSequence)i.Current;
            }

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

            Item aa = arg.item(0);

            if (!(aa is NodeType))
            {
                throw new DynamicError(TypeError.invalid_type(null));
            }

            NodeType nt = (NodeType)aa;

            // ok we got a sane argument... own it.
            Node root = nt.node_value();

            while (root != null && !(root is Document))
            {
                Node newroot = root.ParentNode;
                if (newroot == null && root is Attr)
                {
                    newroot = ((Attr)root).OwnerElement;
                }

                // found it
                if (newroot == null)
                {
                    break;
                }

                root = newroot;
            }

            return(NodeType.dom_to_xpath(root, ec.StaticContext.TypeModel));
        }