/// <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> /// Distinct-values operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:distinct-values 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 distinct_values(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext context) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence distinct_values(ICollection args, DynamicContext context) { ResultBuffer rs = new ResultBuffer(); // get args IEnumerator citer = args.GetEnumerator(); citer.MoveNext(); ResultSequence arg1 = (ResultSequence)citer.Current; ResultSequence arg2 = ResultBuffer.EMPTY; if (citer.MoveNext()) { arg2 = (ResultSequence)citer.Current; } string collationURI = context.CollationProvider.DefaultCollation; if (!(arg2 == null || arg2.empty())) { XSString collation = (XSString)arg2.item(0); collationURI = collation.StringValue; } for (var iter = arg1.iterator(); iter.MoveNext();) { AnyAtomicType atomizedItem = (AnyAtomicType)FnData.atomize((Item)iter.Current); if (!contains(rs, atomizedItem, context, collationURI)) { rs.add(atomizedItem); } } return(rs.Sequence); }
private bool isCastable(AnyAtomicType aat) { if (aat is XSString || aat is XSUntypedAtomic) { return(true); } if (aat is XSGYearMonth) { return(true); } if (aat is XSDate) { return(true); } if (aat is XSTime) { return(false); } if (aat is XSDateTime) { return(true); } return(false); }
/// <summary> /// Min operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <param name="dynamic"> /// Dynamic context </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:min 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 min(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext context) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence min(ICollection args, DynamicContext context) { ResultSequence arg = FnMax.get_arg(args, typeof(CmpLt)); if (arg.empty()) { return(ResultSequenceFactory.create_new()); } CmpLt max = null; TypePromoter tp = new ComparableTypePromoter(); tp.considerSequence(arg); for (var i = arg.iterator(); i.MoveNext();) { AnyAtomicType conv = tp.promote((AnyType)i.Current); if (conv != null) { if (conv is XSDouble && ((XSDouble)conv).nan() || conv is XSFloat && ((XSFloat)conv).nan()) { return(ResultSequenceFactory.create_new(tp.promote(new XSFloat(float.NaN)))); } if (max == null || ((CmpLt)conv).lt((AnyType)max, context)) { max = (CmpLt)conv; } } } return(ResultSequenceFactory.create_new((AnyType)max)); }
/// <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> /// Adds a type into the functions library as an abstract type. /// </summary> /// <param name="at"> /// input of any atomic type. </param> public virtual void add_abstract_type(string localName, AnyAtomicType at) { QName name = new QName(localName); name.set_namespace(@namespace()); _types[name] = at; }
/// <summary> /// Support for Contains interface. /// </summary> /// <param name="rs"> /// input1 expression sequence. </param> /// <param name="item"> /// input2 expression of any atomic type. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of operation. </returns> protected internal static bool contains(ResultBuffer rs, AnyAtomicType item, DynamicContext context, string collationURI) { if (!(item is CmpEq)) { return(false); } return(hasValue(rs, item, context, collationURI)); }
private XSDuration castDayTimeDuration(AnyAtomicType aat) { if (aat is XSDuration) { XSDuration duration = (XSDuration)aat; return(new XSDayTimeDuration(duration.days(), duration.hours(), duration.minutes(), duration.seconds(), duration.negative())); } return(parseDTDuration(aat.StringValue)); }
protected internal virtual bool isGDataType(AnyAtomicType aat) { string type = aat.string_type(); if (type.Equals("xs:gMonthDay") || type.Equals("xs:gMonth") || type.Equals("xs:gYear") || type.Equals("xs:gYearMonth")) { return(true); } return(false); }
private XSDuration castYearMonthDuration(AnyAtomicType aat) { if (aat is XSDuration) { XSDuration duration = (XSDuration)aat; return(new XSYearMonthDuration(duration.year(), duration.month(), duration.negative())); } return(parseYMDuration(aat.StringValue)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void considerValue(org.eclipse.wst.xml.xpath2.api.Item at) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public virtual void considerValue(Item at) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType atomize = this.atomize(at); AnyAtomicType atomize = this.atomize(at); if (atomize != null) { // we known that it is not empty sequence this.considerType(atomize.GetType()); } }
//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(); return(new XSUntypedAtomic(aat.StringValue)); }
/// <summary> /// Deep-Equal boolean operation for inputs of any atomic type. /// </summary> /// <param name="one"> /// input1 xpath expression/variable. </param> /// <param name="two"> /// input2 xpath expression/variable. </param> /// <returns> Result of fn:deep-equal operation. </returns> public static bool deep_equal_atomic(AnyAtomicType one, AnyAtomicType two, DynamicContext context, string collationURI) { if (!(one is CmpEq)) { return(false); } if (!(two is CmpEq)) { return(false); } CmpEq a = (CmpEq)one; try { if (isNumeric(one, two)) { NumericType numeric = (NumericType)one; if (numeric.eq(two, context)) { return(true); } else { XSString value1 = new XSString(one.StringValue); if (value1.eq(two, context)) { return(true); } } } if (a.eq(two, context)) { return(true); } if (needsStringComparison(one, two)) { XSString xstr1 = new XSString(one.StringValue); XSString xstr2 = new XSString(two.StringValue); if (FnCompare.compare_string(collationURI, xstr1, xstr2, context).Equals(System.Numerics.BigInteger.Zero)) { return(true); } } return(false); } catch (DynamicError) { return(false); // XXX ??? } }
//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); }
private bool isCastable(AnyAtomicType aat) { if (aat is XSString || aat is XSUntypedAtomic) { return(true); } if (aat is XSBase64Binary || aat is XSHexBinary) { return(true); } return(false); }
private CalendarType castTime(AnyAtomicType aat) { if (aat is XSTime) { XSTime time = (XSTime)aat; return(new XSTime(time.calendar(), time.tz())); } if (aat is XSDateTime) { XSDateTime dateTime = (XSDateTime)aat; return(new XSTime(dateTime.calendar(), dateTime.tz())); } return(parse_time(aat.StringValue)); }
/// <summary> /// Average value operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:avg 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 avg(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence avg(ICollection args) { var j = args.GetEnumerator(); j.MoveNext(); ResultSequence arg = (ResultSequence)j.Current; if (arg == null || arg.empty()) { return(ResultSequenceFactory.create_new()); } int elems = 0; MathPlus total = null; TypePromoter tp = new ScalarTypePromoter(); tp.considerSequence(arg); for (var i = arg.iterator(); i.MoveNext();) { ++elems; AnyAtomicType conv = tp.promote((AnyType)i.Current); if (conv != null) { if (conv is XSDouble && ((XSDouble)conv).nan() || conv is XSFloat && ((XSFloat)conv).nan()) { return(ResultSequenceFactory.create_new(tp.promote(new XSFloat(float.NaN)))); } if (total == null) { total = (MathPlus)conv; } else { total = (MathPlus)total.plus(ResultSequenceFactory.create_new(conv)).first(); } } } if (!(total is MathDiv)) { DynamicError.throw_type_error(); } return(((MathDiv)total).div(ResultSequenceFactory.create_new(new XSInteger(new System.Numerics.BigInteger(elems))))); }
/// <param name="st"> /// is a sequence type. </param> /// <param name="sc"> /// is a static context. </param> public SeqType(SequenceType st, StaticContext sc, ResultSequence rs) { occ = mapSequenceTypeOccurrence(st.occurrence()); // figure out the item is //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.eclipse.wst.xml.xpath2.processor.internal.ast.ItemType item = st.item_type(); ItemType item = st.item_type(); KindTest ktest = null; switch (item.type()) { case ItemType.ITEM: typeClass = typeof(AnyType); return; // XXX IMPLEMENT THIS case ItemType.QNAME: //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType aat = make_atomic(sc, item.qname()); AnyAtomicType aat = make_atomic(sc, item.qname()); Debug.Assert(aat != null); anytype = aat; if (item.qname().Equals(ANY_ATOMIC_TYPE)) { typeClass = typeof(AnyAtomicType); } else { typeClass = anytype.GetType(); } return; case ItemType.KINDTEST: ktest = item.kind_test(); break; } if (ktest == null) { return; } typeClass = ktest.XDMClassType; anytype = ktest.createTestType(rs, sc); nodeName = ktest.name(); wild = ktest.Wild; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public final org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType promote(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType value) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public AnyAtomicType promote(AnyType value) { // This is a short cut, really if (value.GetType() == TargetType) { return((AnyAtomicType)value); } AnyAtomicType atomized = atomize(value); if (atomized == null) { // empty sequence return(null); } return(doPromote(atomized)); }
/// <summary> /// Creates a new ResultSequence consisting of the ENTITY within /// the supplied ResultSequence. The specification says that this /// is relaxed from the XML Schema requirement. The ENTITY does /// not have to be located or expanded during construction and /// evaluation for casting. /// </summary> /// <param name="arg"> /// The ResultSequence from which to extract the ENTITY </param> /// <returns> New ResultSequence consisting of the ENTITY 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); } AnyAtomicType aat = (AnyAtomicType)arg.first(); string strValue = aat.StringValue; if (!isConstraintSatisfied(strValue)) { // invalid input DynamicError.throw_type_error(); } return(new XSEntity(strValue)); }
/// <summary> /// Creates a new ResultSequence consisting of the extractable NMTOKEN within /// the supplied ResultSequence /// </summary> /// <param name="arg"> /// The ResultSequence from which to extract the NMTOKEN </param> /// <returns> New ResultSequence consisting of the NMTOKEN 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); } AnyAtomicType aat = (AnyAtomicType)arg.first(); string strValue = aat.StringValue; if (!XMLChar.isValidNmtoken(strValue)) { // invalid input DynamicError.throw_type_error(); } return(new XSNMTOKEN(strValue)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType doPromote(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType value) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public override AnyAtomicType doPromote(AnyAtomicType value) { if (TargetType == typeof(XSFloat)) { return(new XSFloat(value.StringValue)); } else if (TargetType == typeof(XSDouble)) { return(new XSDouble(value.StringValue)); } else if (TargetType == typeof(XSInteger)) { return(new XSInteger(value.StringValue)); } else if (TargetType == typeof(XSDecimal)) { return(new XSDecimal(value.StringValue)); } return(null); }
private XSGDay castGDay(AnyAtomicType aat) { if (aat is XSGDay) { XSGDay gday = (XSGDay)aat; return(new XSGDay(gday.calendar(), gday.tz())); } if (aat is XSDate) { XSDate date = (XSDate)aat; return(new XSGDay(date.calendar(), date.tz())); } if (aat is XSDateTime) { XSDateTime dateTime = (XSDateTime)aat; return(new XSGDay(dateTime.calendar(), dateTime.tz())); } return(parse_gDay(aat.StringValue)); }
protected internal virtual bool isCastable(AnyAtomicType aat) { string value = aat.StringValue; // get this once so we don't recreate everytime. string type = aat.string_type(); if (type.Equals("xs:string") || type.Equals("xs:untypedAtomic")) { if (isDurationValue(value)) { return(true); // We might be able to cast this. } } // We can cast from ourself or derivations of ourselves. if (aat is XSDuration) { return(true); } return(false); }
private XSGYear castGYear(AnyAtomicType aat) { if (aat is XSGYear) { XSGYear gy = (XSGYear)aat; return(new XSGYear(gy.calendar(), gy.tz())); } if (aat is XSDate) { XSDate date = (XSDate)aat; return(new XSGYear(date.calendar(), date.tz())); } if (aat is XSDateTime) { XSDateTime dateTime = (XSDateTime)aat; return(new XSGYear(dateTime.calendar(), dateTime.tz())); } return(parse_gYear(aat.StringValue)); }
private XSGMonthDay castGMonthDay(AnyAtomicType aat) { if (aat is XSGMonthDay) { XSGMonthDay gmd = (XSGMonthDay)aat; return(new XSGMonthDay(gmd.calendar(), gmd.tz())); } if (aat is XSDate) { XSDate date = (XSDate)aat; return(new XSGMonthDay(date.calendar(), date.tz())); } if (aat is XSDateTime) { XSDateTime dateTime = (XSDateTime)aat; return(new XSGMonthDay(dateTime.calendar(), dateTime.tz())); } return(parse_gMonthDay(aat.StringValue)); }
private XSGYearMonth castGYearMonth(AnyAtomicType aat) { if (aat is XSGYearMonth) { XSGYearMonth gym = (XSGYearMonth)aat; return(new XSGYearMonth(gym.calendar(), gym.tz())); } if (aat is XSDate) { XSDate date = (XSDate)aat; return(new XSGYearMonth(date.calendar(), date.tz())); } if (aat is XSDateTime) { XSDateTime dateTime = (XSDateTime)aat; return(new XSGYearMonth(dateTime.calendar(), dateTime.tz())); } return(parse_gYearMonth(aat.StringValue)); }
/// <summary> /// Sum operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:sum 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 sum(org.eclipse.wst.xml.xpath2.api.ResultSequence arg, org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType zero) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence sum(ResultSequence arg, AnyAtomicType zero) { if (arg.empty()) { return(ResultSequenceFactory.create_new(zero)); } MathPlus total = null; TypePromoter tp = new ScalarTypePromoter(); tp.considerSequence(arg); for (var i = arg.iterator(); i.MoveNext();) { AnyAtomicType conv = tp.promote((AnyType)i.Current); if (conv == null) { conv = zero; } if (conv is XSDouble && ((XSDouble)conv).nan() || conv is XSFloat && ((XSFloat)conv).nan()) { return(ResultSequenceFactory.create_new(tp.promote(new XSFloat(float.NaN)))); } if (total == null) { total = (MathPlus)conv; } else { total = (MathPlus)total.plus(ResultSequenceFactory.create_new(conv)).first(); } } return(ResultSequenceFactory.create_new((AnyType)total)); }
/// <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> /// 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); }