Search in sources :

Example 11 with StaticContext

use of org.eclipse.wst.xml.xpath2.api.StaticContext in project webtools.sourceediting by eclipse.

the class FnResolveQName method resolve_QName.

/**
 * Resolve-QName operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param sc
 *            Result of static context operation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:resolve-QName operation.
 */
public static ResultSequence resolve_QName(Collection args, StaticContext sc) throws DynamicError {
    // Collection cargs = Function.convert_arguments(args, expected_args());
    Collection cargs = args;
    // get args
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    if (arg1.empty())
        return ResultBuffer.EMPTY;
    ResultSequence arg2 = (ResultSequence) argiter.next();
    String name = ((XSString) arg1.first()).value();
    QName qn = QName.parse_QName(name);
    if (qn == null)
        throw DynamicError.lexical_error(null);
    ElementType xselement = (ElementType) arg2.first();
    Element element = (Element) xselement.node_value();
    if (qn.prefix() != null) {
        String namespaceURI = element.lookupNamespaceURI(qn.prefix());
        if (namespaceURI == null) {
            throw DynamicError.invalidPrefix();
        }
        qn.set_namespace(namespaceURI);
    } else {
        if (qn.local().equals(element.getLocalName()) && element.isDefaultNamespace(element.getNamespaceURI())) {
            qn.set_namespace(element.getNamespaceURI());
        }
    }
    return qn;
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) Element(org.w3c.dom.Element) Iterator(java.util.Iterator) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 12 with StaticContext

use of org.eclipse.wst.xml.xpath2.api.StaticContext in project webtools.sourceediting by eclipse.

the class Engine method parseExpression.

public XPath2Expression parseExpression(String expression, StaticContext context) {
    XPath xPath = new JFlexCupParser().parse(expression);
    xPath.setStaticContext(context);
    StaticNameResolver name_check = new StaticNameResolver(context);
    name_check.check(xPath);
    xPath.setAxes(name_check.getAxes());
    xPath.setFreeVariables(name_check.getFreeVariables());
    xPath.setResolvedFunctions(name_check.getResolvedFunctions());
    xPath.setRootUsed(name_check.isRootUsed());
    return xPath;
}
Also used : XPath(org.eclipse.wst.xml.xpath2.processor.ast.XPath)

Example 13 with StaticContext

use of org.eclipse.wst.xml.xpath2.api.StaticContext in project webtools.sourceediting by eclipse.

the class ElementTest method createElementForXSDType.

private AnyType createElementForXSDType(NodeList nodeList, StaticContext sc) {
    for (int i = 0; i < nodeList.getLength(); i++) {
        Element element = (Element) nodeList.item(i);
        TypeModel typeModel = sc.getTypeModel();
        TypeDefinition typedef = typeModel.getType(element);
        if (type() == null || typedef == null) {
            anyType = new ElementType(element, typeModel);
            break;
        } else {
            if (typedef.derivedFrom(type().namespace(), type().local(), getDerviationTypes())) {
                anyType = new ElementType(element, typeModel);
                break;
            }
        }
    }
    return anyType;
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) Element(org.w3c.dom.Element) TypeModel(org.eclipse.wst.xml.xpath2.api.typesystem.TypeModel) TypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)

Aggregations

ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)5 Collection (java.util.Collection)4 Iterator (java.util.Iterator)4 TypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)3 TypeModel (org.eclipse.wst.xml.xpath2.api.typesystem.TypeModel)3 Engine (org.eclipse.wst.xml.xpath2.processor.Engine)3 ElementType (org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType)3 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)3 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)3 Map (java.util.Map)2 DynamicContext (org.eclipse.wst.xml.xpath2.api.DynamicContext)2 StaticContext (org.eclipse.wst.xml.xpath2.api.StaticContext)2 XPath2Expression (org.eclipse.wst.xml.xpath2.api.XPath2Expression)2 AttrType (org.eclipse.wst.xml.xpath2.processor.internal.types.AttrType)2 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)2 DynamicContextBuilder (org.eclipse.wst.xml.xpath2.processor.util.DynamicContextBuilder)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 URI (java.net.URI)1 Calendar (java.util.Calendar)1