use of org.eclipse.wst.xml.xpath2.processor.internal.types.QName in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit element test.
*
* @param e
* is the element test.
* @return a result sequence
*/
public Object visit(ElementTest e) {
// filter out all elements
ResultSequence rs = kind_test((ResultSequence) ((Pair) _param)._two, ElementType.class);
// match the name if it's not a wild card
ResultBuffer rb = new ResultBuffer();
QName nameTest = e.name();
QName typeTest = e.type();
for (Iterator i = rs.iterator(); i.hasNext(); ) {
NodeType node = (NodeType) i.next();
if (nameTest != null && !e.wild()) {
// skip if there's a name test and the name does not match
if (!name_test((ElementType) node, nameTest, "element"))
continue;
}
if (typeTest != null) {
// check if element derives from
if (!derivesFrom(node, typeTest))
continue;
// nilled may be true or false
if (!e.qmark()) {
XSBoolean nilled = (XSBoolean) node.nilled().first();
if (nilled.value())
continue;
}
}
rb.add(node);
}
((Pair) _param)._two = rb.getSequence();
return ((Pair) _param)._two;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.QName in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit schema attribute test.
*
* @param e
* is the schema attribute test.
* @return a result sequence
*/
public Object visit(SchemaAttrTest e) {
// filter out all attrs
ResultSequence rs = kind_test((ResultSequence) ((Pair) _param)._two, AttrType.class);
// match the name
QName name = e.arg();
for (Iterator i = rs.iterator(); i.hasNext(); ) {
if (!name_test((NodeType) i.next(), name, "attribute"))
i.remove();
}
// check the type
TypeDefinition et = _sc.getTypeModel().lookupAttributeDeclaration(name.namespace(), name.local());
for (Iterator i = rs.iterator(); i.hasNext(); ) {
NodeType node = (NodeType) i.next();
if (!derivesFrom(node, et))
i.remove();
}
return rs;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.QName in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method do_exists.
private XSBoolean do_exists(ListIterator iter, Expr finalexpr) {
// we have more vars to bind...
if (iter.hasNext()) {
VarExprPair ve = (VarExprPair) iter.next();
// evaluate binding sequence
ResultSequence rs = (ResultSequence) ve.expr().accept(this);
QName varname = ve.varname();
try {
for (Iterator i = rs.iterator(); i.hasNext(); ) {
AnyType item = (AnyType) i.next();
pushScope(varname, item);
XSBoolean effbool = do_exists(iter, finalexpr);
popScope();
// out what to do with it
if (effbool.value())
return XSBoolean.TRUE;
}
} finally {
iter.previous();
}
// since none in this sequence evaluated to true, return false
return XSBoolean.FALSE;
} else // we finally got to do the "last expression"
{
return effective_boolean_value((ResultSequence) finalexpr.accept(this));
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.QName in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit a name test expression
*
* @param e
* is thename test.
* @return a result sequence
*/
public Object visit(NameTest e) {
QName name = e.name();
// get the arguments
Pair arg = (Pair) _param;
String type = (String) arg._one;
ResultSequence rs = (ResultSequence) arg._two;
ResultBuffer rb = new ResultBuffer();
for (Iterator i = rs.iterator(); i.hasNext(); ) {
NodeType nt = (NodeType) i.next();
// check if node passes name test
if (name_test(nt, name, type))
rb.add(nt);
}
rs = rb.getSequence();
arg._two = rs;
return rs;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.QName in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit cast expression
*
* @param cexp
* is the cast expression.
* @return a new function
*/
public Object visit(CastExpr cexp) {
ResultSequence rs = (ResultSequence) cexp.left().accept(this);
SingleType st = (SingleType) cexp.right();
rs = FnData.atomize(rs);
if (rs.size() > 1)
report_error(TypeError.invalid_type(null));
if (rs.empty()) {
if (st.qmark())
return rs;
else
report_error(TypeError.invalid_type(null));
}
AnyType at = (AnyType) rs.item(0);
if (!(at instanceof AnyAtomicType))
report_error(TypeError.invalid_type(null));
AnyAtomicType aat = (AnyAtomicType) at;
QName type = st.type();
// prepare args from function
Collection args = new ArrayList();
args.add(ResultSequenceFactory.create_new(aat));
try {
Function function = cexp.function();
if (function == null) {
function = _sc.resolveFunction(type.asQName(), args.size());
cexp.set_function(function);
}
if (function == null)
report_error(TypeError.invalid_type(null));
return function.evaluate(args, _ec);
} catch (DynamicError err) {
report_error(err);
// unreach
return null;
}
}
Aggregations