use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType 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.NodeType 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.NodeType in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method node_cmp.
private ResultSequence node_cmp(int type, Collection args) {
assert args.size() == 2;
Iterator argsiter = args.iterator();
ResultSequence one = (ResultSequence) argsiter.next();
ResultSequence two = (ResultSequence) argsiter.next();
int size_one = one.size();
int size_two = two.size();
if (size_one > 1 || size_two > 1)
report_error(TypeError.invalid_type(null));
if (size_one == 0 || size_two == 0)
return ResultBuffer.EMPTY;
Item at_one = one.item(0);
Item at_two = two.item(0);
if (!(at_one instanceof NodeType) || !(at_two instanceof NodeType))
report_error(TypeError.invalid_type(null));
// ok we got the args finally
NodeType nt_one = (NodeType) at_one;
NodeType nt_two = (NodeType) at_two;
// we are pessimistic as usual
boolean answer = false;
// do comparison
switch(type) {
case CmpExpr.IS:
answer = nt_one.node_value() == nt_two.node_value();
break;
case CmpExpr.LESS_LESS:
answer = nt_one.before(nt_two);
break;
case CmpExpr.GREATER_GREATER:
answer = nt_one.after(nt_two);
break;
default:
assert false;
}
return XSBoolean.valueOf(answer);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method descendant_or_self_node.
private ResultSequence descendant_or_self_node(ResultSequence rs) {
ResultBuffer res = new ResultBuffer();
Axis axis = new DescendantOrSelfAxis();
// for all nodes, get descendant or self nodes
for (Iterator i = rs.iterator(); i.hasNext(); ) {
NodeType item = (NodeType) i.next();
axis.iterate(item, res, _dc.getLimitNode());
}
return res.getSequence();
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method derivesFrom.
private boolean derivesFrom(NodeType at, TypeDefinition td) {
TypeDefinition nodeTd = _sc.getTypeModel().getType(at.node_value());
short method = TypeDefinition.DERIVATION_EXTENSION | TypeDefinition.DERIVATION_RESTRICTION;
return nodeTd != null && nodeTd.derivedFromType(td, method);
}
Aggregations