Search in sources :

Example 6 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, QName et) {
    TypeDefinition td = _sc.getTypeModel().getType(at.node_value());
    short method = TypeDefinition.DERIVATION_EXTENSION | TypeDefinition.DERIVATION_RESTRICTION;
    return td != null && td.derivedFrom(et.namespace(), et.local(), method);
}
Also used : TypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)

Example 7 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 element test.
 *
 * @param e
 *            is the schema element test.
 * @return a result sequence
 */
public Object visit(SchemaElemTest e) {
    // filter out all elements
    ResultSequence rs = kind_test((ResultSequence) ((Pair) _param)._two, ElementType.class);
    // match the name
    // XXX substitution groups
    QName name = e.name();
    for (Iterator i = rs.iterator(); i.hasNext(); ) {
        if (!name_test((ElementType) i.next(), name, "element"))
            i.remove();
    }
    // check the type
    TypeDefinition et = _sc.getTypeModel().lookupElementDeclaration(name.namespace(), name.local());
    for (Iterator i = rs.iterator(); i.hasNext(); ) {
        NodeType node = (NodeType) i.next();
        if (!derivesFrom(node, et)) {
            i.remove();
            continue;
        }
        XSBoolean nilled = (XSBoolean) node.nilled().first();
        // XXX or, in schema it is nillable
        if (nilled.value())
            i.remove();
    }
    return rs;
}
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) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) 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 8 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 definition.
 *
 * @param at
 *            node actual type.
 * @param et
 *            type definition of expected type.
 * @return true if a derivation exists.
 */
public boolean derives_from(NodeType at, TypeDefinition et) {
    TypeDefinition td = _model.getType(at.node_value());
    short method = 0;
    return td.derivedFromType(et, method);
}
Also used : TypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)

Example 9 with TypeDefinition

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

Example 10 with TypeDefinition

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

the class NodeType method getXDMTypedValue.

// getTypedValueForPrimitiveType
/*
	 * Construct the "typed value" from a "string value", given the simpleType of the node.
     */
protected ResultSequence getXDMTypedValue(TypeDefinition typeDef, List itemValTypes) {
    if ("anySimpleType".equals(typeDef.getName()) || "anyAtomicType".equals(typeDef.getName())) {
        return new XSUntypedAtomic(getStringValue());
    } else {
        SimpleTypeDefinition simpType = null;
        if (typeDef instanceof ComplexTypeDefinition) {
            ComplexTypeDefinition complexTypeDefinition = (ComplexTypeDefinition) typeDef;
            simpType = complexTypeDefinition.getSimpleType();
            if (simpType != null) {
                // element has a complexType with a simple content
                return getTypedValueForSimpleContent(simpType, itemValTypes);
            } else {
                // element has a complexType with complex content
                return new XSUntypedAtomic(getStringValue());
            }
        } else {
            // element has a simpleType
            simpType = (SimpleTypeDefinition) typeDef;
            return getTypedValueForSimpleContent(simpType, itemValTypes);
        }
    }
}
Also used : ComplexTypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.ComplexTypeDefinition) SimpleTypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.SimpleTypeDefinition)

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