use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.
the class PrecedingAxis method iterate.
// XXX DOCUMENT ORDER.... dunno
/**
* returns preceding nodes of the context node
*
* @param node
* is the node type.
* @throws dc
* is the Dynamic context.
*/
public void iterate(NodeType node, ResultBuffer result, Node limitNode) {
if (limitNode != null && limitNode.isSameNode(node.node_value())) {
// no further, we have reached the limit node
return;
}
// get the parent
NodeType parent = null;
ResultBuffer parentBuffer = new ResultBuffer();
new ParentAxis().iterate(node, parentBuffer, limitNode);
if (parentBuffer.size() == 1) {
parent = (NodeType) parentBuffer.item(0);
// if we got a parent, we gotta repeat the story for the parent
// and add the results
iterate(parent, result, limitNode);
}
// get the following siblings of this node, and add them
PrecedingSiblingAxis psa = new PrecedingSiblingAxis();
ResultBuffer siblingBuffer = new ResultBuffer();
psa.iterate(node, siblingBuffer, limitNode);
// for each sibling, get all its descendants
DescendantAxis da = new DescendantAxis();
for (Iterator i = siblingBuffer.iterator(); i.hasNext(); ) {
result.add((NodeType) i);
da.iterate((NodeType) i.next(), result, null);
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.
the class DefaultStaticContext method derives_from.
/**
* Checks if an XML node derives from a specified type.
*
* @param at
* node actual type
* @param et
* name of expected type
* @return true if a derivation exists
*/
// XXX fix this
public boolean derives_from(NodeType at, QName et) {
TypeDefinition td = _model.getType(at.node_value());
short method = TypeDefinition.DERIVATION_EXTENSION | TypeDefinition.DERIVATION_RESTRICTION;
// XXX
if (!et.expanded()) {
String pre = et.prefix();
if (pre != null) {
if (prefix_exists(pre)) {
et.set_namespace(resolve_prefix(pre));
} else
assert false;
} else
et.set_namespace(default_namespace());
}
return td != null && td.derivedFrom(et.namespace(), et.local(), method);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.
the class PrecedingSiblingAxis method iterate.
// XXX again, unify with following
/**
* returns preceding nodes of the context node
*
* @param node
* is the node type.
* @throws dc
* is the Dynamic context.
*/
public void iterate(NodeType node, ResultBuffer copyInto, Node limitNode) {
// XXX check for attribute / namespace node... if so return
// empty sequence
int pos = copyInto.size();
Node iterNode = node.node_value();
// get the children of the parent [siblings]
do {
iterNode = iterNode.getPreviousSibling();
if (iterNode != null) {
NodeType nodeType = NodeType.dom_to_xpath(iterNode, node.getTypeModel());
if (nodeType != null) {
copyInto.addAt(pos, nodeType);
}
}
} while (iterNode != null);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.
the class SeqType method match.
/**
* matches args
*
* @param args
* is a result sequence
* @throws a
* dynamic error
* @return a result sequence
*/
public ResultSequence match(ResultSequence args) throws DynamicError {
int occurrence = occurence();
// Check for empty sequence first
if (occurrence == OCC_EMPTY && !args.empty()) {
throw new DynamicError(TypeError.invalid_type(null));
}
int arg_count = 0;
for (Iterator i = args.iterator(); i.hasNext(); ) {
AnyType arg = (AnyType) i.next();
// make sure all args are the same type as expected type
if (!(typeClass.isInstance(arg))) {
throw new DynamicError(TypeError.invalid_type(null));
}
if (anytype != null) {
if ((nodeName != null || wild) && arg instanceof NodeType) {
NodeType nodeType = (NodeType) arg;
Node node = nodeType.node_value();
Node lnode = ((NodeType) anytype).node_value();
if (lnode == null) {
// throw new DynamicError(TypeError.invalid_type(null));
continue;
}
if (!lnode.isEqualNode(node)) {
// throw new DynamicError(TypeError.invalid_type(null));
continue;
}
}
}
arg_count++;
}
switch(occurrence) {
case OCC_NONE:
if (arg_count != 1) {
throw new DynamicError(TypeError.invalid_type(null));
}
break;
case OCC_PLUS:
if (arg_count == 0) {
throw new DynamicError(TypeError.invalid_type(null));
}
break;
case OCC_STAR:
break;
case OCC_QMARK:
if (arg_count > 1) {
throw new DynamicError(TypeError.invalid_type(null));
}
break;
default:
assert false;
}
return args;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.
the class ElementTest method createElementType.
private AnyType createElementType(Item at, StaticContext sc) {
anyType = new ElementType();
NodeType nodeType = (NodeType) at;
Node node = nodeType.node_value();
Document doc = null;
if (node.getNodeType() == Node.DOCUMENT_NODE) {
doc = (Document) node;
} else {
doc = nodeType.node_value().getOwnerDocument();
}
NodeList nodeList = null;
if (!wild()) {
nodeList = doc.getElementsByTagNameNS(name().namespace(), name().local());
} else {
nodeList = new SingleItemNodeListImpl(node);
}
if (nodeList.getLength() > 0) {
anyType = createElementForXSDType(nodeList, sc);
}
return anyType;
}
Aggregations