use of org.eclipse.wst.xml.xpath2.api.StaticContext in project webtools.sourceediting by eclipse.
the class AttributeTest method createAttrType.
private AnyType createAttrType(Item at, StaticContext sc) {
anyType = new AttrType();
NodeType nodeType = (NodeType) at;
Node node = nodeType.node_value();
if (node == null) {
return anyType;
}
String nodeName = node.getLocalName();
if (wild()) {
if (type() != null) {
anyType = createAttrForXSDType(node, sc);
}
} else if (nodeName.equals(name().local())) {
if (type() != null) {
anyType = createAttrForXSDType(node, sc);
} else {
anyType = new AttrType((Attr) node, sc.getTypeModel());
}
}
return anyType;
}
use of org.eclipse.wst.xml.xpath2.api.StaticContext in project webtools.sourceediting by eclipse.
the class FilteringPerformanceTest method evalXPath2.
protected Object evalXPath2(String xpath, Node doc, Class resultClass) {
StaticContext sc = new StaticContextBuilder();
XPath2Expression path = new Engine().parseExpression(xpath, sc);
DynamicContext dynamicContext = new DynamicContextBuilder(sc);
long before = System.nanoTime();
// path.evaluate(dynamicContext, doc != null ? new Object[] { doc } : new Object[0]);
// path.evaluate(dynamicContext, doc != null ? new Object[] { doc } : new Object[0]);
org.eclipse.wst.xml.xpath2.api.ResultSequence rs = path.evaluate(dynamicContext, doc != null ? new Object[] { doc } : new Object[0]);
assertEquals("Expected single result from \'" + xpath + "\'", 1, rs.size());
Object result = rs.value(0);
long after = System.nanoTime();
System.out.println("XPath2 " + xpath + " evaluated to " + result + " in " + (after - before) / 1000 + " μs");
assertTrue("Exected XPath result instanceof class " + resultClass.getSimpleName() + " from \'" + xpath + "\', got " + result.getClass(), resultClass.isInstance(result));
return resultClass.cast(result);
}
use of org.eclipse.wst.xml.xpath2.api.StaticContext in project webtools.sourceediting by eclipse.
the class TestBugs method testNulVarNamespacePrefix.
public void testNulVarNamespacePrefix() throws Exception {
// Bug 345326
String xpath = "for $a in //* return $a";
new Engine().parseExpression(xpath, new StaticContext() {
public boolean isXPath1Compatible() {
return false;
}
public StaticVariableResolver getInScopeVariables() {
return null;
}
public TypeDefinition getInitialContextType() {
return null;
}
public Map getFunctionLibraries() {
return null;
}
public CollationProvider getCollationProvider() {
return null;
}
public URI getBaseUri() {
return null;
}
public ItemType getDocumentType(URI documentUri) {
return null;
}
public NamespaceContext getNamespaceContext() {
return new NamespaceContext() {
public String getNamespaceURI(String arg0) {
if (arg0 == null)
throw new IllegalArgumentException("#fail");
return XMLConstants.NULL_NS_URI;
}
public String getPrefix(String arg0) {
if (arg0 == null)
throw new IllegalArgumentException("#fail");
return XMLConstants.DEFAULT_NS_PREFIX;
}
public Iterator getPrefixes(String arg0) {
if (arg0 == null)
throw new IllegalArgumentException("#fail");
return Collections.emptyList().iterator();
}
};
}
public String getDefaultNamespace() {
return XMLConstants.NULL_NS_URI;
}
public String getDefaultFunctionNamespace() {
return null;
}
public TypeModel getTypeModel() {
return null;
}
public Function resolveFunction(QName name, int arity) {
return null;
}
public TypeDefinition getCollectionType(String collectionName) {
return null;
}
public TypeDefinition getDefaultCollectionType() {
return null;
}
});
}
use of org.eclipse.wst.xml.xpath2.api.StaticContext in project webtools.sourceediting by eclipse.
the class CompleteNewApiTest method evaluateSimpleXPath.
protected Object evaluateSimpleXPath(String xpath, StaticContext sc, Document doc, Class resultClass) {
XPath2Expression path = new Engine().parseExpression(xpath, sc);
DynamicContext dynamicContext = new DynamicContextBuilder(sc);
org.eclipse.wst.xml.xpath2.api.ResultSequence rs = path.evaluate(dynamicContext, doc != null ? new Object[] { doc } : new Object[0]);
assertEquals("Expected single result from \'" + xpath + "\'", 1, rs.size());
Object result = rs.value(0);
assertTrue("Exected XPath result instanceof class " + resultClass.getSimpleName() + " from \'" + xpath + "\', got " + result.getClass(), resultClass.isInstance(result));
return result;
}
use of org.eclipse.wst.xml.xpath2.api.StaticContext in project webtools.sourceediting by eclipse.
the class FnQName method resolve_QName.
/**
* Resolve the QName of the given arguments.
*
* @param args
* Result from teh expressions evaluation.
* @param sc
* Result of static context operation.
* @throws DynamicError
* Dynamic error.
* @return Result of the fn:QName operation.
*/
public static ResultSequence resolve_QName(Collection args, StaticContext sc) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
// get args
Iterator argiter = cargs.iterator();
ResultSequence arg1 = (ResultSequence) argiter.next();
String ns = null;
if (!arg1.empty())
ns = ((XSString) arg1.first()).value();
ResultSequence arg2 = (ResultSequence) argiter.next();
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;
}
Aggregations