use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType in project webtools.sourceediting by eclipse.
the class SequenceTypeSyntaxTest method test_sequence_type_14.
// Simple evaluation of sequence type matching involving castable as and a sequence of two decimals. (Uses decimal?).
public void test_sequence_type_14() throws Exception {
String inputFile = "/TestSources/emptydoc.xml";
String xqFile = "/Queries/XQuery/Basics/Types/SequenceTypeSyntax/sequence-type-14.xq";
String resultFile = "/ExpectedTestResults/Basics/Types/SequenceTypeSyntax/falsevalue.txt";
String expectedResult = getExpectedResult(resultFile);
URL fileURL = bundle.getEntry(inputFile);
loadDOMDocument(fileURL);
// Get XML Schema Information for the Document
XSModel schema = getGrammar();
setupDynamicContext(schema);
String xpath = extractXPathExpression(xqFile, inputFile);
String actual = null;
try {
compileXPath(xpath);
ResultSequence rs = evaluate(domDoc);
AnyType result = rs.first();
actual = result.getStringValue();
} catch (XPathParserException ex) {
actual = ex.code();
} catch (StaticError ex) {
actual = ex.code();
}
assertEquals("XPath Result Error:", expectedResult, actual);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType in project webtools.sourceediting by eclipse.
the class AbstractURIFunction method escape_uri.
/**
* Apply the URI escaping rules to the arguments.
*
* @param args
* have the URI escaping rules applied to them.
* @param escape_space TODO
* @throws DynamicError
* Dynamic error.
* @return The result of applying the URI escaping rules to the arguments.
*/
public static ResultSequence escape_uri(Collection args, boolean escape_delimiters, boolean escape_space) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
Iterator argi = cargs.iterator();
ResultSequence arg1 = (ResultSequence) argi.next();
if (arg1.empty()) {
return new XSString("");
}
AnyType aat = (AnyType) arg1.item(0);
String str = aat.getStringValue();
ByteBuffer buffer = UTF_8.encode(str);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < buffer.limit(); i++) {
byte x = buffer.get(i);
if (needs_escape(x, escape_delimiters, escape_space)) {
sb.append("%");
sb.append(Integer.toHexString(x & 0xFF).toUpperCase());
} else
sb.append((char) x);
}
return new XSString(sb.toString());
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType in project webtools.sourceediting by eclipse.
the class FnAbs method get_single_numeric_arg.
/**
* Obtain numeric value from expression.
*
* @param arg
* input expression.
* @throws DynamicError
* Dynamic error.
* @return Resulting numeric type from the operation.
*/
public static NumericType get_single_numeric_arg(ResultSequence arg) throws DynamicError {
int size = arg.size();
if (size > 1)
DynamicError.throw_type_error();
if (size == 0)
return null;
arg = FnData.atomize(arg);
AnyType at = (AnyType) arg.item(0);
if (!(at instanceof NumericType))
throw DynamicError.invalidType();
return (NumericType) at;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType in project webtools.sourceediting by eclipse.
the class FnAvg method avg.
/**
* Average value operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:avg operation.
*/
public static ResultSequence avg(Collection args) throws DynamicError {
ResultSequence arg = (ResultSequence) args.iterator().next();
if (arg.empty())
return ResultSequenceFactory.create_new();
int elems = 0;
MathPlus total = null;
TypePromoter tp = new ScalarTypePromoter();
tp.considerSequence(arg);
for (Iterator i = arg.iterator(); i.hasNext(); ) {
++elems;
AnyAtomicType conv = tp.promote((AnyType) i.next());
if (conv != null) {
if (conv instanceof XSDouble && ((XSDouble) conv).nan() || conv instanceof 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 instanceof MathDiv))
DynamicError.throw_type_error();
return ((MathDiv) total).div(ResultSequenceFactory.create_new(new XSInteger(BigInteger.valueOf(elems))));
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType in project webtools.sourceediting by eclipse.
the class DefaultStaticContext method debug_print_vars.
/**
* Debug function which will print current variable scopes and info.
*/
// debug functions
public void debug_print_vars() {
int level = 0;
for (Iterator i = _scopes.iterator(); i.hasNext(); ) {
Map scope = (Map) i.next();
System.out.println("Scope level " + level);
// scope.entrySet().iterator();
for (Iterator j = scope.entrySet().iterator(); j.hasNext(); ) {
QName varname = (QName) j.next();
AnyType val = (AnyType) scope.get(varname);
String string_val = "null";
if (val != null)
string_val = val.getStringValue();
System.out.println("Varname: " + varname.string() + " expanded=" + varname.expanded() + " Value: " + string_val);
}
level++;
}
}
Aggregations