Search in sources :

Example 1 with TypeDefinition

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

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

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

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

the class DefaultEvaluator method visit.

/**
 * visit schema attribute test.
 *
 * @param e
 *            is the schema attribute test.
 * @return a result sequence
 */
public Object visit(SchemaAttrTest e) {
    // filter out all attrs
    ResultSequence rs = kind_test((ResultSequence) ((Pair) _param)._two, AttrType.class);
    // match the name
    QName name = e.arg();
    for (Iterator i = rs.iterator(); i.hasNext(); ) {
        if (!name_test((NodeType) i.next(), name, "attribute"))
            i.remove();
    }
    // check the type
    TypeDefinition et = _sc.getTypeModel().lookupAttributeDeclaration(name.namespace(), name.local());
    for (Iterator i = rs.iterator(); i.hasNext(); ) {
        NodeType node = (NodeType) i.next();
        if (!derivesFrom(node, et))
            i.remove();
    }
    return rs;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair) TypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)

Example 5 with TypeDefinition

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

the class DefaultEvaluator method derivesFrom.

private boolean derivesFrom(NodeType at, TypeDefinition td) {
    TypeDefinition nodeTd = _sc.getTypeModel().getType(at.node_value());
    short method = TypeDefinition.DERIVATION_EXTENSION | TypeDefinition.DERIVATION_RESTRICTION;
    return nodeTd != null && nodeTd.derivedFromType(td, method);
}
Also used : TypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)

Aggregations

TypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)9 Iterator (java.util.Iterator)3 TypeModel (org.eclipse.wst.xml.xpath2.api.typesystem.TypeModel)3 ListIterator (java.util.ListIterator)2 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)2 VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)2 ElementType (org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType)2 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)2 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)2 URI (java.net.URI)1 Map (java.util.Map)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 StaticContext (org.eclipse.wst.xml.xpath2.api.StaticContext)1 StaticVariableResolver (org.eclipse.wst.xml.xpath2.api.StaticVariableResolver)1 ComplexTypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.ComplexTypeDefinition)1 ItemType (org.eclipse.wst.xml.xpath2.api.typesystem.ItemType)1 SimpleTypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.SimpleTypeDefinition)1