Search in sources :

Example 1 with TypeModel

use of org.eclipse.wst.xml.xpath2.api.typesystem.TypeModel 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 2 with TypeModel

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

the class TestBugs method testNulVarNamespacePrefix.

public void testNulVarNamespacePrefix() throws Exception {
    // Bug 345326
    String xpath = "for $a in //* return $a";
    new Engine().parseExpression(xpath, new StaticContext() {

        public boolean isXPath1Compatible() {
            return false;
        }

        public StaticVariableResolver getInScopeVariables() {
            return null;
        }

        public TypeDefinition getInitialContextType() {
            return null;
        }

        public Map getFunctionLibraries() {
            return null;
        }

        public CollationProvider getCollationProvider() {
            return null;
        }

        public URI getBaseUri() {
            return null;
        }

        public ItemType getDocumentType(URI documentUri) {
            return null;
        }

        public NamespaceContext getNamespaceContext() {
            return new NamespaceContext() {

                public String getNamespaceURI(String arg0) {
                    if (arg0 == null)
                        throw new IllegalArgumentException("#fail");
                    return XMLConstants.NULL_NS_URI;
                }

                public String getPrefix(String arg0) {
                    if (arg0 == null)
                        throw new IllegalArgumentException("#fail");
                    return XMLConstants.DEFAULT_NS_PREFIX;
                }

                public Iterator getPrefixes(String arg0) {
                    if (arg0 == null)
                        throw new IllegalArgumentException("#fail");
                    return Collections.emptyList().iterator();
                }
            };
        }

        public String getDefaultNamespace() {
            return XMLConstants.NULL_NS_URI;
        }

        public String getDefaultFunctionNamespace() {
            return null;
        }

        public TypeModel getTypeModel() {
            return null;
        }

        public Function resolveFunction(QName name, int arity) {
            return null;
        }

        public TypeDefinition getCollectionType(String collectionName) {
            return null;
        }

        public TypeDefinition getDefaultCollectionType() {
            return null;
        }
    });
}
Also used : StaticVariableResolver(org.eclipse.wst.xml.xpath2.api.StaticVariableResolver) QName(javax.xml.namespace.QName) ItemType(org.eclipse.wst.xml.xpath2.api.typesystem.ItemType) TypeModel(org.eclipse.wst.xml.xpath2.api.typesystem.TypeModel) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) URI(java.net.URI) TypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition) Function(org.eclipse.wst.xml.xpath2.api.Function) NamespaceContext(javax.xml.namespace.NamespaceContext) Iterator(java.util.Iterator) CollationProvider(org.eclipse.wst.xml.xpath2.api.CollationProvider) Map(java.util.Map) Engine(org.eclipse.wst.xml.xpath2.processor.Engine) StaticContext(org.eclipse.wst.xml.xpath2.api.StaticContext)

Example 3 with TypeModel

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

the class AbstractPsychoPathWTPTest method setupDynamicContext.

protected DefaultDynamicContext setupDynamicContext(XSModel schema) {
    XercesTypeModel typeModel = schema != null ? new XercesTypeModel(schema) : null;
    DefaultDynamicContext dc = new DefaultDynamicContext(typeModel);
    // DefaultDynamicContext dc = new DefaultDynamicContext(schema, domDoc);
    dynamicContext = dc;
    dc.add_namespace("xs", "http://www.w3.org/2001/XMLSchema");
    dc.add_namespace("xsd", "http://www.w3.org/2001/XMLSchema");
    dc.add_namespace("fn", "http://www.w3.org/2005/xpath-functions");
    dc.add_namespace("xml", "http://www.w3.org/XML/1998/namespace");
    dc.add_function_library(new FnFunctionLibrary());
    dc.add_function_library(new XSCtrLibrary());
    setupVariables(dc);
    return dc;
}
Also used : FnFunctionLibrary(org.eclipse.wst.xml.xpath2.processor.function.FnFunctionLibrary) DefaultDynamicContext(org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext) XercesTypeModel(org.eclipse.wst.xml.xpath2.processor.internal.types.xerces.XercesTypeModel) XSCtrLibrary(org.eclipse.wst.xml.xpath2.processor.function.XSCtrLibrary)

Example 4 with TypeModel

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

the class AbstractPsychoPathTest method setupDynamicContext.

protected DefaultDynamicContext setupDynamicContext(XSModel schema) {
    XercesTypeModel typeModel = schema != null ? new XercesTypeModel(schema) : null;
    if (useNewApi) {
        staticContextBuilder.withTypeModel(typeModel);
        staticContextBuilder.withNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        staticContextBuilder.withNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
        staticContextBuilder.withNamespace("fn", "http://www.w3.org/2005/xpath-functions");
        staticContextBuilder.withNamespace("xml", "http://www.w3.org/XML/1998/namespace");
        dynamicContextBuilder = new DynamicContextBuilder(staticContextBuilder);
        setupVariables(dynamicContext);
        try {
            dynamicContextBuilder.withTimezoneOffset(DatatypeFactory.newInstance().newDuration(false, /*i.e. negative*/
            0, 0, 0, 5, 0, 0));
        } catch (DatatypeConfigurationException e) {
            throw new RuntimeException("Shouldn't fail here", e);
        }
        return null;
    }
    DefaultDynamicContext dc = new DefaultDynamicContext(typeModel);
    dynamicContext = dc;
    dc.add_namespace("xs", "http://www.w3.org/2001/XMLSchema");
    dc.add_namespace("xsd", "http://www.w3.org/2001/XMLSchema");
    dc.add_namespace("fn", "http://www.w3.org/2005/xpath-functions");
    dc.add_namespace("xml", "http://www.w3.org/XML/1998/namespace");
    dc.add_function_library(new FnFunctionLibrary());
    dc.add_function_library(new XSCtrLibrary());
    setupVariables(dc);
    return dc;
}
Also used : DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) FnFunctionLibrary(org.eclipse.wst.xml.xpath2.processor.function.FnFunctionLibrary) DynamicContextBuilder(org.eclipse.wst.xml.xpath2.processor.util.DynamicContextBuilder) DefaultDynamicContext(org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext) XercesTypeModel(org.eclipse.wst.xml.xpath2.processor.internal.types.xerces.XercesTypeModel) XSCtrLibrary(org.eclipse.wst.xml.xpath2.processor.function.XSCtrLibrary)

Example 5 with TypeModel

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

the class DefaultEvaluator method visit.

/**
 * visit item type.
 *
 * @param e
 *            is the item type.
 * @return null
 */
public Object visit(ItemType e) {
    switch(e.type()) {
        case ItemType.ITEM:
            break;
        case ItemType.QNAME:
            boolean ok = false;
            TypeModel model = _sc.getTypeModel();
            if (model != null) {
                ok = _sc.getTypeModel().lookupType(e.qname().namespace(), e.qname().local()) != null;
            }
            if (!ok) {
                ok = BuiltinTypeLibrary.BUILTIN_TYPES.lookupType(e.qname().namespace(), e.qname().local()) != null;
            }
            if (!ok)
                report_error(new StaticTypeNameError("Type not defined: " + e.qname().string()));
            ResultSequence arg = (ResultSequence) ((Pair) _param)._two;
            ((Pair) _param)._two = item_test(arg, e.qname());
            break;
        case ItemType.KINDTEST:
            ((Pair) _param)._two = e.kind_test().accept(this);
            break;
    }
    return null;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) TypeModel(org.eclipse.wst.xml.xpath2.api.typesystem.TypeModel) StaticTypeNameError(org.eclipse.wst.xml.xpath2.processor.internal.StaticTypeNameError)

Aggregations

TypeModel (org.eclipse.wst.xml.xpath2.api.typesystem.TypeModel)5 TypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)3 DefaultDynamicContext (org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext)3 FnFunctionLibrary (org.eclipse.wst.xml.xpath2.processor.function.FnFunctionLibrary)3 XSCtrLibrary (org.eclipse.wst.xml.xpath2.processor.function.XSCtrLibrary)3 XercesTypeModel (org.eclipse.wst.xml.xpath2.processor.internal.types.xerces.XercesTypeModel)3 URI (java.net.URI)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 NamespaceContext (javax.xml.namespace.NamespaceContext)1 QName (javax.xml.namespace.QName)1 CollationProvider (org.eclipse.wst.xml.xpath2.api.CollationProvider)1 Function (org.eclipse.wst.xml.xpath2.api.Function)1 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)1 StaticContext (org.eclipse.wst.xml.xpath2.api.StaticContext)1 StaticVariableResolver (org.eclipse.wst.xml.xpath2.api.StaticVariableResolver)1 ItemType (org.eclipse.wst.xml.xpath2.api.typesystem.ItemType)1 Engine (org.eclipse.wst.xml.xpath2.processor.Engine)1 StaticTypeNameError (org.eclipse.wst.xml.xpath2.processor.internal.StaticTypeNameError)1