use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType 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.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.
the class FnNodeName method node_name.
/**
* Node-Name operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:node-name operation.
*/
public static ResultSequence node_name(Collection args) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
if (arg1.empty())
return ResultBuffer.EMPTY;
NodeType nt = (NodeType) arg1.first();
QName nodename = nt.node_name();
if (nodename == null)
return ResultBuffer.EMPTY;
return nodename;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.
the class FnRoot method fn_root.
/**
* Root operation.
*
* @param arg
* Result from the expressions evaluation.
* @param dc
* Result of dynamic context operation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:root operation.
*/
public static ResultSequence fn_root(Collection args, EvaluationContext ec) {
Collection cargs = Function.convert_arguments(args, expected_args());
if (cargs.size() > 1)
throw new DynamicError(TypeError.invalid_type(null));
ResultSequence arg = null;
if (cargs.isEmpty()) {
if (ec.getContextItem() == null) {
throw DynamicError.contextUndefined();
}
arg = ResultBuffer.wrap(ec.getContextItem());
} else {
arg = (ResultSequence) cargs.iterator().next();
}
if (arg.empty()) {
return ResultBuffer.EMPTY;
}
Item aa = arg.item(0);
if (!(aa instanceof NodeType))
throw new DynamicError(TypeError.invalid_type(null));
NodeType nt = (NodeType) aa;
// ok we got a sane argument... own it.
Node root = nt.node_value();
while (root != null && !(root instanceof Document)) {
Node newroot = root.getParentNode();
if (newroot == null && root instanceof Attr) {
newroot = ((Attr) root).getOwnerElement();
}
// found it
if (newroot == null)
break;
root = newroot;
}
return NodeType.dom_to_xpath(root, ec.getStaticContext().getTypeModel());
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.
the class OpExcept method op_except.
/**
* Op-Except operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of operation.
*/
public static ResultSequence op_except(Collection args) throws DynamicError {
ResultBuffer rs = new ResultBuffer();
// convert arguments
Collection cargs = Function.convert_arguments(args, expected_args());
// get arguments
Iterator iter = cargs.iterator();
ResultSequence one = (ResultSequence) iter.next();
ResultSequence two = (ResultSequence) iter.next();
// XXX lame
for (Iterator i = one.iterator(); i.hasNext(); ) {
NodeType node = (NodeType) i.next();
boolean found = false;
// death
for (Iterator j = two.iterator(); j.hasNext(); ) {
NodeType node2 = (NodeType) j.next();
if (node.node_value() == node2.node_value()) {
found = true;
break;
}
}
if (!found)
rs.add(node);
}
rs = NodeType.linarize(rs);
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method name_test.
// XXX this routine sux
private boolean name_test(NodeType node, QName name, String type) {
// make sure principal node kind is the same
if (node == null) {
return false;
}
if (!type.equals(node.string_type())) {
return false;
}
String test_prefix = name.prefix();
// element namespace
if (test_prefix == null && type.equals("element")) {
// XXX make a new copy
name = new QName(null, name.local());
name.set_namespace(_sc.getDefaultNamespace());
// if we actually have a namespace, pretend we do =D
if (name.namespace() != null && name.namespace().length() > 0)
test_prefix = "";
}
QName node_name = node.node_name();
assert node_name != null;
// make sure namespace matches
String node_namespace = node_name.namespace();
String test_namespace = null;
if (name.expanded())
test_namespace = name.namespace();
// name test has no prefix
if (test_prefix == null) {
// ok no namespace... match
if (node_namespace == null) {
} else {
return false;
}
} else // XXX AT THIS POINT ALL PREFIXES NEED TO BE RESOLVED!
if (!test_namespace.equals("*")) {
// the node doesn't have a namespace... no match
if (node_namespace == null) {
return false;
} else // check namespaces
{
if (node_namespace.equals(test_namespace)) {
// namespace matches
} else {
return false;
}
}
}
// check for wildcard in localpart
if (name.local().equals("*"))
return true;
// check if local part matches
if (!name.local().equals(node_name.local())) {
return false;
}
return true;
}
Aggregations