use of org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType 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.ElementType in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit document test.
*
* @param e
* is the document test.
* @return result sequence
*/
public Object visit(DocumentTest e) {
ResultSequence arg = (ResultSequence) ((Pair) _param)._two;
int type = e.type();
// filter doc nodes
ResultSequence rs = kind_test(arg, DocType.class);
if (type == DocumentTest.NONE)
return rs;
// the element test
for (Iterator i = rs.iterator(); i.hasNext(); ) {
DocType doc = (DocType) i.next();
int elem_count = 0;
ElementType elem = null;
// make sure doc has only 1 element
NodeList children = doc.node_value().getChildNodes();
for (int j = 0; j < children.getLength(); j++) {
Node child = children.item(j);
// bingo
if (child.getNodeType() == Node.ELEMENT_NODE) {
elem_count++;
if (elem_count > 1)
break;
elem = new ElementType((Element) child, _sc.getTypeModel());
}
}
// this doc is no good... send him to hell
if (elem_count != 1) {
i.remove();
continue;
}
assert elem != null;
// setup parameter for element test
ResultSequence res = new ResultBuffer.SingleResultSequence(elem);
_param = new Pair("element", res);
// do name test
res = null;
if (type == DocumentTest.ELEMENT)
res = (ResultSequence) e.elem_test().accept(this);
else if (type == DocumentTest.SCHEMA_ELEMENT)
res = (ResultSequence) e.schema_elem_test().accept(this);
else
assert false;
// check if element survived nametest
if (res.size() != 1)
i.remove();
}
return rs;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit schema element test.
*
* @param e
* is the schema element test.
* @return a result sequence
*/
public Object visit(SchemaElemTest e) {
// filter out all elements
ResultSequence rs = kind_test((ResultSequence) ((Pair) _param)._two, ElementType.class);
// match the name
// XXX substitution groups
QName name = e.name();
for (Iterator i = rs.iterator(); i.hasNext(); ) {
if (!name_test((ElementType) i.next(), name, "element"))
i.remove();
}
// check the type
TypeDefinition et = _sc.getTypeModel().lookupElementDeclaration(name.namespace(), name.local());
for (Iterator i = rs.iterator(); i.hasNext(); ) {
NodeType node = (NodeType) i.next();
if (!derivesFrom(node, et)) {
i.remove();
continue;
}
XSBoolean nilled = (XSBoolean) node.nilled().first();
// XXX or, in schema it is nillable
if (nilled.value())
i.remove();
}
return rs;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType in project webtools.sourceediting by eclipse.
the class AttributeAxis method iterate.
/**
* Retrieves the context node's attributes.
*
* @param node
* is the type of node.
*/
public void iterate(NodeType node, ResultBuffer copyInto, Node limitNode) {
// only elements have attributes
if (!(node instanceof ElementType))
return;
// get attributes
ElementType elem = (ElementType) node;
NamedNodeMap attrs = elem.value().getAttributes();
// add attributes
for (int i = 0; i < attrs.getLength(); i++) {
Attr attr = (Attr) attrs.item(i);
copyInto.add(NodeType.dom_to_xpath(attr, node.getTypeModel()));
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType in project webtools.sourceediting by eclipse.
the class ChildAxis method addChildren.
protected void addChildren(NodeType node, ResultBuffer copyInto, boolean recurse) {
NodeList nl = null;
// only document and element nodes have children
if (node instanceof DocType) {
nl = ((DocType) node).value().getChildNodes();
}
if (node instanceof ElementType)
nl = ((ElementType) node).value().getChildNodes();
// add the children to the result
if (nl != null) {
for (int i = 0; i < nl.getLength(); i++) {
Node dnode = nl.item(i);
NodeType n = NodeType.dom_to_xpath(dnode, node.getTypeModel());
if (n != null) {
copyInto.add(n);
if (recurse)
addChildren(n, copyInto, recurse);
}
}
}
}
Aggregations