/// <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); } }
/// <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(); } }
/// <summary> /// Unary operation on the arguments. /// </summary> /// <param name="args"> /// input arguments. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of the operation. </returns> public static ResultSequence fs_plus_unary(ICollection args) { // make sure we got only one arg if (args.Count != 1) { DynamicError.throw_type_error(); } var i = args.GetEnumerator(); i.MoveNext(); ResultSequence arg = (ResultSequence)i.Current; // make sure we got only one numeric atom if (arg.size() != 1) { DynamicError.throw_type_error(); } Item at = arg.first(); if (!(at is NumericType)) { DynamicError.throw_type_error(); } // no-op return(arg); }
/// <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)); }
/// <summary> /// Mathematical multiplication between this duration stored and the supplied /// duration of time (of type XSYearMonthDuration) /// </summary> /// <param name="arg"> /// The duration of time to multiply by </param> /// <returns> New XSYearMonthDuration representing the resulting duration /// after the multiplication </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 times(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public virtual ResultSequence times(ResultSequence arg) { ResultSequence convertedRS = arg; if (arg.size() == 1) { Item argValue = arg.first(); if (argValue is XSDecimal) { convertedRS = ResultSequenceFactory.create_new(new XSDouble(argValue.StringValue)); } } XSDouble val = (XSDouble)NumericType.get_single_type(convertedRS, typeof(XSDouble)); if (val.nan()) { throw DynamicError.nan(); } if (val.infinite()) { throw DynamicError.overflowDateTime(); } int res = (int)Math.Round(monthValue() * val.double_value()); return(ResultSequenceFactory.create_new(new XSYearMonthDuration(res))); }
/// <summary> /// Mathematical subtraction between this time stored and the supplied /// representation. This supplied representation must be of either type /// XSTime (in which case the result is the duration of time between these /// two times) or a XSDayTimeDuration (in which case the result is the time /// when this duration is subtracted from the time stored). /// </summary> /// <param name="arg"> /// The representation to subtract (either XSTim or /// XDTDayTimeDuration) </param> /// <returns> A ResultSequence representing the result of the subtraction </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence minus(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public virtual ResultSequence minus(ResultSequence arg) { if (arg.size() != 1) { DynamicError.throw_type_error(); } Item at = arg.first(); if (!(at is XSTime) && !(at is XSDayTimeDuration)) { throw DynamicError.throw_type_error(); } if (at is XSTime) { return(minusXSTimeDuration(at)); } if (at is XSDayTimeDuration) { return(minusXSDayTimeDuration(at)); } return(null); // unreach }
/// <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); }
/// <summary> /// Mathematical integer division operator between this XSDouble and the /// supplied ResultSequence. /// </summary> /// <param name="arg"> /// The ResultSequence to perform an integer division with </param> /// <returns> A XSInteger consisting of the result of the mathematical integer /// division. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence idiv(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public override ResultSequence idiv(ResultSequence arg) { ResultSequence carg = convertResultSequence(arg); XSDouble val = (XSDouble)get_single_type(carg, typeof(XSDouble)); if (this.nan() || val.nan()) { throw DynamicError.numeric_overflow("Dividend or divisor is NaN"); } if (this.infinite()) { throw DynamicError.numeric_overflow("Dividend is infinite"); } if (val.zero()) { throw DynamicError.div_zero(null); } decimal result = new decimal((double_value() / val.double_value())); return(ResultSequenceFactory.create_new(new XSInteger(new BigInteger(result)))); }
/// <summary> /// Creates a new ResultSequence consisting of the extractable unsignedByte /// in the supplied ResultSequence /// </summary> /// <param name="arg"> /// The ResultSequence from which the unsignedByte is to be extracted </param> /// <returns> New ResultSequence consisting of the 'unsignedByte' 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 unsignedByte. 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 255 System.Numerics.BigInteger min = new System.Numerics.BigInteger(0); System.Numerics.BigInteger max = new System.Numerics.BigInteger(255L); if (bigInt.CompareTo(min) < 0 || bigInt.CompareTo(max) > 0) { // invalid input throw DynamicError.cant_cast(null); } return(new XSUnsignedByte(bigInt)); } catch (System.FormatException) { throw DynamicError.cant_cast(null); } }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
private static ArrayList tokenize(string pattern, string flags, string src) { MatchCollection matches = regex(pattern, flags, src); ArrayList tokens = new ArrayList(); int startpos = 0; int endpos = src.Length; foreach (Match match in matches) { string delim = match.Groups[0].Value; if (delim.Length == 0) { throw DynamicError.regex_match_zero_length(null); } string token = src.Substring(startpos, match.Index - startpos); startpos = match.Index + match.Length; tokens.Add(token); } if (startpos < endpos) { string token = src.Substring(startpos, endpos - startpos); tokens.Add(token); } return(tokens); }
/// <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); }
//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()) { DynamicError.throw_type_error(); } throw new DynamicError("XPST0080", "Can't Cast to NOTATION"); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: protected org.eclipse.wst.xml.xpath2.api.Item get_single_arg(org.eclipse.wst.xml.xpath2.api.ResultSequence rs) throws org.eclipse.wst.xml.xpath2.processor.DynamicError protected internal virtual Item get_single_arg(ResultSequence rs) { if (rs.size() != 1) { DynamicError.throw_type_error(); } return(rs.first()); }
/// <summary> ///* /// Check whether the supplied node is of the supplied type /// </summary> /// <param name="at"> /// The node being tested </param> /// <param name="type"> /// The type expected </param> /// <returns> The node being tested </returns> /// <exception cref="DynamicError"> /// If node being tested is not of expected type </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.Item get_single_type(org.eclipse.wst.xml.xpath2.api.Item at, Class type) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static Item get_single_type(Item at, Type type) { if (!type.IsInstanceOfType(at)) { DynamicError.throw_type_error(); } return(at); }
// voodoo 2 /// <summary> /// Actual equality operation for fs_eq_value. /// </summary> /// <param name="args"> /// input arguments. </param> /// <param name="type"> /// type of the arguments. </param> /// <param name="mname"> /// Method name for template simulation. </param> /// <param name="dynamicContext"> /// Dynamic error. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of the operation. </returns> public static ResultSequence do_cmp_value_op(ICollection args, Type type, string mname, DynamicContext context) { // sanity check args + convert em if (args.Count != 2) { DynamicError.throw_type_error(); } ICollection cargs = value_convert_args(args); if (cargs.Count == 0) { return(ResultBuffer.EMPTY); } // make sure arugments are comparable by equality IEnumerator argi = cargs.GetEnumerator(); argi.MoveNext(); Item arg = ((ResultSequence)argi.Current).first(); argi.MoveNext(); ResultSequence arg2 = (ResultSequence)argi.Current; if (arg2.size() != 1) { DynamicError.throw_type_error(); } if (!(type.IsInstanceOfType(arg))) { DynamicError.throw_type_error(); } try { Type[] margsdef = new Type[] { type }; Type[] margsdef2 = new Type[] { typeof(AnyType), typeof(DynamicContext) }; object[] margs3 = new object[] { mname, margsdef2 }; var v1 = typeof(GenericIComparer) .GetMethod("GetComparer"); var v2 = v1.MakeGenericMethod(margsdef); var method = (MethodBase)v2.Invoke(null, margs3); object[] margs = new object[] { arg2.first(), context }; object[] real_args = new object[] { arg, margs }; bool cmpres = (bool)method.Invoke(arg, margs); return(ResultSequenceFactory.create_new(new XSBoolean(cmpres))); } catch { Debug.Assert(false); throw new Exception("cannot compare using method " + mname); } }
/// <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)); } }
/// <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)); }
/// <summary> /// Position 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:position 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 position(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence position(ICollection args, EvaluationContext ec) { Debug.Assert(args.Count == 0); if (ec.ContextItem == null) { throw DynamicError.contextUndefined(); } return(ResultSequenceFactory.create_new(new XSInteger(new System.Numerics.BigInteger(ec.ContextPosition)))); }
public static System.Numerics.BigInteger compare_string(string collationUri, XSString xstr1, XSString xstr2, DynamicContext context) { var collator = context.CollationProvider.getCollation(collationUri); if (collator == null) { throw DynamicError.unsupported_collation(collationUri); } if (xstr1 == null || xstr2 == null) { return(default);
/// <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); } }
/// <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); }
// math /// <summary> /// Mathematical addition operator between this XSDouble and the supplied /// ResultSequence. /// </summary> /// <param name="arg"> /// The ResultSequence to perform an addition with </param> /// <returns> A XSDouble consisting of the result of the mathematical addition. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence plus(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public override ResultSequence plus(ResultSequence arg) { ResultSequence carg = convertResultSequence(arg); Item at = get_single_arg(carg); if (!(at is XSDouble)) { DynamicError.throw_type_error(); } XSDouble val = (XSDouble)at; return(ResultSequenceFactory.create_new(new XSDouble(double_value() + val.double_value()))); }
/// <summary> /// Mathematical subtraction operator between this XSFloat and the supplied /// ResultSequence. /// </summary> /// <param name="arg"> /// The ResultSequence to perform a subtraction with </param> /// <returns> A XSFloat consisting of the result of the mathematical /// subtraction. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence minus(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public override ResultSequence minus(ResultSequence arg) { ResultSequence carg = constructor(arg); Item at = get_single_arg(carg); if (!(at is XSFloat)) { DynamicError.throw_type_error(); } XSFloat val = (XSFloat)at; return(ResultSequenceFactory.create_new(new XSFloat(float_value() - val.float_value()))); }
/// <summary> /// Mathematical division operator between this XSDecimal and the supplied /// ResultSequence. /// </summary> /// <param name="arg"> /// The ResultSequence to perform a division with </param> /// <returns> A XSDecimal consisting of the result of the mathematical /// division. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence div(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public override ResultSequence div(ResultSequence arg) { ResultSequence carg = convertResultSequence(arg); XSDecimal val = (XSDecimal)get_single_type(carg, typeof(XSDecimal)); if (val.zero()) { throw DynamicError.div_zero(null); } //decimal result = Value.divide(val.Value, 18, decimal.ROUND_HALF_EVEN); //return ResultSequenceFactory.create_new(new XSDecimal(result)); throw new Exception(); }
/// <summary> /// Mathematical addition operator between this XSDate and a supplied result /// sequence (XDTYearMonthDuration and XDTDayTimeDuration are only valid /// ones). /// </summary> /// <param name="arg"> /// The supplied ResultSequence that is on the right of the minus /// operator. If arg is an XDTYearMonthDuration or an /// XDTDayTimeDuration the result will be a XSDate of the result /// of the current date minus the duration of time supplied. </param> /// <returns> New ResultSequence consisting of the result of the mathematical /// minus operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence plus(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public virtual ResultSequence plus(ResultSequence arg) { if (arg.size() != 1) { DynamicError.throw_type_error(); } Item at = arg.first(); try { if (at is XSYearMonthDuration) { XSYearMonthDuration val = (XSYearMonthDuration)at; XSDate res = (XSDate)clone(); res.calendar().add(Calendar.MONTH, val.monthValue()); return(ResultSequenceFactory.create_new(res)); } else if (at is XSDayTimeDuration) { XSDayTimeDuration val = (XSDayTimeDuration)at; XSDate res = (XSDate)clone(); // We only need to add the Number of days dropping the rest. int days = val.days(); if (val.negative()) { days *= -1; } res.calendar().add(Calendar.DAY_OF_MONTH, days); res.calendar().add(Calendar.MILLISECOND, (int)(val.time_value() * 1000.0)); return(ResultSequenceFactory.create_new(res)); } else { DynamicError.throw_type_error(); return(null); // unreach } } catch { Debug.Assert(false); return(null); } }
/// <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); }