/// <summary> /// Atomize a ResultSequnce argument expression. /// </summary> /// <param name="arg"> /// input expression. </param> /// <returns> Result of operation. </returns> public static ResultSequence atomize(ResultSequence arg) { ResultBuffer rs = new ResultBuffer(); for (var i = arg.iterator(); i.MoveNext();) { AnyType at = (AnyType)i.Current; if (at is AnyAtomicType) { rs.add(at); } else if (at is NodeType) { NodeType nt = (NodeType)at; rs.concat(nt.typed_value()); } else { Debug.Assert(false); } } return(rs.Sequence); }
/// <summary> /// Op-Union operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of 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 op_union(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence op_union(ICollection args) { ResultBuffer rs = new ResultBuffer(); // convert arguments ICollection cargs = Function.convert_arguments(args, expected_args()); // get arguments IEnumerator iter = cargs.GetEnumerator(); iter.MoveNext(); ResultSequence one = (ResultSequence)iter.Current; iter.MoveNext(); ResultSequence two = (ResultSequence)iter.Current; // XXX i don't fink u've ever seen anything lamer than this rs.concat(one); rs.concat(two); rs = NodeType.linarize(rs); return(rs.Sequence); }
// convert argument according to section 3.1.5 of xpath 2.0 spec /// <summary> /// Convert the input argument according to section 3.1.5 of specification. /// </summary> /// <param name="arg"> /// input argument. </param> /// <param name="expected"> /// Expected Sequence type. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Converted argument. </returns> public static org.eclipse.wst.xml.xpath2.api.ResultSequence convert_argument(org.eclipse.wst.xml.xpath2.api.ResultSequence arg, SeqType expected) { ResultBuffer result = new ResultBuffer(); // XXX: Should use type_class instead and use item.getClass().isAssignableTo(expected.type_class()) AnyType expected_type = expected.type(); // expected is atomic if (expected_type is AnyAtomicType) { AnyAtomicType expected_aat = (AnyAtomicType)expected_type; // atomize org.eclipse.wst.xml.xpath2.api.ResultSequence rs = FnData.atomize(arg); // cast untyped to expected type for (var i = rs.iterator(); i.MoveNext();) { AnyType item = (AnyType)i.Current; if (item is XSUntypedAtomic) { // create a new item of the expected // type initialized with from the string // value of the item ResultSequence converted = null; if (expected_aat is XSString) { XSString strType = new XSString(item.StringValue); converted = ResultSequenceFactory.create_new(strType); } else { converted = ResultSequenceFactory.create_new(item); } result.concat(converted); } // xs:anyURI promotion to xs:string else if (item is XSAnyURI && expected_aat is XSString) { result.add(new XSString(item.StringValue)); } // numeric type promotion else if (item is NumericType) { if (expected_aat is XSDouble) { XSDouble doubleType = new XSDouble(item.StringValue); result.add(doubleType); } else { result.add(item); } } else { result.add(item); } } // do sequence type matching on converted arguments return(expected.match(result.Sequence)); } else { // do sequence type matching on converted arguments return(expected.match(arg)); } }
/// <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 insert_before(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence insert_before(ICollection args) { Debug.Assert(args.Count == 3); ResultBuffer rs = new ResultBuffer(); // get args IEnumerator citer = args.GetEnumerator(); citer.MoveNext(); ResultSequence target = (ResultSequence)citer.Current; citer.MoveNext(); ResultSequence arg2 = (ResultSequence)citer.Current; citer.MoveNext(); ResultSequence inserts = (ResultSequence)citer.Current; // sanity chex if (arg2.size() != 1) { DynamicError.throw_type_error(); } Item at = arg2.first(); if (!(at is XSInteger)) { DynamicError.throw_type_error(); } // XXX cloning! if (target.empty()) { return(inserts); } if (inserts.empty()) { return(target); } int position = (int)((XSInteger)at).int_value(); if (position < 1) { position = 1; } int target_size = target.size(); if (position > target_size) { position = target_size + 1; } int curpos = 1; for (var i = target.iterator(); i.MoveNext();) { at = (AnyType)i.Current; if (curpos == position) { rs.concat(inserts); } rs.add(at); curpos++; } if (curpos == position) { rs.concat(inserts); } return(rs.Sequence); }
/// <summary> /// Convert-Operand operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fs: 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 convert_operand(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence convert_operand(ICollection args) { Debug.Assert(args.Count == 2); IEnumerator iter = args.GetEnumerator(); iter.MoveNext(); ResultSequence actual = (ResultSequence)iter.Current; iter.MoveNext(); ResultSequence expected = (ResultSequence)iter.Current; if (expected == null || expected.size() != 1) { DynamicError.throw_type_error(); } Item at = expected.first(); if (!(at is AnyAtomicType)) { DynamicError.throw_type_error(); } AnyAtomicType exp_aat = (AnyAtomicType)at; ResultBuffer result = new ResultBuffer(); // 1 if (actual.empty()) { return(result.Sequence); } // convert sequence for (var i = actual.iterator(); i.MoveNext();) { AnyType item = (AnyType)i.Current; // 2 if (item is XSUntypedAtomic) { // a if (exp_aat is XSUntypedAtomic) { result.add(new XSString(item.StringValue)); } // b else if (exp_aat is NumericType) { result.add(new XSDouble(item.StringValue)); } // c else { Debug.Assert(exp_aat is CtrType); CtrType cons = (CtrType)exp_aat; result.concat(cons.constructor(new XSString(item.StringValue))); } } // 4 else { result.add(item); } } return(result.Sequence); }