Search in sources :

Example 6 with NodeType

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);
    }
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Iterator(java.util.Iterator)

Example 7 with NodeType

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);
}
Also used : TypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)

Example 8 with NodeType

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);
}
Also used : Node(org.w3c.dom.Node) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)

Example 9 with NodeType

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;
}
Also used : NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 10 with NodeType

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;
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document)

Aggregations

NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)39 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)23 Iterator (java.util.Iterator)21 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)15 Collection (java.util.Collection)12 Node (org.w3c.dom.Node)12 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)11 ListIterator (java.util.ListIterator)10 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)9 ElementType (org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType)9 VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)7 TypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)6 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)5 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)5 ArrayList (java.util.ArrayList)4 Attr (org.w3c.dom.Attr)4 ForwardAxis (org.eclipse.wst.xml.xpath2.processor.internal.ForwardAxis)3 ParentAxis (org.eclipse.wst.xml.xpath2.processor.internal.ParentAxis)3 ReverseAxis (org.eclipse.wst.xml.xpath2.processor.internal.ReverseAxis)3 AttrType (org.eclipse.wst.xml.xpath2.processor.internal.types.AttrType)3