/// <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); }
/// <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); }
//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> /// 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); }
/// <summary> /// String operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:string 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(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence @string(ICollection args, EvaluationContext ec) { Debug.Assert(args.Count == 0 || args.Count == 1); ResultSequence arg1 = null; if (args.Count == 0) { // support for arity = 0 return(getResultSetForArityZero(ec)); } else { var i = args.GetEnumerator(); i.MoveNext(); arg1 = (ResultSequence)i.Current; } // sanity check args if (arg1.size() > 1) { throw new DynamicError(TypeError.invalid_type(null)); } ResultBuffer rs = new ResultBuffer(); if (arg1.empty()) { rs.add(new XSString("")); } else { Item at = arg1.first(); rs.add(new XSString(at.StringValue)); } return(rs.Sequence); }
/// <summary> /// Evaluate arguments. /// </summary> /// <param name="args"> /// argument expressions. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of evaluation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence evaluate(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public override ResultSequence evaluate(ICollection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) { IEnumerator argIterator = args.GetEnumerator(); argIterator.MoveNext(); ResultSequence argSequence = (ResultSequence)argIterator.Current; AnyAtomicType zero = ZERO; if (argIterator.MoveNext()) { ResultSequence zeroSequence = (ResultSequence)argIterator.Current; if (zeroSequence.size() != 1) { throw new DynamicError(TypeError.invalid_type(null)); } if (!(zeroSequence.first() is AnyAtomicType)) { throw new DynamicError(TypeError.invalid_type(zeroSequence.first().StringValue)); } zero = (AnyAtomicType)zeroSequence.first(); } return(sum(argSequence, zero)); }
/// <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); }
/// <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)); }
/// <summary> /// @since 1.1 /// </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static DynamicError invalidType() throws DynamicError public static DynamicError invalidType() { throw new DynamicError(TypeError.invalid_type(null)); }
/// <summary> /// Number 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:number operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble fn_number(org.eclipse.wst.xml.xpath2.api.ResultSequence arg, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static XSDouble fn_number(ResultSequence arg, EvaluationContext ec) { if (arg.size() > 1) { throw new DynamicError(TypeError.invalid_type("bad argument passed to fn:number()")); } else if (arg.size() == 1) { Item at = arg.first(); /* * if (!(at instanceof AnyAtomicType)) * DynamicError.throw_type_error(); */ if (at is AnyAtomicType) { if ((at is XSDouble)) { return((XSDouble)at); } else if ((at is XSFloat)) { float value = ((XSFloat)at).float_value(); if (float.IsNaN(value)) { return(new XSDouble(double.NaN)); } else if (value == float.NegativeInfinity) { return(new XSDouble(double.NegativeInfinity)); } else if (value == float.PositiveInfinity) { return(new XSDouble(double.PositiveInfinity)); } else { return(new XSDouble((double)value)); } } else { XSDouble d = XSDouble.parse_double(at.StringValue); return(d != null ? d : new XSDouble(double.NaN)); } } else if (at is NodeType) { XSDouble d = XSDouble.parse_double((FnData.atomize(at)).StringValue); return(d != null ? d : new XSDouble(double.NaN)); } } else { return(new XSDouble(double.NaN)); } // unreach return(null); }