Search in sources :

Example 26 with AnyType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType 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 27 with AnyType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType 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)

Example 28 with AnyType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType in project webtools.sourceediting by eclipse.

the class AttributeTest method createAttrForXSDType.

private AnyType createAttrForXSDType(Node node, StaticContext sc) {
    Attr attr = (Attr) node;
    TypeModel typeModel = sc.getTypeModel();
    TypeDefinition typedef = typeModel.getType(attr);
    if (typedef != null) {
        if (typedef.derivedFrom(type().namespace(), type().local(), getDerviationTypes())) {
            anyType = new AttrType(attr, sc.getTypeModel());
        }
    } else {
        anyType = new AttrType(attr, sc.getTypeModel());
    }
    return anyType;
}
Also used : AttrType(org.eclipse.wst.xml.xpath2.processor.internal.types.AttrType) TypeModel(org.eclipse.wst.xml.xpath2.api.typesystem.TypeModel) Attr(org.w3c.dom.Attr) TypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)

Example 29 with AnyType

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

Example 30 with AnyType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType in project webtools.sourceediting by eclipse.

the class XSDecimal method lt.

/**
 * Comparison between this number and the supplied representation.
 *
 * @param arg
 *            Representation to be compared with (must currently be of type
 *            XSDecimal)
 * @return True if the supplied type represents a number greater than this
 *         one stored. False otherwise
 */
public boolean lt(AnyType arg, DynamicContext context) throws DynamicError {
    Item carg = convertArg(arg);
    XSDecimal val = (XSDecimal) get_single_type(carg, XSDecimal.class);
    return (_value.compareTo(val.getValue()) == -1);
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

Aggregations

AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)162 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)127 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)123 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)123 URL (java.net.URL)122 XSModel (org.apache.xerces.xs.XSModel)121 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)40 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)38 Iterator (java.util.Iterator)37 Item (org.eclipse.wst.xml.xpath2.api.Item)26 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)14 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)14 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)11 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)9 XSDouble (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble)9 Collection (java.util.Collection)8 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)8 ListIterator (java.util.ListIterator)7 ArrayList (java.util.ArrayList)6 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)6